add enable/disable functions to unify the behaviors

This commit is contained in:
Aaron Bieber 2024-10-30 07:24:25 -06:00
parent e99ff27549
commit 83f68cca4a
No known key found for this signature in database

23
main.go
View File

@ -42,6 +42,19 @@ func main() {
} }
var desk desktop.App var desk desktop.App
disable := func() {
enabled = false
icon.Enabled = enabled
desk.SetSystemTrayIcon(icon.Draw(0.0))
systray.SetTooltip("Disabled")
}
enable := func() {
enabled = true
icon.Enabled = enabled
}
if !*makeIcon { if !*makeIcon {
a := app.New() a := app.New()
driver := fyne.CurrentApp().Driver().(desktop.Driver) driver := fyne.CurrentApp().Driver().(desktop.Driver)
@ -53,12 +66,10 @@ func main() {
desk.SetSystemTrayMenu( desk.SetSystemTrayMenu(
fyne.NewMenu("fynado", fyne.NewMenu("fynado",
fyne.NewMenuItem("Enable", func() { fyne.NewMenuItem("Enable", func() {
enabled = true enable()
icon.Enabled = enabled
}), }),
fyne.NewMenuItem("Disable", func() { fyne.NewMenuItem("Disable", func() {
enabled = false disable()
icon.Enabled = enabled
}), }),
), ),
) )
@ -98,11 +109,9 @@ func main() {
container.NewBorder(timerText, nil, nil, nil), container.NewBorder(timerText, nil, nil, nil),
container.NewBorder(roundsText, nil, nil, nil), container.NewBorder(roundsText, nil, nil, nil),
container.NewBorder(nil, widget.NewButton("Extended Break", func() { container.NewBorder(nil, widget.NewButton("Extended Break", func() {
enabled = false
rounds = 0 rounds = 0
w.Hide() w.Hide()
desk.SetSystemTrayIcon(icon.Draw(0.0)) disable()
systray.SetTooltip("Disabled")
}), nil, nil), }), nil, nil),
)), )),
), ),