Skip to content

Commit

Permalink
Showing 3 changed files with 68 additions and 69 deletions.
125 changes: 61 additions & 64 deletions cmd/sni/tray/tray.go
Original file line number Diff line number Diff line change
@@ -89,6 +89,9 @@ func trayStart() {
}))

refresh := devicesMenu.AddSubMenuItem("Refresh", "Refresh list of devices")
refresh.ClickedFunc = func(item *systray.MenuItem) {
RefreshDeviceList()
}
for i := range deviceMenuItems {
deviceMenuItems[i] = devicesMenu.AddSubMenuItemCheckbox("_", "_", false)
deviceMenuItems[i].Hide()
@@ -145,25 +148,18 @@ func trayStart() {

for len(appsMenuItems) < len(appConfigs) {
i := len(appsMenuItems)
menuItem := appsMenu.AddSubMenuItem("", "")
appsMenuItems = append(appsMenuItems, menuItem)

// run a click handler goroutine for this menu item:
go func() {
defer func() {
recover()
}()
app := appConfigs[i]

for range menuItem.ClickedCh {
// skip the action if this menu item no longer exists:
if i >= len(appConfigs) {
continue
}

app := appConfigs[i]
launch(app)
menuItem := appsMenu.AddSubMenuItem("", "")
menuItem.ClickedFunc = func(item *systray.MenuItem) {
// skip the action if this menu item no longer exists:
if i >= len(appConfigs) {
return
}
}()

launch(app)
}
appsMenuItems = append(appsMenuItems, menuItem)
}

// set menu items:
@@ -183,55 +179,56 @@ func trayStart() {
}
}))

// Menu item click handler:
// click handlers:
versionMenuItem.ClickedFunc = func(item *systray.MenuItem) {
launch(&appConfig{
Name: "",
Tooltip: "",
Os: "",
Dir: "",
Path: "",
Args: nil,
Url: logging.Dir,
})
}



appsReload.ClickedFunc = func(item *systray.MenuItem) {
config.ReloadApps()
}

disconnectAll.ClickedFunc = func(item *systray.MenuItem) {
for _, named := range snes.Drivers() {
log.Printf("%s: disconnecting all devices...\n", named.Name)
named.Driver.DisconnectAll()
}
}

toggleVerbose.ClickedFunc = func(item *systray.MenuItem) {
config.VerboseLogging = !config.VerboseLogging
if config.VerboseLogging {
log.Println("enable verbose logging")
toggleVerbose.Check()
} else {
log.Println("disable verbose logging")
toggleVerbose.Uncheck()
}
// update config file:
config.Config.Set("verboseLogging", config.VerboseLogging)
config.Save()
}

mQuit.ClickedFunc = func(item *systray.MenuItem) {
fmt.Println("Requesting quit")
systray.Quit()
}

// refresh device list periodically:
go func() {
refreshPeriod := time.Tick(time.Second * 2)
for {
select {
case <-mQuit.ClickedCh:
fmt.Println("Requesting quit")
systray.Quit()
break
case <-versionMenuItem.ClickedCh:
launch(&appConfig{
Name: "",
Tooltip: "",
Os: "",
Dir: "",
Path: "",
Args: nil,
Url: logging.Dir,
})
break
case <-appsReload.ClickedCh:
config.ReloadApps()
break
case <-disconnectAll.ClickedCh:
for _, named := range snes.Drivers() {
log.Printf("%s: disconnecting all devices...\n", named.Name)
named.Driver.DisconnectAll()
}
break
case <-toggleVerbose.ClickedCh:
config.VerboseLogging = !config.VerboseLogging
if config.VerboseLogging {
log.Println("enable verbose logging")
toggleVerbose.Check()
} else {
log.Println("disable verbose logging")
toggleVerbose.Uncheck()
}
// update config file:
config.Config.Set("verboseLogging", config.VerboseLogging)
config.Save()
break
case <-refresh.ClickedCh:
RefreshDeviceList()
break
case <-refreshPeriod:
RefreshDeviceList()
break
}
for range refreshPeriod {
RefreshDeviceList()
}
}()
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ module sni
go 1.16

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/getlantern/systray v1.2.0
github.com/fsnotify/fsnotify v1.4.9
github.com/getlantern/systray v1.3.0
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.0.4
@@ -15,4 +15,6 @@ require (
google.golang.org/protobuf v1.26.0
)

replace github.com/getlantern/systray => github.com/alttpo/systray v1.2.0
replace github.com/getlantern/systray => github.com/alttpo/systray v1.3.0

//replace github.com/getlantern/systray => ../systray
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -48,8 +48,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/alttpo/systray v1.2.0 h1:TknDbd60eNaeDaJmuzGd4VgO1jjstiM6PnV1fMCTbyY=
github.com/alttpo/systray v1.2.0/go.mod h1:SHjooj3IKvtx2SeEbHOaDgTZ6dN3oYoMJAjtcN75Dzo=
github.com/alttpo/systray v1.3.0 h1:hinULhOMk3mjb5IhJe/rVQKdkoqTG+2G8fcZJSCvTQM=
github.com/alttpo/systray v1.3.0/go.mod h1:SHjooj3IKvtx2SeEbHOaDgTZ6dN3oYoMJAjtcN75Dzo=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=

0 comments on commit 3e1a752

Please sign in to comment.