aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOx Cart2017-08-27 11:58:01 -0500
committerOx Cart2017-08-27 11:58:01 -0500
commit98b24bc00bf9f94d20a776253ee5086f2ae5b00c (patch)
tree714d5917e3b6057bb501a559de133cec488f3f08
parentf328fc3e81eb9ae48f27810bc6df210111e97743 (diff)
downloadsystray-98b24bc00bf9f94d20a776253ee5086f2ae5b00c.tar.bz2
Running onReady in separate goroutine
-rw-r--r--systray.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/systray.go b/systray.go
index 7eb17b4..5ee6609 100644
--- a/systray.go
+++ b/systray.go
@@ -53,8 +53,22 @@ func Run(onReady func(), onExit func()) {
if onReady == nil {
onReady = func() {}
+ } else {
+ // Run onReady on separate goroutine to avoid blocking event loop
+ origOnReady := onReady
+ readyCh := make(chan interface{})
+ go func() {
+ <-readyCh
+ origOnReady()
+ }()
+ onReady = func() {
+ close(readyCh)
+ }
}
systrayReady = onReady
+
+ // unlike onReady, onExit runs in the event loop to make sure it has time to
+ // finish before the process terminates
if onExit == nil {
onExit = func() {}
}