mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
WIP: Trayicon
This commit is contained in:
parent
13ea4bc4b2
commit
86f98cb8e5
6 changed files with 116 additions and 41 deletions
61
be/app/systray.go
Normal file
61
be/app/systray.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"be/app/helper"
|
||||
"os"
|
||||
|
||||
"github.com/getlantern/systray"
|
||||
)
|
||||
|
||||
func InitSystray() {
|
||||
go func() {
|
||||
systray.Run(OnReady, OnExit)
|
||||
}()
|
||||
}
|
||||
|
||||
func OnReady() {
|
||||
systray.SetIcon(getFavicon())
|
||||
systray.SetTitle("Macrame")
|
||||
systray.SetTooltip("Macrame - Server")
|
||||
|
||||
ip, _ := GetServerIp()
|
||||
|
||||
systray.AddMenuItem("IP: "+ip+":"+helper.EnvGet("MCRM__PORT"), "")
|
||||
|
||||
systray.AddSeparator()
|
||||
|
||||
addMCRMItem("Dashboard", "/")
|
||||
addMCRMItem("Panels", "/panels")
|
||||
addMCRMItem("Macros", "/macros")
|
||||
addMCRMItem("Devices", "/devices")
|
||||
|
||||
systray.AddSeparator()
|
||||
|
||||
mQuit := systray.AddMenuItem("Quit Macrame", "Quit Macrame")
|
||||
go func() {
|
||||
<-mQuit.ClickedCh
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
|
||||
func addMCRMItem(name, urlPath string) {
|
||||
m := systray.AddMenuItem(name, name)
|
||||
go func() {
|
||||
<-m.ClickedCh
|
||||
helper.OpenBrowser("http://localhost:" + helper.EnvGet("MCRM__PORT") + urlPath)
|
||||
}()
|
||||
}
|
||||
|
||||
func OnExit() {
|
||||
systray.Quit()
|
||||
}
|
||||
|
||||
func getFavicon() []byte {
|
||||
favicon, err := os.ReadFile("favicon.ico")
|
||||
|
||||
if err != nil {
|
||||
MCRMLog("getFavicon Error: ", err)
|
||||
}
|
||||
|
||||
return favicon
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue