-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: play notification sound when pomodoro ends (#14)
* feat: play notification sound when pomodoro ends * fix(build): add libasound2-dev dep when building * chore(release): add deb and rpm dependencies * ci: cancel previous runs of workflow if new one is run * ci: cancel previous runs of workflow if new one is run (codeql) * feat: play notification sound on pomodoro end * doc: add credit for notification sound * doc: describe how to override the notification sound * feat: wrap errors instead of log.Fatal
- Loading branch information
Showing
9 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ui | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hajimehoshi/go-mp3" | ||
"github.com/hajimehoshi/oto" | ||
"io" | ||
"os" | ||
"sync" | ||
) | ||
|
||
var once sync.Once | ||
var context *oto.Context | ||
|
||
func playNotificationSound() error { | ||
fileName := "/usr/share/fynodoro/notification.mp3" | ||
f, err := os.Open(fileName) | ||
if err != nil { | ||
return fmt.Errorf("unable to read %s: %w", fileName, err) | ||
} | ||
|
||
decoder, err := mp3.NewDecoder(f) | ||
if err != nil { | ||
return fmt.Errorf("unable to decode %s: %w", fileName, err) | ||
} | ||
|
||
once.Do(func() { | ||
context, err = oto.NewContext(decoder.SampleRate(), 2, 2, 8192) | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("unable to create oto context: %w", err) | ||
} | ||
|
||
go func() { | ||
player := context.NewPlayer() | ||
defer func() { | ||
err = player.Close() | ||
}() | ||
|
||
_, err = io.Copy(player, decoder) | ||
}() | ||
if err != nil { | ||
return fmt.Errorf("unable to play: %w", err) | ||
} | ||
|
||
return nil | ||
} |