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

internal/tray: support displaying connection status #68

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
25 changes: 19 additions & 6 deletions internal/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ func statusIcon(online bool) []byte {
}

type Tray struct {
showItem *systray.MenuItem
quitItem *systray.MenuItem
selfNodeItem *systray.MenuItem
showItem *systray.MenuItem
quitItem *systray.MenuItem
selfNodeItem *systray.MenuItem
connectionStatusMenuItem *systray.MenuItem
}

func New(online bool) *Tray {
systray.SetIcon(statusIcon(online))
systray.SetTitle("Trayscale")

selfNodeItem := systray.AddMenuItem("", "")
connectionStatusMenuItem := systray.AddMenuItem(connectionStatusText(online), "")
connectionStatusMenuItem.Disable()
systray.AddSeparator()
showWindow := systray.AddMenuItem("Show", "")
systray.AddSeparator()
quit := systray.AddMenuItem("Quit", "")

return &Tray{
showItem: showWindow,
quitItem: quit,
selfNodeItem: selfNodeItem,
showItem: showWindow,
quitItem: quit,
selfNodeItem: selfNodeItem,
connectionStatusMenuItem: connectionStatusMenuItem,
}
}

Expand All @@ -60,6 +64,7 @@ func (t *Tray) SelfNodeChan() <-chan struct{} {

func (t *Tray) setOnlineStatus(online bool) {
systray.SetIcon(statusIcon(online))
t.connectionStatusMenuItem.SetTitle(connectionStatusText(online))
}

func (t *Tray) Update(s tsutil.Status, previousOnlineStatus bool) {
Expand Down Expand Up @@ -113,3 +118,11 @@ func selfTitle(s tsutil.Status) (string, bool) {

return fmt.Sprintf("%v (%v)", tsutil.DNSOrQuoteHostname(s.Status, s.Status.Self), addr), true
}

func connectionStatusText(online bool) string {
if online {
return "Connected"
}

return "Disconnected"
}
Loading