Added hide/show for darwin

This commit is contained in:
Ox Cart
2017-09-11 16:06:23 -05:00
parent 66e6fad5ee
commit 620c9318ea
5 changed files with 68 additions and 2 deletions
+12 -2
View File
@@ -25,9 +25,9 @@ func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Awesome App")
systray.SetTooltip("Lantern")
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
mQuitOrig := systray.AddMenuItem("Quit", "Quit the whole app")
go func() {
<-mQuit.ClickedCh
<-mQuitOrig.ClickedCh
fmt.Println("Requesting quit")
systray.Quit()
fmt.Println("Finished quitting")
@@ -44,6 +44,8 @@ func onReady() {
systray.AddMenuItem("Ignored", "Ignored")
mUrl := systray.AddMenuItem("Open Lantern.org", "my home")
mQuit := systray.AddMenuItem("退出", "Quit the whole app")
mToggle := systray.AddMenuItem("Toggle", "Toggle the Quit button")
shown := true
for {
select {
case <-mChange.ClickedCh:
@@ -61,6 +63,14 @@ func onReady() {
mEnabled.Disable()
case <-mUrl.ClickedCh:
open.Run("https://www.getlantern.org")
case <-mToggle.ClickedCh:
if shown {
mQuitOrig.Hide()
shown = false
} else {
mQuitOrig.Show()
shown = true
}
case <-mQuit.ClickedCh:
systray.Quit()
fmt.Println("Quit2 now...")
+10
View File
@@ -129,6 +129,16 @@ func (item *MenuItem) Disable() {
item.update()
}
// Hide hides a menu item
func (item *MenuItem) Hide() {
hideMenuItem(item)
}
// Show shows a previously hidden menu item
func (item *MenuItem) Show() {
showMenuItem(item)
}
// Checked returns if the menu item has a check mark
func (item *MenuItem) Checked() bool {
return item.checked
+2
View File
@@ -7,4 +7,6 @@ void setIcon(const char* iconBytes, int length);
void setTitle(char* title);
void setTooltip(char* tooltip);
void add_or_update_menu_item(int menuId, char* title, char* tooltip, short disabled, short checked);
void hide_menu_item(int menuId);
void show_menu_item(int menuId);
void quit();
+32
View File
@@ -108,6 +108,28 @@
}
}
- (void) hide_menu_item:(NSNumber*) menuId
{
NSMenuItem* menuItem;
int existedMenuIndex = [menu indexOfItemWithRepresentedObject: menuId];
if (existedMenuIndex == -1) {
return;
}
menuItem = [menu itemAtIndex: existedMenuIndex];
[menuItem setHidden:TRUE];
}
- (void) show_menu_item:(NSNumber*) menuId
{
NSMenuItem* menuItem;
int existedMenuIndex = [menu indexOfItemWithRepresentedObject: menuId];
if (existedMenuIndex == -1) {
return;
}
menuItem = [menu itemAtIndex: existedMenuIndex];
[menuItem setHidden:NO];
}
- (void) quit
{
[NSApp terminate:self];
@@ -156,6 +178,16 @@ void add_or_update_menu_item(int menuId, char* title, char* tooltip, short disab
runInMainThread(@selector(add_or_update_menu_item:), (id)item);
}
void hide_menu_item(int menuId) {
NSNumber *mId = [NSNumber numberWithInt:menuId];
runInMainThread(@selector(hide_menu_item:), (id)mId);
}
void show_menu_item(int menuId) {
NSNumber *mId = [NSNumber numberWithInt:menuId];
runInMainThread(@selector(show_menu_item:), (id)mId);
}
void quit() {
runInMainThread(@selector(quit), nil);
}
+12
View File
@@ -60,6 +60,18 @@ func addOrUpdateMenuItem(item *MenuItem) {
)
}
func hideMenuItem(item *MenuItem) {
C.hide_menu_item(
C.int(item.id),
)
}
func showMenuItem(item *MenuItem) {
C.show_menu_item(
C.int(item.id),
)
}
//export systray_ready
func systray_ready() {
systrayReady()