Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add About menu item #2

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 3 additions & 1 deletion internal/mouse/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions internal/utils/about.go
Original file line number Diff line number Diff line change
@@ -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()
}
}