From 40b854379c7934fc3f9a183cd871fa5d57d6aa14 Mon Sep 17 00:00:00 2001 From: thatguywiththatname Date: Sat, 3 Oct 2020 03:09:01 +0100 Subject: [PATCH] Add 'Uncheck All' button --- internal/buttons/uncheckall.go | 28 ++++++++++++++++++++++++++++ internal/tray/tray.go | 9 ++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 internal/buttons/uncheckall.go diff --git a/internal/buttons/uncheckall.go b/internal/buttons/uncheckall.go new file mode 100644 index 0000000..edd194b --- /dev/null +++ b/internal/buttons/uncheckall.go @@ -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) + } + } +} diff --git a/internal/tray/tray.go b/internal/tray/tray.go index 7b7716b..fd2ac0c 100644 --- a/internal/tray/tray.go +++ b/internal/tray/tray.go @@ -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") @@ -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.