Skip to content

Commit

Permalink
systray: enable only if the StatusNotifierWatcher is available on the…
Browse files Browse the repository at this point in the history
… supported unix system
  • Loading branch information
lucor committed Jan 11, 2025
1 parent 535903c commit 632deda
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- all: update Fyne to v2.5.3
- all: update age to v1.2.1
- ui: fix a possible nil pointer on loginURL when upgrading paw from previous versions
- systray: enable only if the StatusNotifierWatcher is available on the supported unix system

- deps update:
- fyne.io/fyne v2.5.3
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
filippo.io/age v1.2.1
fyne.io/fyne/v2 v2.5.3
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2
github.com/godbus/dbus/v5 v5.1.0
github.com/stretchr/testify v1.8.4
golang.design/x/clipboard v0.7.0
golang.org/x/crypto v0.32.0
Expand All @@ -28,7 +29,6 @@ require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-text/render v0.2.0 // indirect
github.com/go-text/typesetting v0.2.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
Expand Down
29 changes: 29 additions & 0 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/godbus/dbus/v5"

"lucor.dev/paw/internal/agent"
"lucor.dev/paw/internal/icon"
Expand Down Expand Up @@ -86,6 +87,10 @@ func (a *app) agentClient() agent.PawAgent {

func (a *app) makeSysTray() {
if desk, ok := fyne.CurrentApp().(desktop.App); ok {
if err := checkStatusNotifierWatcher(); err != nil {
log.Println("systray not available: %w", err)
return
}
a.win.SetCloseIntercept(a.win.Hide) // don't close the window if system tray used
menu := fyne.NewMenu("Vaults", a.makeVaultMenuItems()...)
desk.SetSystemTrayMenu(menu)
Expand Down Expand Up @@ -260,3 +265,27 @@ func imageFromResource(resource fyne.Resource) *canvas.Image {
img.SetMinSize(fyne.NewSize(64, 64))
return img
}

// checkStatusNotifierWatcher checks if the StatusNotifierWatcher is available on the supported unix system
func checkStatusNotifierWatcher() error {
// systrayUnixSupportedOSes list the supported unix system by https://github.com/fyne-io/systray
// see: https://github.com/fyne-io/systray/blob/master/systray_unix.go#L1
systrayUnixSupportedOSes := map[string]bool{
"linux": true,
"freebsd": true,
"openbsd": true,
"netbsd": true,
}
if !systrayUnixSupportedOSes[runtime.GOOS] {
return nil
}
conn, err := dbus.ConnectSessionBus()
if err != nil {
return fmt.Errorf("Failed to connect to session bus: %w", err)

Check failure on line 284 in internal/ui/app.go

View workflow job for this annotation

GitHub Actions / lint

error strings should not be capitalized (ST1005)
}
defer conn.Close()

obj := conn.Object("org.kde.StatusNotifierWatcher", "/StatusNotifierWatcher")
call := obj.Call("org.kde.StatusNotifierWatcher.RegisterStatusNotifierItem", 0, "/StatusNotifierItem")
return call.Err
}

0 comments on commit 632deda

Please sign in to comment.