aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOx Cart2015-02-12 21:34:43 -0600
committerOx Cart2015-02-12 21:34:43 -0600
commit42246e6e5bea55bf70a4c07a22cd4e2a4b47589f (patch)
tree4805e59a3cc863d970f72b136930af4c4b2d86d3
parent0f459768ff159adb288e5ca51eb7718801dad4dc (diff)
downloadsystray-42246e6e5bea55bf70a4c07a22cd4e2a4b47589f.tar.bz2
Switching to integer ids
-rw-r--r--systray.go12
-rw-r--r--systray.h4
-rw-r--r--systray_darwin.m16
3 files changed, 16 insertions, 16 deletions
diff --git a/systray.go b/systray.go
index 5d753cc..38fcd6c 100644
--- a/systray.go
+++ b/systray.go
@@ -8,8 +8,8 @@ package systray
import (
"runtime"
"sync"
+ "sync/atomic"
- "code.google.com/p/go-uuid/uuid"
"github.com/getlantern/golog"
)
@@ -20,7 +20,7 @@ type MenuItem struct {
ClickedCh chan interface{}
// id uniquely identify a menu item, not supposed to be modified
- id string
+ id int32
// title is the text shown on menu item
title string
// tooltip is the text shown when pointing to menu item
@@ -36,8 +36,10 @@ var (
readyCh = make(chan interface{})
clickedCh = make(chan interface{})
- menuItems = make(map[string]*MenuItem)
+ menuItems = make(map[int32]*MenuItem)
menuItemsLock sync.RWMutex
+
+ currentId int32
)
// Run initializes GUI and starts the event loop, then invokes the onReady
@@ -67,7 +69,7 @@ func Quit() {
//
// AddMenuItem can be safely invoked from different goroutines.
func AddMenuItem(title string, tooltip string) *MenuItem {
- id := uuid.New()
+ id := atomic.AddInt32(&currentId, 1)
item := &MenuItem{nil, id, title, tooltip, false, false}
item.ClickedCh = make(chan interface{})
item.update()
@@ -124,7 +126,7 @@ func systrayReady() {
readyCh <- nil
}
-func systrayMenuItemSelected(id string) {
+func systrayMenuItemSelected(id int32) {
menuItemsLock.RLock()
item := menuItems[id]
menuItemsLock.RUnlock()
diff --git a/systray.h b/systray.h
index 88ba563..819b65f 100644
--- a/systray.h
+++ b/systray.h
@@ -1,9 +1,9 @@
extern void systray_ready();
-extern void systray_menu_item_selected(char* menu_id);
+extern void systray_menu_item_selected(int menu_id);
int nativeLoop(void);
void setIcon(const char* iconBytes, int length);
void setTitle(char* title);
void setTooltip(char* tooltip);
-void add_or_update_menu_item(char* menuId, char* title, char* tooltip, short disabled, short checked);
+void add_or_update_menu_item(int menuId, char* title, char* tooltip, short disabled, short checked);
void quit();
diff --git a/systray_darwin.m b/systray_darwin.m
index 680f1df..010143f 100644
--- a/systray_darwin.m
+++ b/systray_darwin.m
@@ -4,27 +4,26 @@
@interface MenuItem : NSObject
{
@public
- NSString* menuId;
+ NSNumber* menuId;
NSString* title;
NSString* tooltip;
short disabled;
short checked;
}
--(id) initWithId: (const char*)theMenuId
+-(id) initWithId: (int)theMenuId
withTitle: (const char*)theTitle
withTooltip: (const char*)theTooltip
withDisabled: (short)theDisabled
withChecked: (short)theChecked;
@end
@implementation MenuItem
- -(id) initWithId: (const char*)theMenuId
+ -(id) initWithId: (int)theMenuId
withTitle: (const char*)theTitle
withTooltip: (const char*)theTooltip
withDisabled: (short)theDisabled
withChecked: (short)theChecked
{
- menuId = [[NSString alloc] initWithCString:theMenuId
- encoding:NSUTF8StringEncoding];
+ menuId = [NSNumber numberWithInt:theMenuId];
title = [[NSString alloc] initWithCString:theTitle
encoding:NSUTF8StringEncoding];
tooltip = [[NSString alloc] initWithCString:theTooltip
@@ -79,8 +78,8 @@
- (IBAction)menuHandler:(id)sender
{
- NSString* menuId = [sender representedObject];
- systray_menu_item_selected((char*)[menuId cStringUsingEncoding: NSUTF8StringEncoding]);
+ NSNumber* menuId = [sender representedObject];
+ systray_menu_item_selected(menuId.intValue);
}
- (void) add_or_update_menu_item:(MenuItem*) item
@@ -151,9 +150,8 @@ void setTooltip(char* ctooltip) {
runInMainThread(@selector(setTooltip:), (id)tooltip);
}
-void add_or_update_menu_item(char* menuId, char* title, char* tooltip, short disabled, short checked) {
+void add_or_update_menu_item(int menuId, char* title, char* tooltip, short disabled, short checked) {
MenuItem* item = [[MenuItem alloc] initWithId: menuId withTitle: title withTooltip: tooltip withDisabled: disabled withChecked: checked];
- free(menuId);
free(title);
free(tooltip);
runInMainThread(@selector(add_or_update_menu_item:), (id)item);