Skip to content

Commit d09cdea

Browse files
tomsquestclaude
andcommitted
feat: add option to start application minimized
Add the ability to start Fynodoro minimized to system tray via: - CLI flag: --minimized - User preference: checkbox in Settings dialog Either option causes the app to start hidden, accessible via tray menu. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 38f301e commit d09cdea

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package main
33

44
import (
5+
"flag"
6+
57
"fyne.io/fyne/v2/app"
68
"github.com/tomsquest/fynodoro/ui"
79
)
@@ -14,9 +16,13 @@ var (
1416
commitDate string
1517
)
1618

19+
var startMinimized = flag.Bool("minimized", false, "Start the application minimized to tray")
20+
1721
func main() {
22+
flag.Parse()
23+
1824
myApp := app.NewWithID("com.tomsquest.fynodoro")
1925
myApp.SetIcon(ui.AssetIconPng)
2026

21-
ui.Display(myApp, ui.BuildInfo{version, commit, commitDate})
27+
ui.Display(myApp, ui.BuildInfo{version, commit, commitDate}, *startMinimized)
2228
}

pref/pref.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Pref struct {
99
ShortBreakDuration int
1010
LongBreakDuration int
1111
WorkRounds int
12+
StartMinimized bool
1213
}
1314

1415
func Load() Pref {
@@ -18,6 +19,7 @@ func Load() Pref {
1819
ShortBreakDuration: app.Preferences().IntWithFallback("shortBreakDuration", 5),
1920
LongBreakDuration: app.Preferences().IntWithFallback("longBreakDuration", 15),
2021
WorkRounds: app.Preferences().IntWithFallback("workRounds", 4),
22+
StartMinimized: app.Preferences().BoolWithFallback("startMinimized", false),
2123
}
2224
}
2325

@@ -27,4 +29,5 @@ func Save(pref Pref) {
2729
app.Preferences().SetInt("shortBreakDuration", pref.ShortBreakDuration)
2830
app.Preferences().SetInt("longBreakDuration", pref.LongBreakDuration)
2931
app.Preferences().SetInt("workRounds", pref.WorkRounds)
32+
app.Preferences().SetBool("startMinimized", pref.StartMinimized)
3033
}

ui/settings.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,24 @@ func makeForm() *widget.Form {
7474
_ = workRoundsBinding.Set(myPref.WorkRounds)
7575
form.AppendItem(newIntegerFormItem(workRoundsBinding, "Work rounds", "Set how many Work rounds before a long break. Default is: %d. 0 to disable.", NewRangeValidator(0, 999)))
7676

77+
startMinimizedBinding := binding.NewBool()
78+
_ = startMinimizedBinding.Set(myPref.StartMinimized)
79+
startMinimizedCheck := widget.NewCheckWithData("Start minimized to tray", startMinimizedBinding)
80+
form.AppendItem(widget.NewFormItem("", startMinimizedCheck))
81+
7782
form.OnSubmit = func() {
7883
workDuration, _ := workDurationBinding.Get()
7984
shortBreakDuration, _ := shortBreakDurationBinding.Get()
8085
longBreakDuration, _ := longBreakDurationBinding.Get()
8186
workRounds, _ := workRoundsBinding.Get()
87+
startMinimized, _ := startMinimizedBinding.Get()
8288

8389
newPref := pref.Pref{
84-
workDuration,
85-
shortBreakDuration,
86-
longBreakDuration,
87-
workRounds,
90+
WorkDuration: workDuration,
91+
ShortBreakDuration: shortBreakDuration,
92+
LongBreakDuration: longBreakDuration,
93+
WorkRounds: workRounds,
94+
StartMinimized: startMinimized,
8895
}
8996
pref.Save(newPref)
9097
}

ui/ui.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type BuildInfo struct {
1919
CommitDate string
2020
}
2121

22-
func Display(app fyne.App, buildInfo BuildInfo) {
22+
func Display(app fyne.App, buildInfo BuildInfo, cliStartMinimized bool) {
2323
myPref := pref.Load()
2424
thePomodoro := pomodoro.NewPomodoro(&pomodoro.Params{
2525
WorkDuration: time.Duration(myPref.WorkDuration) * time.Minute,
@@ -44,7 +44,11 @@ func Display(app fyne.App, buildInfo BuildInfo) {
4444
desk.SetSystemTrayMenu(trayMenu)
4545
}
4646

47-
mainWindow.ShowAndRun()
47+
if cliStartMinimized || myPref.StartMinimized {
48+
app.Run()
49+
} else {
50+
mainWindow.ShowAndRun()
51+
}
4852
}
4953

5054
func makeAboutWindow(app fyne.App, buildInfo BuildInfo) fyne.Window {

0 commit comments

Comments
 (0)