From 5b4346dabe5db16fdd71561b2b9fc80c4c686f57 Mon Sep 17 00:00:00 2001 From: Ox Cart Date: Mon, 16 Mar 2020 07:25:48 -0500 Subject: [PATCH] Code review updates --- example/main.go | 2 ++ systray.go | 6 ++---- systray_darwin.m | 18 ++++++------------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/example/main.go b/example/main.go index dd793e4..2a9f78c 100644 --- a/example/main.go +++ b/example/main.go @@ -62,11 +62,13 @@ func onReady() { toggle := func() { if shown { subMenuBottom.Check() + subMenuBottom2.Hide() mQuitOrig.Hide() mEnabled.Hide() shown = false } else { subMenuBottom.Uncheck() + subMenuBottom2.Show() mQuitOrig.Show() mEnabled.Show() shown = true diff --git a/systray.go b/systray.go index 0a1ef36..9e84eaa 100644 --- a/systray.go +++ b/systray.go @@ -114,8 +114,7 @@ func Quit() { } } -// AddMenuItem adds menu item with designated title and tooltip, returning a channel -// that notifies whenever that menu item is clicked. +// AddMenuItem adds a menu item with the designated title and tooltip. // // It can be safely invoked from different goroutines. func AddMenuItem(title string, tooltip string) *MenuItem { @@ -129,8 +128,7 @@ func AddSeparator() { addSeparator(atomic.AddInt32(¤tID, 1)) } -// AddSubMenuItem adds nested sub-menu item with designated title and tooltip, returning a channel -// that notifies whenever that menu item is clicked. +// AddSubMenuItem adds a nested sub-menu item with the designated title and tooltip. // // It can be safely invoked from different goroutines. func (item *MenuItem) AddSubMenuItem(title string, tooltip string) *MenuItem { diff --git a/systray_darwin.m b/systray_darwin.m index cf15282..bd14dcc 100644 --- a/systray_darwin.m +++ b/systray_darwin.m @@ -181,13 +181,10 @@ NSMenuItem *find_menu_item(NSMenu *ourMenu, NSNumber *menuId) { - (void) hide_menu_item:(NSNumber*) menuId { - NSMenuItem* menuItem; - int existedMenuIndex = [menu indexOfItemWithRepresentedObject: menuId]; - if (existedMenuIndex == -1) { - return; + NSMenuItem* menuItem = find_menu_item(menu, menuId); + if (menuItem != NULL) { + [menuItem setHidden:TRUE]; } - menuItem = [menu itemAtIndex: existedMenuIndex]; - [menuItem setHidden:TRUE]; } - (void) setMenuItemIcon:(NSArray*)imageAndMenuId { @@ -204,13 +201,10 @@ NSMenuItem *find_menu_item(NSMenu *ourMenu, NSNumber *menuId) { - (void) show_menu_item:(NSNumber*) menuId { - NSMenuItem* menuItem; - int existedMenuIndex = [menu indexOfItemWithRepresentedObject: menuId]; - if (existedMenuIndex == -1) { - return; + NSMenuItem* menuItem = find_menu_item(menu, menuId); + if (menuItem != NULL) { + [menuItem setHidden:FALSE]; } - menuItem = [menu itemAtIndex: existedMenuIndex]; - [menuItem setHidden:FALSE]; } - (void) quit