diff options
Diffstat (limited to 'vendor/github.com/getlantern/systray/example/main.go')
-rw-r--r-- | vendor/github.com/getlantern/systray/example/main.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/github.com/getlantern/systray/example/main.go b/vendor/github.com/getlantern/systray/example/main.go new file mode 100644 index 0000000..f889b3c --- /dev/null +++ b/vendor/github.com/getlantern/systray/example/main.go @@ -0,0 +1,84 @@ +package main + +import ( + "fmt" + "io/ioutil" + "time" + + "github.com/getlantern/systray" + "github.com/getlantern/systray/example/icon" + "github.com/skratchdot/open-golang/open" +) + +func main() { + onExit := func() { + fmt.Println("Starting onExit") + now := time.Now() + ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644) + fmt.Println("Finished onExit") + } + // Should be called at the very beginning of main(). + systray.Run(onReady, onExit) +} + +func onReady() { + systray.SetIcon(icon.Data) + systray.SetTitle("Awesome App") + systray.SetTooltip("Lantern") + mQuitOrig := systray.AddMenuItem("Quit", "Quit the whole app") + go func() { + <-mQuitOrig.ClickedCh + fmt.Println("Requesting quit") + systray.Quit() + fmt.Println("Finished quitting") + }() + + // We can manipulate the systray in other goroutines + go func() { + systray.SetIcon(icon.Data) + systray.SetTitle("Awesome App") + systray.SetTooltip("Pretty awesome棒棒嗒") + mChange := systray.AddMenuItem("Change Me", "Change Me") + mChecked := systray.AddMenuItem("Unchecked", "Check Me") + mEnabled := systray.AddMenuItem("Enabled", "Enabled") + systray.AddMenuItem("Ignored", "Ignored") + mUrl := systray.AddMenuItem("Open Lantern.org", "my home") + mQuit := systray.AddMenuItem("退出", "Quit the whole app") + systray.AddSeparator() + mToggle := systray.AddMenuItem("Toggle", "Toggle the Quit button") + shown := true + for { + select { + case <-mChange.ClickedCh: + mChange.SetTitle("I've Changed") + case <-mChecked.ClickedCh: + if mChecked.Checked() { + mChecked.Uncheck() + mChecked.SetTitle("Unchecked") + } else { + mChecked.Check() + mChecked.SetTitle("Checked") + } + case <-mEnabled.ClickedCh: + mEnabled.SetTitle("Disabled") + mEnabled.Disable() + case <-mUrl.ClickedCh: + open.Run("https://www.getlantern.org") + case <-mToggle.ClickedCh: + if shown { + mQuitOrig.Hide() + mEnabled.Hide() + shown = false + } else { + mQuitOrig.Show() + mEnabled.Show() + shown = true + } + case <-mQuit.ClickedCh: + systray.Quit() + fmt.Println("Quit2 now...") + return + } + } + }() +} |