Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customize notification sounds #127

Merged
merged 15 commits into from
Nov 6, 2024
Prev Previous commit
Next Next commit
chore: save custom audio path
  • Loading branch information
vjousse committed Oct 30, 2024
commit b6261436742d440805e44ad5b82cac4d89743aa5
23 changes: 15 additions & 8 deletions src-elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,20 @@ update msg ({ config } as model) =

ProcessExternalMessage (SoundFilePath sessionType path) ->
let
_ =
Debug.log "SoundFilePath sessionType" sessionType
newConfig =
case sessionType of
Focus ->
config

ShortBreak ->
{ config | shortBreakAudio = Just path }

_ =
Debug.log "SoundFilePath path" path
LongBreak ->
config
in
( model, Cmd.none )
( { model | config = newConfig }
, updateConfig newConfig
)

Reset ->
let
Expand Down Expand Up @@ -402,15 +409,15 @@ update msg ({ config } as model) =

ResetShortBreakAudioFile ->
let
updatedConfig =
newConfig =
{ config
| shortBreakAudio = Nothing
}
in
( { model
| config = updatedConfig
| config = newConfig
}
, Cmd.none
, updateConfig newConfig
)

ShortBreakAudioFileRequested ->
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct Config {
#[serde(default)]
muted: bool,
pomodoro_duration: u16,
short_break_audio: Option<String>,
short_break_duration: u16,
#[serde(default = "default_theme")]
theme: String,
Expand Down Expand Up @@ -211,6 +212,7 @@ impl Default for Config {
minimize_to_tray_on_close: true,
muted: false,
pomodoro_duration: 25 * 60,
short_break_audio: None,
short_break_duration: 5 * 60,
theme: "pomotroid".to_string(),
tick_sounds_during_work: true,
Expand Down Expand Up @@ -590,7 +592,6 @@ async fn update_config(
) -> Result<(), ()> {
let mut state_guard = state.0.lock().await;

// @FIX: reset the pomodoro state if the duration have changed
*state_guard = App {
config: config.clone(),
pomodoro: state_guard.pomodoro,
Expand Down
2 changes: 2 additions & 0 deletions src-ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ElmConfig = {
minimizeToTrayOnClose: boolean;
muted: boolean;
pomodoroDuration: number;
shortBreakAudio: string;
shortBreakDuration: number;
theme: string;
tickSoundsDuringWork: boolean;
Expand Down Expand Up @@ -215,6 +216,7 @@ app.ports.updateConfig.subscribe(function (config: ElmConfig) {
minimize_to_tray_on_close: config.minimizeToTrayOnClose,
muted: config.muted,
pomodoro_duration: config.pomodoroDuration,
short_break_audio: config.shortBreakAudio,
short_break_duration: config.shortBreakDuration,
theme: config.theme,
tick_sounds_during_work: config.tickSoundsDuringWork,
Expand Down