From 4d98dfb5843184dd4a81abf564a1b9fe86f2f107 Mon Sep 17 00:00:00 2001 From: Grant Moore Date: Fri, 4 Jun 2021 14:56:08 -0700 Subject: [PATCH] add extra tray options --- go.mod | 1 + go.sum | 2 ++ tray/tray.go | 17 +++++++++++++++- views/view-google.go | 46 ++++++++++++++++++++++++++++++++++++++++++++ views/views.go | 6 ++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 views/view-google.go diff --git a/go.mod b/go.mod index 27bca38..4d93c98 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,6 @@ go 1.16 require ( github.com/getlantern/systray v1.1.0 + github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/zserge/lorca v0.1.10 ) diff --git a/go.sum b/go.sum index bc36c90..7b38b41 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgF github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= +github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/tray/tray.go b/tray/tray.go index 47fdad4..f0cd51c 100644 --- a/tray/tray.go +++ b/tray/tray.go @@ -10,13 +10,17 @@ import ( "github.com/getlantern/systray" "github.com/granmo/ExampleTrayGUI/icon" "github.com/granmo/ExampleTrayGUI/views" + "github.com/skratchdot/open-golang/open" ) func OnReady() { systray.SetIcon(icon.Data) mHelloWorld := systray.AddMenuItem("Hello, World!", "Opens a simple HTML Hello, World") - + systray.AddSeparator() + mGoogleBrowser := systray.AddMenuItem("Google in Browser", "Opens Google in a normal browser") + mGoogleEmbed := systray.AddMenuItem("Google in Window", "Opens Google in a custom window") + systray.AddSeparator() mQuit := systray.AddMenuItem("Quit", "Quit example tray application") sigc := make(chan os.Signal, 1) @@ -24,11 +28,22 @@ func OnReady() { for { select { + case <-mHelloWorld.ClickedCh: err := views.Get().OpenIndex() if err != nil { fmt.Println(err) } + case <-mGoogleBrowser.ClickedCh: + err := open.Run("https://www.google.com") + if err != nil { + fmt.Println(err) + } + case <-mGoogleEmbed.ClickedCh: + err := views.Get().OpenGoogle() + if err != nil { + fmt.Println(err) + } case <-mQuit.ClickedCh: systray.Quit() case <-sigc: diff --git a/views/view-google.go b/views/view-google.go new file mode 100644 index 0000000..da8af4c --- /dev/null +++ b/views/view-google.go @@ -0,0 +1,46 @@ +package views + +import ( + "log" + "os" + "os/signal" + "sync" + "syscall" + + "github.com/zserge/lorca" +) + +func (v *Views) OpenGoogle() error { + view, err := v.getView("Google") + if err != nil { + return err + } + + v.WaitGroup.Add(1) + go func(wg *sync.WaitGroup) { + defer wg.Done() + + ui, err := lorca.New(view.url, "", view.width, view.height) + if err != nil { + log.Fatal(err) + } + defer ui.Close() + + sigc := make(chan os.Signal, 1) + signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) + + view.isOpen = true + + select { + case <-sigc: + v.Shutdown <- true + case <-ui.Done(): + case <-v.Shutdown: + } + + view.isOpen = false + + }(v.WaitGroup) + + return nil +} diff --git a/views/views.go b/views/views.go index 08f7f65..82512ba 100644 --- a/views/views.go +++ b/views/views.go @@ -42,6 +42,12 @@ func Get() *Views { height: 280, } + l["Google"] = &View{ + url: "https://www.google.com/", + width: 960, + height: 800, + } + views = &Views{ list: l, WaitGroup: &sync.WaitGroup{},