Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
add extra tray options
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Moore committed Jun 4, 2021
1 parent dccbce3 commit 4d98dfb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
17 changes: 16 additions & 1 deletion tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,40 @@ 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)
signal.Notify(sigc, syscall.SIGTERM, syscall.SIGINT)

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:
Expand Down
46 changes: 46 additions & 0 deletions views/view-google.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down

0 comments on commit 4d98dfb

Please sign in to comment.