From d8b16674dd0d038a30e89f934a6686d689741c2b Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 1 May 2022 16:51:52 +0930 Subject: [PATCH] Only do systray stuff on windows --- dau.go | 40 +------------------------------------ dau_nonwindows.go | 11 ++++++++++ dau_windows.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 dau_nonwindows.go create mode 100644 dau_windows.go diff --git a/dau.go b/dau.go index 001d2b0..db86e07 100644 --- a/dau.go +++ b/dau.go @@ -21,7 +21,6 @@ import ( daulog "github.com/tardisx/discord-auto-upload/log" "github.com/tardisx/discord-auto-upload/upload" - "github.com/getlantern/systray" "github.com/skratchdot/open-golang/open" // "github.com/tardisx/discord-auto-upload/upload" @@ -83,7 +82,7 @@ func main() { startWatchers(config, up, configChanged) }() - systray.Run(func() { onReady(config) }, onExit) + mainloop(config) } @@ -207,43 +206,6 @@ func parseOptions() { } -func onReady(c *config.ConfigService) { - - systray.SetIcon(appIcon) - //systray.SetTitle("DAU") - systray.SetTooltip(fmt.Sprintf("discord-auto-upload %s", version.CurrentVersion)) - openApp := systray.AddMenuItem("Open", "Open in web browser") - gh := systray.AddMenuItem("Github", "Open project page") - ghr := systray.AddMenuItem("Release Notes", "Open project release notes") - quit := systray.AddMenuItem("Quit", "Quit") - - go func() { - <-quit.ClickedCh - systray.Quit() - }() - - go func() { - for { - select { - case <-openApp.ClickedCh: - openWebBrowser(c.Config.Port) - case <-gh.ClickedCh: - open.Start("https://github.com/tardisx/discord-auto-upload") - case <-ghr.ClickedCh: - open.Start(fmt.Sprintf("https://github.com/tardisx/discord-auto-upload/releases/tag/%s", version.CurrentVersion)) - } - } - }() - - // Sets the icon of a menu item. Only available on Mac and Windows. - // mQuit.SetIcon(icon.Data) -} - -func onExit() { - // clean up here - daulog.Info("quitting on user request") -} - func openWebBrowser(port int) { address := fmt.Sprintf("http://localhost:%d", port) open.Start(address) diff --git a/dau_nonwindows.go b/dau_nonwindows.go new file mode 100644 index 0000000..b236a00 --- /dev/null +++ b/dau_nonwindows.go @@ -0,0 +1,11 @@ +//go:build !windows + +package main + +import "github.com/tardisx/discord-auto-upload/config" + +func mainloop(c *config.ConfigService) { + + ch := make(chan bool) + <-ch +} diff --git a/dau_windows.go b/dau_windows.go new file mode 100644 index 0000000..75bad2b --- /dev/null +++ b/dau_windows.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + "github.com/getlantern/systray" + "github.com/skratchdot/open-golang/open" + "github.com/tardisx/discord-auto-upload/config" + daulog "github.com/tardisx/discord-auto-upload/log" + "github.com/tardisx/discord-auto-upload/version" +) + +func mainloop(c *config.ConfigService) { + systray.Run(func() { onReady(c) }, onExit) +} + +func onReady(c *config.ConfigService) { + + systray.SetIcon(appIcon) + //systray.SetTitle("DAU") + systray.SetTooltip(fmt.Sprintf("discord-auto-upload %s", version.CurrentVersion)) + openApp := systray.AddMenuItem("Open", "Open in web browser") + gh := systray.AddMenuItem("Github", "Open project page") + ghr := systray.AddMenuItem("Release Notes", "Open project release notes") + quit := systray.AddMenuItem("Quit", "Quit") + + go func() { + <-quit.ClickedCh + systray.Quit() + }() + + go func() { + for { + select { + case <-openApp.ClickedCh: + openWebBrowser(c.Config.Port) + case <-gh.ClickedCh: + open.Start("https://github.com/tardisx/discord-auto-upload") + case <-ghr.ClickedCh: + open.Start(fmt.Sprintf("https://github.com/tardisx/discord-auto-upload/releases/tag/%s", version.CurrentVersion)) + } + } + }() + + // Sets the icon of a menu item. Only available on Mac and Windows. + // mQuit.SetIcon(icon.Data) +} + +func onExit() { + // clean up here + daulog.Info("quitting on user request") +}