From 561ec3f7207fb3d781ad82f70f1721e204b02378 Mon Sep 17 00:00:00 2001 From: Yevhen Pavlov Date: Sun, 31 Mar 2024 23:06:39 +0300 Subject: [PATCH] feat: Add About menu item --- cmd/app/main.go | 6 +++++- internal/mouse/mouse.go | 4 +++- internal/tray/tray.go | 4 ++++ internal/utils/about.go | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 internal/utils/about.go diff --git a/cmd/app/main.go b/cmd/app/main.go index 9503dad..16ae094 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -5,8 +5,12 @@ import ( "github.com/sonjek/mouse-stay-up/internal/tray" ) +const ( + GitRepo string = "https://github.com/sonjek/mouse-stay-up" +) + func main() { - mc := mouse.NewController() + mc := mouse.NewController(GitRepo) trayIcon := tray.NewTray(mc) trayIcon.Run() } diff --git a/internal/mouse/mouse.go b/internal/mouse/mouse.go index f2d766e..e76872e 100644 --- a/internal/mouse/mouse.go +++ b/internal/mouse/mouse.go @@ -9,13 +9,15 @@ import ( type Controller struct { Enabled bool + GitRepo string SleepInterval time.Duration LastX, LastY int } -func NewController() *Controller { +func NewController(gitRepo string) *Controller { return &Controller{ Enabled: true, + GitRepo: gitRepo, } } diff --git a/internal/tray/tray.go b/internal/tray/tray.go index c2cbef3..1354b0d 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -8,6 +8,7 @@ import ( "github.com/getlantern/systray" "github.com/sonjek/mouse-stay-up/internal/mouse" + "github.com/sonjek/mouse-stay-up/internal/utils" ) var ( @@ -61,6 +62,7 @@ func (t *Tray) onReady() { mDisable := systray.AddMenuItem("Disable", "Disable mouse movement") mInterval := systray.AddMenuItem("Sleep Interval", "Set mouse movement interval") systray.AddSeparator() + mAbout := systray.AddMenuItem("About", "Open GitHub repo") mExit := systray.AddMenuItem("Exit", "Exit the application") // Hide the enable option since it's already enabled by default @@ -101,6 +103,8 @@ func (t *Tray) onReady() { // When an interval item is clicked, update the sleep interval and checkmarks t.mouseController.SetSleepIntervalSec(interval) t.updateIntervalChecks(interval) + case <-mAbout.ClickedCh: + utils.OpenWebPage(t.mouseController.GitRepo) case <-mExit.ClickedCh: systray.Quit() return diff --git a/internal/utils/about.go b/internal/utils/about.go new file mode 100644 index 0000000..5461326 --- /dev/null +++ b/internal/utils/about.go @@ -0,0 +1,15 @@ +package utils + +import ( + "os/exec" + "runtime" +) + +func OpenWebPage(url string) { + switch runtime.GOOS { + case "darwin": + exec.Command("open", url).Start() + case "linux": + exec.Command("xdg-open", url).Start() + } +}