Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/desktop-tauri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@tauri-apps/api": "2.10.1",
"@tauri-apps/plugin-dialog": "2.7.2",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop-tauri/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri = { version = "2", features = ["image-png", "tray-icon"] }
tauri-plugin-global-shortcut = "2"
tauri-plugin-dialog = "2.7.2"
tauri-plugin-single-instance = "2"
tokio = { version = "1", features = ["rt", "time", "sync", "net", "io-util"] }
tracing = "0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"identifier": "notification-sound-dialog",
"description": "Allows the settings window to select custom notification WAV files.",
"windows": ["main", "settings"],
"permissions": ["dialog:allow-open"]
}
6 changes: 4 additions & 2 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ pub struct SettingsSnapshot {
start_minimized: bool,
show_notifications: bool,
sound_enabled: bool,
sound_volume: u8,
notification_sound_theme: codexbar::settings::NotificationSoundTheme,
notification_sound_paths: codexbar::settings::NotificationSoundPaths,
high_usage_threshold: f64,
critical_usage_threshold: f64,
provider_usage_thresholds:
Expand Down Expand Up @@ -566,7 +567,8 @@ impl From<Settings> for SettingsSnapshot {
start_minimized: settings.start_minimized,
show_notifications: settings.show_notifications,
sound_enabled: settings.sound_enabled,
sound_volume: settings.sound_volume,
notification_sound_theme: settings.notification_sound_theme,
notification_sound_paths: settings.notification_sound_paths,
high_usage_threshold: settings.high_usage_threshold,
critical_usage_threshold: settings.critical_usage_threshold,
provider_usage_thresholds: settings.provider_usage_thresholds,
Expand Down
13 changes: 11 additions & 2 deletions apps/desktop-tauri/src-tauri/src/commands/locale_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,21 @@ mod locale_tests {
"chinesetraditional",
"japanese",
"korean",
"spanish"
"spanish",
"russian"
]
);
assert_eq!(
displays,
vec!["English", "中文", "繁體中文", "日本語", "한국어", "Español"]
vec![
"English",
"中文",
"繁體中文",
"日本語",
"한국어",
"Español",
"Русский"
]
);
}

Expand Down
57 changes: 51 additions & 6 deletions apps/desktop-tauri/src-tauri/src/commands/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub struct SettingsUpdate {
pub start_minimized: Option<bool>,
pub show_notifications: Option<bool>,
pub sound_enabled: Option<bool>,
pub sound_volume: Option<u8>,
pub notification_sound_theme: Option<codexbar::settings::NotificationSoundTheme>,
pub notification_sound_paths: Option<codexbar::settings::NotificationSoundPaths>,
pub high_usage_threshold: Option<f64>,
pub critical_usage_threshold: Option<f64>,
pub provider_usage_thresholds:
Expand Down Expand Up @@ -212,15 +213,23 @@ impl SettingsUpdate {
self
}

fn apply_notification_settings(self, settings: &mut Settings) -> Self {
fn apply_notification_settings(self, settings: &mut Settings) -> Result<Self, String> {
if let Some(v) = self.show_notifications {
settings.show_notifications = v;
}
if let Some(v) = self.sound_enabled {
settings.sound_enabled = v;
}
if let Some(v) = self.sound_volume {
settings.sound_volume = v;
if let Some(v) = self.notification_sound_theme {
settings.notification_sound_theme = v;
}
if let Some(v) = self.notification_sound_paths.clone() {
codexbar::sound::validate_custom_sound_path_updates(
&settings.notification_sound_paths,
&v,
)
.map_err(|error| error.to_string())?;
settings.notification_sound_paths = v;
}
if let Some(v) = self.high_usage_threshold {
settings.high_usage_threshold = v.clamp(0.0, 100.0);
Expand All @@ -235,7 +244,7 @@ impl SettingsUpdate {
if let Some(v) = self.predictive_pace_warning_enabled {
settings.predictive_pace_warning_enabled = v;
}
self
Ok(self)
}

fn apply_advanced_settings(self, settings: &mut Settings) -> Self {
Expand Down Expand Up @@ -334,7 +343,7 @@ impl SettingsUpdate {
self.apply_provider_settings(settings)
.apply_general_settings(settings)?
.apply_display_settings(settings)
.apply_notification_settings(settings)
.apply_notification_settings(settings)?
.apply_advanced_settings(settings);
float_bar_patch.apply(settings);
Ok(float_bar_patch)
Expand Down Expand Up @@ -545,4 +554,40 @@ mod tests {
.apply_display_settings(&mut settings);
assert_eq!(settings.tray_scale_percent, 100);
}

#[test]
fn apply_notification_settings_updates_sound() {
let mut settings = Settings::default();

SettingsUpdate {
notification_sound_theme: Some(codexbar::settings::NotificationSoundTheme::CodexBar),
..Default::default()
}
.apply_notification_settings(&mut settings)
.expect("apply sound theme");

assert_eq!(
settings.notification_sound_theme,
codexbar::settings::NotificationSoundTheme::CodexBar
);
}

#[test]
fn apply_notification_settings_rejects_invalid_custom_sound() {
let mut settings = Settings::default();
let result = SettingsUpdate {
notification_sound_paths: Some(codexbar::settings::NotificationSoundPaths {
high_usage: Some("relative.wav".to_string()),
..Default::default()
}),
..Default::default()
}
.apply_notification_settings(&mut settings);

assert!(result.is_err());
assert_eq!(
settings.notification_sound_paths,
codexbar::settings::NotificationSoundPaths::default()
);
}
}
9 changes: 5 additions & 4 deletions apps/desktop-tauri/src-tauri/src/commands/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ pub fn get_work_area_rect(app: tauri::AppHandle) -> Result<WorkAreaRect, String>
// ── Misc UX ────────────────────────────────────────────────────────────

#[tauri::command]
pub fn play_notification_sound() -> Result<(), String> {
// Use the shared sound helper, honouring the user's `sound_enabled` flag.
pub fn play_notification_sound(
event: codexbar::sound::NotificationSoundEvent,
) -> Result<(), String> {
// Preview through the same settings resolution path used by real notifications.
let settings = Settings::load();
codexbar::sound::play_alert(codexbar::sound::AlertSound::Success, &settings);
Ok(())
codexbar::sound::play_alert(event, &settings).map_err(|error| error.to_string())
}

/// Reposition the flyout window so its bottom-right corner stays anchored to
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn main() {
tauri::Builder::default()
.manage(Mutex::new(initial_state))
.plugin(shortcut_bridge::plugin())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
if should_reopen_primary_window_from_instance_args(args.iter().skip(1)) {
let request = primary_window_request();
Expand Down
11 changes: 10 additions & 1 deletion apps/desktop-tauri/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ function settings(overrides: Partial<SettingsSnapshot> = {}): SettingsSnapshot {
startMinimized: false,
showNotifications: true,
soundEnabled: true,
soundVolume: 100,
notificationSoundTheme: "windows",
notificationSoundPaths: {
predictiveWarning: null,
highUsage: null,
criticalUsage: null,
exhausted: null,
statusIssue: null,
sessionDepleted: null,
sessionRestored: null,
},
highUsageThreshold: 70,
criticalUsageThreshold: 90,
predictivePaceWarningEnabled: false,
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop-tauri/src/components/FormControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,21 @@ export function Select({
onChange,
disabled,
ariaLabel,
minWidth,
}: {
value: string;
options: { value: string; label: string }[];
onChange: (v: string) => void;
disabled?: boolean;
ariaLabel?: string;
minWidth?: number;
}) {
const selectedLabel = options.find((option) => option.value === value)?.label ?? value;
const width = Math.min(128, Math.max(48, Math.ceil((selectedLabel ?? "").length * 6.8) + 18));
const calculatedWidth = Math.min(
128,
Math.max(48, Math.ceil((selectedLabel ?? "").length * 6.8) + 18),
);
const width = Math.max(calculatedWidth, minWidth ?? 0);

return (
<select
Expand Down
Loading
Loading