Skip to content

Commit 39eff9c

Browse files
authored
internal/tray, internal/ui: add status icon for when an exit node is active (#150)
1 parent 571e4cb commit 39eff9c

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed
14.4 KB
Loading

internal/tray/tray.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ var (
1414

1515
//go:embed status-icon-inactive.png
1616
statusIconInactive []byte
17+
18+
//go:embed status-icon-exit-node.png
19+
statusIconExitNode []byte
1720
)
1821

19-
func statusIcon(online bool) []byte {
20-
if online {
21-
return statusIconActive
22+
func statusIcon(s tsutil.Status) []byte {
23+
if !s.Online() {
24+
return statusIconInactive
2225
}
23-
return statusIconInactive
26+
if s.Status.ExitNodeStatus != nil {
27+
return statusIconExitNode
28+
}
29+
return statusIconActive
2430
}
2531

2632
type Tray struct {
@@ -31,7 +37,7 @@ type Tray struct {
3137
}
3238

3339
func New(online bool) *Tray {
34-
systray.SetIcon(statusIcon(online))
40+
systray.SetIcon(statusIcon(tsutil.Status{}))
3541
systray.SetTitle("Trayscale")
3642

3743
showWindow := systray.AddMenuItem("Show", "")
@@ -49,6 +55,10 @@ func New(online bool) *Tray {
4955
}
5056
}
5157

58+
func (t *Tray) ShowChan() <-chan struct{} {
59+
return t.showItem.ClickedCh
60+
}
61+
5262
func (t *Tray) ConnToggleChan() <-chan struct{} {
5363
return t.connToggleItem.ClickedCh
5464
}
@@ -57,27 +67,17 @@ func (t *Tray) SelfNodeChan() <-chan struct{} {
5767
return t.selfNodeItem.ClickedCh
5868
}
5969

60-
func (t *Tray) ShowChan() <-chan struct{} {
61-
return t.showItem.ClickedCh
62-
}
63-
6470
func (t *Tray) QuitChan() <-chan struct{} {
6571
return t.quitItem.ClickedCh
6672
}
6773

68-
func (t *Tray) setOnlineStatus(online bool) {
69-
systray.SetIcon(statusIcon(online))
70-
t.connToggleItem.SetTitle(connToggleText(online))
71-
}
72-
73-
func (t *Tray) Update(s tsutil.Status, previousOnlineStatus bool) {
74+
func (t *Tray) Update(s tsutil.Status) {
7475
if t == nil {
7576
return
7677
}
7778

78-
if s.Online() != previousOnlineStatus {
79-
t.setOnlineStatus(s.Online())
80-
}
79+
systray.SetIcon(statusIcon(s))
80+
t.connToggleItem.SetTitle(connToggleText(s.Online()))
8181

8282
selfTitle, connected := selfTitle(s)
8383
t.selfNodeItem.SetTitle(fmt.Sprintf("This machine: %v", selfTitle))

internal/ui/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (a *App) updatePeers(status tsutil.Status) {
157157

158158
func (a *App) update(s tsutil.Status) {
159159
online := s.Online()
160-
a.tray.Update(s, a.online)
160+
a.tray.Update(s)
161161
if a.online != online {
162162
a.online = online
163163

0 commit comments

Comments
 (0)