Skip to content

Commit

Permalink
Merge pull request #71 from Jacalz/go1.19-base
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz authored Dec 30, 2023
2 parents 104f5ef + 12d7b25 commit d160fd3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 34 deletions.
1 change: 0 additions & 1 deletion example/icon/iconunix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin
// +build linux darwin

// File generated by 2goarray (http://github.com/cratonica/2goarray)

Expand Down
1 change: 0 additions & 1 deletion example/icon/iconwin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

// File generated by 2goarray v0.1.0 (http://github.com/cratonica/2goarray)

Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module fyne.io/systray

go 1.13

require golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9
go 1.19

require (
github.com/godbus/dbus/v5 v5.0.4
github.com/tevino/abool v1.2.0 // indirect
github.com/godbus/dbus/v5 v5.1.0
golang.org/x/sys v0.15.0
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA=
github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
8 changes: 4 additions & 4 deletions systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
menuItems = make(map[uint32]*MenuItem)
menuItemsLock sync.RWMutex

currentID = uint32(0)
currentID atomic.Uint32
quitOnce sync.Once
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func (item *MenuItem) String() string {
func newMenuItem(title string, tooltip string, parent *MenuItem) *MenuItem {
return &MenuItem{
ClickedCh: make(chan struct{}),
id: atomic.AddUint32(&currentID, 1),
id: currentID.Add(1),
title: title,
tooltip: tooltip,
disabled: false,
Expand Down Expand Up @@ -157,12 +157,12 @@ func AddMenuItemCheckbox(title string, tooltip string, checked bool) *MenuItem {

// AddSeparator adds a separator bar to the menu
func AddSeparator() {
addSeparator(atomic.AddUint32(&currentID, 1), 0)
addSeparator(currentID.Add(1), 0)
}

// AddSeparator adds a separator bar to the submenu
func (item *MenuItem) AddSeparator() {
addSeparator(atomic.AddUint32(&currentID, 1), item.id)
addSeparator(currentID.Add(1), item.id)
}

// AddSubMenuItem adds a nested sub-menu item with the designated title and tooltip.
Expand Down
1 change: 0 additions & 1 deletion systray_menu_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

package systray

Expand Down
1 change: 0 additions & 1 deletion systray_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || freebsd || openbsd || netbsd
// +build linux freebsd openbsd netbsd

//Note that you need to have github.com/knightpp/dbus-codegen-go installed from "custom" branch
//go:generate dbus-codegen-go -prefix org.kde -package notifier -output internal/generated/notifier/status_notifier_item.go internal/StatusNotifierItem.xml
Expand Down
13 changes: 5 additions & 8 deletions systray_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package systray

Expand All @@ -13,10 +12,10 @@ import (
"path/filepath"
"sort"
"sync"
"sync/atomic"
"syscall"
"unsafe"

"github.com/tevino/abool"
"golang.org/x/sys/windows"
)

Expand Down Expand Up @@ -237,12 +236,12 @@ type winTray struct {
wmSystrayMessage,
wmTaskbarCreated uint32

initialized *abool.AtomicBool
initialized atomic.Bool
}

// isReady checks if the tray as already been initialized. It is not goroutine safe with in regard to the initialization function, but prevents a panic when functions are called too early.
func (t *winTray) isReady() bool {
return t.initialized.IsSet()
return t.initialized.Load()
}

// Loads an image from file and shows it in tray.
Expand Down Expand Up @@ -290,9 +289,7 @@ func (t *winTray) setTooltip(src string) error {
return t.nid.modify()
}

var wt = winTray{
initialized: abool.New(),
}
var wt = winTray{}

// WindowProc callback function that processes messages sent to a window.
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573(v=vs.85).aspx
Expand Down Expand Up @@ -895,7 +892,7 @@ func registerSystray() {
return
}

wt.initialized.Set()
wt.initialized.Store(true)
systrayReady()
}

Expand Down
13 changes: 6 additions & 7 deletions systray_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build windows
// +build windows

package systray

Expand Down Expand Up @@ -44,24 +43,24 @@ func TestBaseWindowsTray(t *testing.T) {
t.Errorf("SetIcon failed: %s", err)
}

var id int32 = 0
err := wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple enabled", false, false)
var id atomic.Int32
err := wt.addOrUpdateMenuItem(id.Add(1), "Simple enabled", false, false)
if err != nil {
t.Errorf("mergeMenuItem failed: %s", err)
}
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple disabled", true, false)
err = wt.addOrUpdateMenuItem(id.Add(1), "Simple disabled", true, false)
if err != nil {
t.Errorf("mergeMenuItem failed: %s", err)
}
err = wt.addSeparatorMenuItem(atomic.AddInt32(&id, 1))
err = wt.addSeparatorMenuItem(id.Add(1))
if err != nil {
t.Errorf("addSeparatorMenuItem failed: %s", err)
}
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple checked enabled", false, true)
err = wt.addOrUpdateMenuItem(id.Add(1), "Simple checked enabled", false, true)
if err != nil {
t.Errorf("mergeMenuItem failed: %s", err)
}
err = wt.addOrUpdateMenuItem(atomic.AddInt32(&id, 1), "Simple checked disabled", true, true)
err = wt.addOrUpdateMenuItem(id.Add(1), "Simple checked disabled", true, true)
if err != nil {
t.Errorf("mergeMenuItem failed: %s", err)
}
Expand Down

0 comments on commit d160fd3

Please sign in to comment.