Add systray with icon

This commit is contained in:
2022-05-01 12:37:05 +09:30
parent 06ac259e0a
commit b04ed6aa62
8 changed files with 84 additions and 7 deletions

59
dau.go
View File

@@ -11,16 +11,17 @@ import (
"strings"
"time"
_ "embed"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
// "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/upload"
"github.com/getlantern/systray"
"github.com/skratchdot/open-golang/open"
// "github.com/tardisx/discord-auto-upload/upload"
@@ -35,6 +36,9 @@ type watch struct {
uploader *upload.Uploader
}
//go:embed dau.ico
var appIcon []byte
func main() {
parseOptions()
@@ -54,8 +58,7 @@ func main() {
web.StartWebServer()
if config.Config.OpenBrowserOnStart {
address := fmt.Sprintf("http://localhost:%d", config.Config.Port)
open.Start(address)
openWebBrowser(config.Config.Port)
}
go func() {
@@ -72,7 +75,11 @@ func main() {
// create the watchers, restart them if config changes
// blocks forever
startWatchers(config, up, configChanged)
go func() {
startWatchers(config, up, configChanged)
}()
systray.Run(func() { onReady(config) }, onExit)
}
@@ -195,3 +202,45 @@ 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)
}