72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"streamcore-edge/agent"
|
|
|
|
"github.com/getlantern/systray"
|
|
)
|
|
|
|
func runTray(ag *agent.Agent) {
|
|
systray.Run(
|
|
func() { onReady(ag) },
|
|
func() { onExit(ag) },
|
|
)
|
|
}
|
|
|
|
func onReady(ag *agent.Agent) {
|
|
systray.SetIcon(iconData)
|
|
systray.SetTitle("StreamCore Edge")
|
|
systray.SetTooltip("StreamCore Edge Node")
|
|
|
|
mStatus := systray.AddMenuItem("Node: "+ag.NodeID(), "Node")
|
|
mStatus.Disable()
|
|
mConnection := systray.AddMenuItem("Connection: connecting", "Master connection")
|
|
mConnection.Disable()
|
|
|
|
systray.AddSeparator()
|
|
|
|
mCPU := systray.AddMenuItem("CPU: --", "CPU")
|
|
mCPU.Disable()
|
|
mMem := systray.AddMenuItem("MEM: --", "Memory")
|
|
mMem.Disable()
|
|
mBW := systray.AddMenuItem("Bandwidth: --", "Bandwidth")
|
|
mBW.Disable()
|
|
|
|
systray.AddSeparator()
|
|
|
|
mQuit := systray.AddMenuItem("Quit", "Shutdown")
|
|
|
|
go func() {
|
|
ticker := time.NewTicker(3 * time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
if ag.Connected() {
|
|
mConnection.SetTitle("Connection: connected")
|
|
} else {
|
|
mConnection.SetTitle("Connection: disconnected")
|
|
}
|
|
m := ag.Metrics()
|
|
mCPU.SetTitle(fmt.Sprintf("CPU: %.1f%%", m.CPU))
|
|
mMem.SetTitle(fmt.Sprintf("MEM: %.1f%%", m.Memory))
|
|
mBW.SetTitle(fmt.Sprintf("Bandwidth: %.1f Mbps", m.Bandwidth))
|
|
case <-mQuit.ClickedCh:
|
|
systray.Quit()
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func onExit(ag *agent.Agent) {
|
|
log.Println("Tray exit requested")
|
|
ag.Stop()
|
|
}
|