gui-less mode for linux

This commit is contained in:
Nazar Kanaev
2020-09-15 20:17:57 +01:00
parent 9de14fcb09
commit 439d98003f
4 changed files with 52 additions and 26 deletions

33
platform/gui.go Normal file
View File

@@ -0,0 +1,33 @@
// +build macos windows
package platform
import (
"github.com/getlantern/systray"
"github.com/nkanaev/yarr/server"
"github.com/skratchdot/open-golang/open"
)
func Start(s *server.Handler) {
systrayOnReady := func() {
systray.SetIcon(server.Icon)
menuOpen := systray.AddMenuItem("Open", "")
systray.AddSeparator()
menuQuit := systray.AddMenuItem("Quit", "")
go func() {
for {
select {
case <-menuOpen.ClickedCh:
open.Run("http://" + s.Addr)
case <-menuQuit.ClickedCh:
systray.Quit()
}
}
}()
s.Start()
}
systray.Run(systrayOnReady, nil)
}

11
platform/guiless.go Normal file
View File

@@ -0,0 +1,11 @@
// +build !windows,!macos
package platform
import (
"github.com/nkanaev/yarr/server"
)
func Start(s *server.Handler) {
s.Start()
}