aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfffw2015-10-10 18:20:04 +0800
committerfffw2015-10-10 18:20:04 +0800
commit2bd673783db47a90635d96fda462d2614ccb1a24 (patch)
treedc372118a147dc0a9d6b6d19d36430e9c9dcf765
parente59aeccf5e8ba5ea5e430b5a193aec86a3fc38ab (diff)
parentde8a27cc9f31b7f900200a3a80d7b49636f0ecc8 (diff)
downloadsystray-master_bak.tar.bz2
Merge pull request #7 from getlantern/back-from-lanternmaster_bak
Back from lantern
-rw-r--r--systray.go21
-rw-r--r--systray_darwin.m3
-rw-r--r--systray_nonwindows.go10
3 files changed, 19 insertions, 15 deletions
diff --git a/systray.go b/systray.go
index b3e7c82..7abc072 100644
--- a/systray.go
+++ b/systray.go
@@ -39,7 +39,7 @@ var (
menuItems = make(map[int32]*MenuItem)
menuItemsLock sync.RWMutex
- currentId int32
+ currentID int32
)
// Run initializes GUI and starts the event loop, then invokes the onReady
@@ -61,54 +61,59 @@ func Quit() {
quit()
}
-// Add menu item with designated title and tooltip, returning a channel that
-// notifies whenever that menu item has been clicked.
+// AddMenuItem adds menu item with designated title and tooltip, returning a channel
+// that notifies whenever that menu item is clicked.
//
-// Menu items are keyed to an id. If the same id is added twice, the 2nd one
-// overwrites the first.
-//
-// AddMenuItem can be safely invoked from different goroutines.
+// It can be safely invoked from different goroutines.
func AddMenuItem(title string, tooltip string) *MenuItem {
- id := atomic.AddInt32(&currentId, 1)
+ id := atomic.AddInt32(&currentID, 1)
item := &MenuItem{nil, id, title, tooltip, false, false}
item.ClickedCh = make(chan interface{})
item.update()
return item
}
+// SetTitle set the text to display on a menu item
func (item *MenuItem) SetTitle(title string) {
item.title = title
item.update()
}
+// SetTooltip set the tooltip to show when mouse hover
func (item *MenuItem) SetTooltip(tooltip string) {
item.tooltip = tooltip
item.update()
}
+// Disabled checkes if the menu item is disabled
func (item *MenuItem) Disabled() bool {
return item.disabled
}
+// Enable a menu item regardless if it's previously enabled or not
func (item *MenuItem) Enable() {
item.disabled = false
item.update()
}
+// Disable a menu item regardless if it's previously disabled or not
func (item *MenuItem) Disable() {
item.disabled = true
item.update()
}
+// Checked returns if the menu item has a check mark
func (item *MenuItem) Checked() bool {
return item.checked
}
+// Check a menu item regardless if it's previously checked or not
func (item *MenuItem) Check() {
item.checked = true
item.update()
}
+// Uncheck a menu item regardless if it's previously unchecked or not
func (item *MenuItem) Uncheck() {
item.checked = false
item.update()
diff --git a/systray_darwin.m b/systray_darwin.m
index f266cf1..14bb3b9 100644
--- a/systray_darwin.m
+++ b/systray_darwin.m
@@ -52,8 +52,7 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self->statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
- NSZone *menuZone = [NSMenu menuZone];
- self->menu = [[NSMenu allocWithZone:menuZone] init];
+ self->menu = [[NSMenu alloc] init];
[self->menu setAutoenablesItems: FALSE];
[self->statusItem setMenu:self->menu];
systray_ready();
diff --git a/systray_nonwindows.go b/systray_nonwindows.go
index f570b42..ed060ca 100644
--- a/systray_nonwindows.go
+++ b/systray_nonwindows.go
@@ -36,18 +36,18 @@ func SetTitle(title string) {
C.setTitle(C.CString(title))
}
-// SetTitle sets the systray tooltip to display on mouse hover of the tray icon,
+// SetTooltip sets the systray tooltip to display on mouse hover of the tray icon,
// only available on Mac and Windows.
func SetTooltip(tooltip string) {
C.setTooltip(C.CString(tooltip))
}
func addOrUpdateMenuItem(item *MenuItem) {
- var disabled C.short = 0
+ var disabled C.short
if item.disabled {
disabled = 1
}
- var checked C.short = 0
+ var checked C.short
if item.checked {
checked = 1
}
@@ -66,6 +66,6 @@ func systray_ready() {
}
//export systray_menu_item_selected
-func systray_menu_item_selected(cId C.int) {
- systrayMenuItemSelected(int32(cId))
+func systray_menu_item_selected(cID C.int) {
+ systrayMenuItemSelected(int32(cID))
}