From 2c869c5e11486c1263d78ac6f8da86ee76083555 Mon Sep 17 00:00:00 2001 From: Allan Frese Date: Fri, 10 Jul 2020 18:45:27 +0200 Subject: [PATCH] added checkmark in menu --- src/app.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/app.go b/src/app.go index a128527..27ceb20 100644 --- a/src/app.go +++ b/src/app.go @@ -41,6 +41,8 @@ var menuItems = []trayhost.MenuItem{ }, } +var menuItemsCopy = []trayhost.MenuItem{} + func appInit() { // On macOS, when you run an app bundle, the working directory of the executed process @@ -61,6 +63,18 @@ func appInit() { log.Fatalln(err) } + // Set initial checkmark for autostart + if existsLaunchConf() { + for i, m := range menuItems { + if m.Title == "Startup on login" { + menuItems[i].Title = "√ Startup on login" + } + } + } + for _, m := range menuItems { + menuItemsCopy = append(menuItemsCopy, m) + } + trayhost.Initialize("Pagerduty Notifier", iconData, menuItems) } @@ -68,9 +82,24 @@ func toggleStartup() { if existsLaunchConf() { deleteLaunchConf() appNotify("Pagerduty Notifier", "Removed from Launch configuration", "", nil, 10*time.Second) + + for i, m := range menuItemsCopy { + if m.Title == "√ Startup on login" { + menuItemsCopy[i].Title = "Startup on login" + } + } + trayhost.UpdateMenu(menuItemsCopy) + } else { writeLaunchConf() appNotify("Pagerduty Notifier", "Added to launch configuration", "", nil, 10*time.Second) + + for i, m := range menuItemsCopy { + if m.Title == "Startup on login" { + menuItemsCopy[i].Title = "√ Startup on login" + } + } + trayhost.UpdateMenu(menuItemsCopy) } }