diff --git a/cmd/hyprnotify/main.go b/cmd/hyprnotify/main.go index b47ea1e..fb57631 100644 --- a/cmd/hyprnotify/main.go +++ b/cmd/hyprnotify/main.go @@ -1,19 +1,19 @@ package main import ( + "flag" "github.com/codelif/hyprnotify/internal" - "os" ) func main() { - var enable_sound bool = true + var enableSound bool + const message = "Disable sound" - for _, arg := range os.Args[1:] { - if arg == "--no-sound" || arg == "--silent" || arg == "-s" { - enable_sound = false - break - } - } + flag.BoolVar(&enableSound, "no-sound", false, message) + flag.BoolVar(&enableSound, "silent", false, message) + flag.BoolVar(&enableSound, "s", false, message) - internal.InitDBus(enable_sound) + flag.Parse() + + internal.InitDBus(enableSound) } diff --git a/internal/audio.go b/internal/audio.go index de85e22..e32c5a8 100644 --- a/internal/audio.go +++ b/internal/audio.go @@ -1,8 +1,8 @@ package internal import ( + "embed" "time" - "embed" "github.com/gopxl/beep" "github.com/gopxl/beep/speaker" @@ -21,7 +21,12 @@ func PlayAudio() { if err != nil { panic(err) } - defer streamer.Close() + defer func(streamer beep.StreamSeekCloser) { + err := streamer.Close() + if err != nil { + panic(err) + } + }(streamer) speaker.Play(streamer) for streamer.Len() != streamer.Position() { time.Sleep(time.Second) @@ -30,6 +35,10 @@ func PlayAudio() { func InitSpeaker() { var sr beep.SampleRate = 44100 - speaker.Init(sr, sr.N(time.Second/10)) + err := speaker.Init(sr, sr.N(time.Second/10)) + + if err != nil { + return + } }