Skip to content

Commit

Permalink
instance a few more things
Browse files Browse the repository at this point in the history
  • Loading branch information
DeedleFake committed Apr 11, 2023
1 parent 486902f commit 375c5c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package systray

import (
"sync"
"sync/atomic"
)

var (
Expand Down Expand Up @@ -111,5 +110,5 @@ func AddMenuItemCheckbox(title string, tooltip string, checked bool) *MenuItem {
func AddSeparator() {
initDefaultIcon()

defaultIcon.addSeparator(atomic.AddUint32(&currentID, 1), 0)
defaultIcon.addSeparator(0)
}
10 changes: 6 additions & 4 deletions menuitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package systray

import (
"fmt"
"sync/atomic"
)

// MenuItem is used to keep track each menu item of systray.
Expand All @@ -23,6 +22,8 @@ type MenuItem struct {
checked bool
// has the menu item a checkbox (Linux)
isCheckable bool
// icon is the icon that the item was created from
icon *Icon
// parent item, for sub menus
parent *MenuItem
}
Expand All @@ -35,22 +36,23 @@ func (item *MenuItem) String() string {
}

// newMenuItem returns a populated MenuItem object
func newMenuItem(title string, tooltip string, parent *MenuItem) *MenuItem {
func (icon *Icon) newMenuItem(title string, tooltip string, parent *MenuItem) *MenuItem {
return &MenuItem{
ClickedCh: make(chan struct{}),
id: atomic.AddUint32(&currentID, 1),
id: icon.nextID(),
title: title,
tooltip: tooltip,
disabled: false,
checked: false,
isCheckable: false,
icon: icon,
parent: parent,
}
}

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

// AddSubMenuItem adds a nested sub-menu item with the designated title and tooltip.
Expand Down
5 changes: 5 additions & 0 deletions systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package systray
import (
"log"
"sync"
"sync/atomic"
)

type Icon struct {
Expand All @@ -24,6 +25,10 @@ func NewIcon() (*Icon, error) {
}, nil
}

func (icon *Icon) nextID() uint32 {
return atomic.AddUint32(&icon.id, 1)
}

// This helper function allows us to call systrayExit only once,
// without accidentally calling it twice in the same lifetime.
func runSystrayExit() {
Expand Down

0 comments on commit 375c5c5

Please sign in to comment.