From 0a4c497fda68987daabad00594b3c123958beab8 Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Fri, 3 Mar 2023 20:06:32 +0100 Subject: [PATCH] initial commit from https://github.com/getlantern/systray example --- .gitignore | 2 + go.mod | 20 ++++++++++ go.sum | 29 +++++++++++++++ main.go | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb7d21a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +on_exit_*.txt +restictray \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..aedeb31 --- /dev/null +++ b/go.mod @@ -0,0 +1,20 @@ +module brainbaking.com/restictray + +go 1.19 + +require ( + github.com/getlantern/systray v1.2.1 + github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 +) + +require ( + github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect + github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect + github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect + github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect + github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect + github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect + github.com/go-stack/stack v1.8.0 // indirect + github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect + golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ce4956d --- /dev/null +++ b/go.sum @@ -0,0 +1,29 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= +github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= +github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So= +github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A= +github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 h1:guBYzEaLz0Vfc/jv0czrr2z7qyzTOGC9hiQ0VC+hKjk= +github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7/go.mod h1:zx/1xUUeYPy3Pcmet8OSXLbF47l+3y6hIPpyLWoR9oc= +github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0= +github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o= +github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc= +github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA= +github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA= +github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA= +github.com/getlantern/systray v1.2.1 h1:udsC2k98v2hN359VTFShuQW6GGprRprw6kD6539JikI= +github.com/getlantern/systray v1.2.1/go.mod h1:AecygODWIsBquJCJFop8MEQcJbWFfw/1yWbVabNgpCM= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= +github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..b0f350d --- /dev/null +++ b/main.go @@ -0,0 +1,107 @@ +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() { + now := time.Now() + ioutil.WriteFile(fmt.Sprintf(`on_exit_%d.txt`, now.UnixNano()), []byte(now.String()), 0644) + } + + systray.Run(onReady, onExit) +} + +func onReady() { + systray.SetTemplateIcon(icon.Data, 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.SetTemplateIcon(icon.Data, icon.Data) + systray.SetTitle("Awesome App") + systray.SetTooltip("Pretty awesome棒棒嗒") + mChange := systray.AddMenuItem("Change Me", "Change Me") + mChecked := systray.AddMenuItemCheckbox("Unchecked", "Check Me", true) + mEnabled := systray.AddMenuItem("Enabled", "Enabled") + // Sets the icon of a menu item. Only available on Mac. + mEnabled.SetTemplateIcon(icon.Data, icon.Data) + + systray.AddMenuItem("Ignored", "Ignored") + + subMenuTop := systray.AddMenuItem("SubMenuTop", "SubMenu Test (top)") + subMenuMiddle := subMenuTop.AddSubMenuItem("SubMenuMiddle", "SubMenu Test (middle)") + subMenuBottom := subMenuMiddle.AddSubMenuItemCheckbox("SubMenuBottom - Toggle Panic!", "SubMenu Test (bottom) - Hide/Show Panic!", false) + subMenuBottom2 := subMenuMiddle.AddSubMenuItem("SubMenuBottom - Panic!", "SubMenu Test (bottom)") + + mUrl := systray.AddMenuItem("Open UI", "my home") + mQuit := systray.AddMenuItem("退出", "Quit the whole app") + + // Sets the icon of a menu item. Only available on Mac. + mQuit.SetIcon(icon.Data) + + systray.AddSeparator() + mToggle := systray.AddMenuItem("Toggle", "Toggle the Quit button") + shown := true + toggle := func() { + if shown { + subMenuBottom.Check() + subMenuBottom2.Hide() + mQuitOrig.Hide() + mEnabled.Hide() + shown = false + } else { + subMenuBottom.Uncheck() + subMenuBottom2.Show() + mQuitOrig.Show() + mEnabled.Show() + 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 <-subMenuBottom2.ClickedCh: + panic("panic button pressed") + case <-subMenuBottom.ClickedCh: + toggle() + case <-mToggle.ClickedCh: + toggle() + case <-mQuit.ClickedCh: + systray.Quit() + fmt.Println("Quit2 now...") + return + } + } + }() +}