144 lines
3.6 KiB
Go
144 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"github.com/getlantern/systray"
|
|
"go.wit.com/lib/debugger"
|
|
)
|
|
|
|
func systrayMain() {
|
|
onExit := func() {
|
|
fmt.Println("Starting onExit")
|
|
|
|
now := time.Now()
|
|
ioutil.WriteFile(fmt.Sprintf(`/tmp/on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644)
|
|
now = time.Now()
|
|
ioutil.WriteFile(fmt.Sprintf(`/tmp/on_exit_%d.2.txt`, now.UnixNano()), []byte(now.String()), 0644)
|
|
|
|
fmt.Println("Finished onExit")
|
|
}
|
|
// Should be called at the very beginning of main().
|
|
systray.Run(onReady, onExit)
|
|
}
|
|
|
|
var mHide *systray.MenuItem
|
|
var mShow *systray.MenuItem
|
|
var mChecked *systray.MenuItem
|
|
|
|
func onReady() {
|
|
systray.SetIcon(myIcon)
|
|
systray.SetTitle("Awesome App")
|
|
systray.SetTooltip("Lantern")
|
|
mDump := systray.AddMenuItem("Debug Window", "Debug Window")
|
|
/*
|
|
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(myIcon)
|
|
systray.SetTitle("Awesome App")
|
|
systray.SetTooltip("Pretty awesome棒棒嗒")
|
|
|
|
mShow = systray.AddMenuItem("Show 640x480", "Show 480")
|
|
mHide = systray.AddMenuItem("Hide Window", "Hide Window")
|
|
|
|
mChange := systray.AddMenuItem("Change Me", "Change Me")
|
|
mChecked = systray.AddMenuItem("Unchecked", "Check Me")
|
|
mEnabled := systray.AddMenuItem("Enabled", "Enabled")
|
|
mUrl := systray.AddMenuItem("Open Lantern.org", "my home")
|
|
// mQuit := systray.AddMenuItem("退出", "Quit the whole app")
|
|
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
|
|
|
// Sets the icon of a menu item. Only available on Mac.
|
|
mQuit.SetIcon(myIcon)
|
|
|
|
systray.AddSeparator()
|
|
mToggle := systray.AddMenuItem("Toggle", "Toggle the Quit button")
|
|
shown := true
|
|
// var blah struct{int}
|
|
// blah := make(chan struct{})
|
|
for {
|
|
select {
|
|
case <-mChange.ClickedCh:
|
|
log.Println("START")
|
|
log.Println("END")
|
|
mChange.SetTitle("I've Changed")
|
|
case <-mChecked.ClickedCh:
|
|
log.Println("CHECKED START")
|
|
if mChecked.Checked() {
|
|
mChecked.Uncheck()
|
|
mChecked.SetTitle("Unchecked")
|
|
log.Println("UNCHECKED")
|
|
} else {
|
|
mChecked.Check()
|
|
mChecked.SetTitle("Checked")
|
|
log.Println("CHECKED")
|
|
}
|
|
spew.Dump(mChecked.ClickedCh)
|
|
log.Println("CHECKED END")
|
|
case <-mDump.ClickedCh:
|
|
log.Println("START")
|
|
debugger.DebugWindow(myGui)
|
|
log.Println("END")
|
|
case <-mShow.ClickedCh:
|
|
log.Println("START Show()")
|
|
debugger.DebugWindow(myGui)
|
|
log.Println("END")
|
|
case <-mHide.ClickedCh:
|
|
log.Println("START Hide()")
|
|
/*
|
|
window := gui.Data.WindowMap["splash"]
|
|
if window != nil {
|
|
box := window.BoxMap["splash"]
|
|
box.Window.UiTab.Hide()
|
|
}
|
|
*/
|
|
log.Println("END")
|
|
case <-mEnabled.ClickedCh:
|
|
log.Println("START")
|
|
mEnabled.SetTitle("Disabled")
|
|
mEnabled.Disable()
|
|
log.Println("END")
|
|
case <-mUrl.ClickedCh:
|
|
log.Println("START")
|
|
// open.Run("https://www.getlantern.org")
|
|
log.Println("END")
|
|
case <-mToggle.ClickedCh:
|
|
log.Println("START")
|
|
if shown {
|
|
// mQuitOrig.Hide()
|
|
mEnabled.Hide()
|
|
shown = false
|
|
} else {
|
|
// mQuitOrig.Show()
|
|
mEnabled.Show()
|
|
shown = true
|
|
}
|
|
log.Println("END")
|
|
// os.Exit(0)
|
|
case <-mQuit.ClickedCh:
|
|
log.Println("START")
|
|
log.Println("Systray Quit now...")
|
|
systray.Quit()
|
|
log.Println("END")
|
|
log.Println("os.Exit() now...")
|
|
os.Exit(0)
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}
|