Skip to content

Commit

Permalink
Add 'Uncheck All' button
Browse files Browse the repository at this point in the history
  • Loading branch information
psidex committed Oct 3, 2020
1 parent a3ea136 commit 40b8543
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
28 changes: 28 additions & 0 deletions internal/buttons/uncheckall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package buttons

import (
"github.com/getlantern/systray"
"github.com/psidex/EACS/internal/appdata"
"github.com/psidex/EACS/internal/icon"
"github.com/psidex/EACS/internal/util"
)

// UncheckAllHandler takes the "Uncheck All" button and handles it's click event.
func UncheckAllHandler(uncheckAllBtn *systray.MenuItem, dc *appdata.DataController, allButtons []*systray.MenuItem) {
for {
<-uncheckAllBtn.ClickedCh
uncheckAllBtn.Uncheck()

dc.RemoveAllActiveConfigFileNames()
for _, btn := range allButtons {
btn.Uncheck()
}

systray.SetIcon(icon.DataInactive)

err := dc.Save()
if err != nil {
util.FatalError(err)
}
}
}
9 changes: 6 additions & 3 deletions internal/tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const saveDataPath = ".\\data.gob"
// OnReady is the function to be called when the application is ready to run.
func OnReady() {
// systray has an issue on Windows that causes errors to happen if you call methods before setting the icon.
// To fix this the first thing that happens in OnReady is settings the icon.
// To fix this the first thing that happens in OnReady is setting the icon.
// https://github.com/getlantern/systray/issues/158
systray.SetIcon(icon.DataInactive)
systray.SetTooltip("Equalizer APO Config Switcher")
Expand Down Expand Up @@ -60,17 +60,20 @@ func OnReady() {

// Add the last menu bits.
systray.AddSeparator()
allowMultipleBtn := systray.AddMenuItem("Allow Multiple", "")
allowMultipleBtn := systray.AddMenuItem("Allow Multiple", "Allows only a single configuration to be active")
uncheckAllBtn := systray.AddMenuItem("Uncheck All", "Unchecks all configurations")
systray.AddSeparator()
quitBtn := systray.AddMenuItem("Quit", "Quit the whole app")

if dc.AllowMultiple() {
allowMultipleBtn.Check()
}

// Having a single handler for button presses means we don't have to worry about concurrent file access.
// Having a single handler for config button presses means we don't have to worry about concurrent file access.
go buttons.ConfigButtonsReceiverLoop(fileNameChan, menuItemChan, dc, allButtons)

go buttons.AllowMultipleHandler(allowMultipleBtn, dc)
go buttons.UncheckAllHandler(uncheckAllBtn, dc, allButtons)
go buttons.QuitButtonHandler(quitBtn)

// If we have active configs, set to the active icon.
Expand Down

0 comments on commit 40b8543

Please sign in to comment.