diff --git a/internal/core/core.go b/internal/core/core.go index 4ab0904..43f7aab 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -17,8 +17,8 @@ var loop int /* Create a new TwentyTwentyTwenty struct. */ -func New(optional Optional, settings Settings) *TwentyTwentyTwenty { - return &TwentyTwentyTwenty{Optional: optional, Settings: settings} +func New(features Features, settings Settings) *TwentyTwentyTwenty { + return &TwentyTwentyTwenty{Features: features, Settings: settings} } /* @@ -36,7 +36,7 @@ This will start the main twenty-twenty-twenty loop in a goroutine, so avoid calling this function inside a goroutine. */ func (t *TwentyTwentyTwenty) Start() { - if t.Optional.Sound { + if t.Features.Sound { log.Printf( "Running twenty-twenty-twenty every %.1f minute(s), with %.f second(s) duration and sound set to %t\n", t.Settings.Frequency.Minutes(), @@ -134,7 +134,7 @@ func (t *TwentyTwentyTwenty) loop() { log.Printf("Showing notification for %.f second(s)\n", t.Settings.Duration.Seconds()) // wait 1.5x the duration so we have some time for the sounds to // finish playing - if t.Optional.Sound { + if t.Features.Sound { go sound.SuspendAfter(min(t.Settings.Duration*3/2, t.Settings.Frequency)) } err := notification.SendWithDuration( diff --git a/internal/core/core_test.go b/internal/core/core_test.go index 2be78fa..d6d3d8a 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -41,7 +41,7 @@ func newMockNotifier() *mockNotifier { var ( notifier *mockNotifier twenty = New( - Optional{ + Features{ Sound: false, Systray: false, }, diff --git a/internal/core/flags.go b/internal/core/flags.go index 5881b87..1b44592 100644 --- a/internal/core/flags.go +++ b/internal/core/flags.go @@ -11,7 +11,7 @@ func ParseFlags( progname string, args []string, version string, - optional Optional, + features Features, ) Settings { flags := flag.NewFlagSet(progname, flag.ExitOnError) durationInSec := flags.Uint( @@ -25,7 +25,7 @@ func ParseFlags( "how often the pause should be in seconds", ) pauseInSec := new(uint) - if optional.Systray { + if features.Systray { pauseInSec = flags.Uint( "pause", 60*60, @@ -33,7 +33,7 @@ func ParseFlags( ) } disableSound := new(bool) - if optional.Sound { + if features.Sound { disableSound = flags.Bool( "disable-sound", false, @@ -62,7 +62,7 @@ func ParseFlags( Duration: time.Duration(*durationInSec) * time.Second, Frequency: time.Duration(*frequencyInSec) * time.Second, Pause: time.Duration(*pauseInSec) * time.Second, - Sound: optional.Sound && !*disableSound, + Sound: features.Sound && !*disableSound, Verbose: *verbose, } } diff --git a/internal/core/flags_test.go b/internal/core/flags_test.go index 10e695a..4923e6b 100644 --- a/internal/core/flags_test.go +++ b/internal/core/flags_test.go @@ -13,7 +13,7 @@ func TestParseFlags(t *testing.T) { const version = "test" // always return false for sound if disabled - settings := ParseFlags(progname, []string{}, version, Optional{Sound: false, Systray: false}) + settings := ParseFlags(progname, []string{}, version, Features{Sound: false, Systray: false}) assert.Equal(t, settings.Sound, false) var tests = []struct { @@ -28,7 +28,7 @@ func TestParseFlags(t *testing.T) { for _, tt := range tests { t.Run(strings.Join(tt.args, " "), func(t *testing.T) { - settings := ParseFlags(progname, tt.args, version, Optional{Sound: true, Systray: true}) + settings := ParseFlags(progname, tt.args, version, Features{Sound: true, Systray: true}) assert.Equal(t, settings, tt.settings) }) } diff --git a/internal/core/structs.go b/internal/core/structs.go index d5f5208..5bef09a 100644 --- a/internal/core/structs.go +++ b/internal/core/structs.go @@ -12,8 +12,8 @@ TwentyTwentyTwenty struct. Keeps the main state of the program. */ type TwentyTwentyTwenty struct { - Optional Optional - Settings Settings + Features + Settings cancelLoopCtx context.CancelFunc loopCtx context.Context @@ -21,12 +21,12 @@ type TwentyTwentyTwenty struct { } /* -Optional struct. +Features struct. This is used for features that are optional in the program, for example if sound or systray are permanently disabled. */ -type Optional struct { +type Features struct { Sound bool Systray bool } diff --git a/main.go b/main.go index 8d47840..16d9988 100644 --- a/main.go +++ b/main.go @@ -30,19 +30,19 @@ func main() { logger := slog.New(handler) slog.SetDefault(logger) - optional := core.Optional{Sound: sound.Enabled, Systray: systrayEnabled} - settings := core.ParseFlags(os.Args[0], os.Args[1:], version, optional) + features := core.Features{Sound: sound.Enabled, Systray: systrayEnabled} + settings := core.ParseFlags(os.Args[0], os.Args[1:], version, features) if settings.Verbose { lvl.Set(slog.LevelDebug) } - if optional.Sound { + if features.Sound { err := sound.Init(!settings.Sound) if err != nil { log.Printf("Error while initialising sound: %v\n", err) log.Println("Disabling sound") - optional.Sound = false + features.Sound = false settings.Sound = false } } @@ -55,13 +55,13 @@ func main() { if err != nil { log.Fatalf("Test notification failed: %v. Exiting...", err) } - twenty = core.New(optional, settings) + twenty = core.New(features, settings) // we need to start notification cancellation in a goroutine to show the // systray as soon as possible (since it depends on the loop() call), but we // also need to give it access to the core.Ctx to cancel it if necessary twenty.Start() go func() { - if optional.Sound { + if features.Sound { // wait the 1.5x of duration so we have some time for the sounds to // finish playing go sound.SuspendAfter(min(settings.Duration*3/2, settings.Frequency)) diff --git a/systray.go b/systray.go index 86bfce9..fe8f02c 100644 --- a/systray.go +++ b/systray.go @@ -30,7 +30,7 @@ func onReady() { false, ) mSound := new(systray.MenuItem) - if twenty.Optional.Sound { + if twenty.Features.Sound { mSound = systray.AddMenuItemCheckbox("Sound", "Enable notification sound", twenty.Settings.Sound) } systray.AddSeparator()