Skip to content

Commit

Permalink
Merge pull request #5 from coquer/main
Browse files Browse the repository at this point in the history
chore: modify flags input and handle exceptions
  • Loading branch information
codelif authored Aug 7, 2024
2 parents d2b555d + 2c34d12 commit ec6159c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
18 changes: 9 additions & 9 deletions cmd/hyprnotify/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
15 changes: 12 additions & 3 deletions internal/audio.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package internal

import (
"embed"
"time"
"embed"

"github.com/gopxl/beep"
"github.com/gopxl/beep/speaker"
Expand All @@ -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)
Expand All @@ -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
}

}

0 comments on commit ec6159c

Please sign in to comment.