aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOx Cart2017-08-28 14:36:05 -0500
committerOx Cart2017-08-28 14:51:15 -0500
commit66e6fad5eea92d7adda31abfae7a5a52070dfae5 (patch)
treed8b5e5142bc7325e22314d43f39b067f853fe587
parent6f1d1d82e189395fa6266fcdb665a50531918d25 (diff)
downloadsystray-66e6fad5eea92d7adda31abfae7a5a52070dfae5.tar.bz2
Only quit once
-rw-r--r--systray.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/systray.go b/systray.go
index d4f86cc..33f6172 100644
--- a/systray.go
+++ b/systray.go
@@ -15,6 +15,11 @@ import (
"github.com/getlantern/golog"
)
+var (
+ hasStarted = int64(0)
+ hasQuit = int64(0)
+)
+
// MenuItem is used to keep track each menu item of systray
// Don't create it directly, use the one systray.AddMenuItem() returned
type MenuItem struct {
@@ -50,6 +55,7 @@ var (
// Should be called at the very beginning of main() to lock at main thread.
func Run(onReady func(), onExit func()) {
runtime.LockOSThread()
+ atomic.StoreInt64(&hasStarted, 1)
if onReady == nil {
systrayReady = func() {}
@@ -77,7 +83,9 @@ func Run(onReady func(), onExit func()) {
// Quit the systray
func Quit() {
- quit()
+ if atomic.LoadInt64(&hasStarted) == 1 && atomic.CompareAndSwapInt64(&hasQuit, 0, 1) {
+ quit()
+ }
}
// AddMenuItem adds menu item with designated title and tooltip, returning a channel