mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-22 08:46:22 +03:00
add tray
This commit is contained in:
parent
1e33e0a6d8
commit
e310505efd
1 changed files with 65 additions and 0 deletions
65
functions/tray.go
Normal file
65
functions/tray.go
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package functions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/getlantern/systray"
|
||||||
|
"github.com/shirou/gopsutil/v3/process"
|
||||||
|
"github.com/skratchdot/open-golang/open"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Tray() {
|
||||||
|
systray.SetIcon(GetIcon("web/static/image/icons/everynasa.ico"))
|
||||||
|
systray.SetTitle("EveryNasa")
|
||||||
|
systray.SetTooltip("EveryNasa")
|
||||||
|
ui := systray.AddMenuItem("Open Ui", "Open Ui")
|
||||||
|
exit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ui.ClickedCh:
|
||||||
|
err := open.Run("http://localhost:4662")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
case <-exit.ClickedCh:
|
||||||
|
Quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Quit() {
|
||||||
|
err := KillProcess("EveryNasa.exe")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
systray.Quit()
|
||||||
|
}
|
||||||
|
|
||||||
|
func KillProcess(name string) error {
|
||||||
|
processes, err := process.Processes()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range processes {
|
||||||
|
n, ProccErr := p.Name()
|
||||||
|
if ProccErr != nil {
|
||||||
|
panic(ProccErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == name {
|
||||||
|
return p.Kill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fmt.Errorf("process not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetIcon(s string) []byte {
|
||||||
|
b, err := os.ReadFile(s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err)
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue