mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-25 01:46:21 +03:00
65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
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
|
|
}
|