Skip to content

Commit aa331c4

Browse files
committed
Settings: Live-apply SMB toggles via Tauri commands
- Add `set_direct_smb_connection`, `set_filter_safe_save_artifacts_cmd`, `set_smb_concurrency_cmd` in `commands/settings.rs`, each a thin wrapper over the existing `file_system::set_*` helpers. - Register them in the `invoke_handler` list in `lib.rs`. - Unit test covers the `1..=32` clamp on `set_smb_concurrency_cmd` (0 → 1, 100 → 32) plus boolean round-trips, serialized via a local `Mutex` so the process-global atomics don't race against parallel test execution. - Startup-time seeding in `lib.rs` is intentionally kept so the backend boots with a sensible initial value before any window loads.
1 parent 33cb984 commit aa331c4

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

apps/desktop/src-tauri/src/commands/settings.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use tauri::{AppHandle, Manager};
44

5-
use crate::file_system::update_debounce_ms;
5+
use crate::file_system::{
6+
set_direct_smb_enabled, set_filter_safe_save_artifacts, set_smb_concurrency, update_debounce_ms,
7+
};
68
use crate::ignore_poison::IgnorePoison;
79
use crate::menu::{
810
MenuState, command_id_to_menu_id, frontend_shortcut_to_accelerator, update_menu_item_accelerator,
@@ -46,6 +48,28 @@ pub fn update_service_resolve_timeout(_timeout_ms: u64) {
4648
// No-op on non-macOS platforms
4749
}
4850

51+
/// Enable or disable automatic upgrade of SMB mounts to direct smb2 connections.
52+
/// Pushed live from the frontend whenever `network.directSmbConnection` changes.
53+
#[tauri::command]
54+
pub fn set_direct_smb_connection(enabled: bool) {
55+
set_direct_smb_enabled(enabled);
56+
}
57+
58+
/// Toggle filtering of macOS safe-save artifacts (`.sb-*` files) in the SMB watcher.
59+
/// Pushed live from the frontend whenever `advanced.filterSafeSaveArtifacts` changes.
60+
#[tauri::command]
61+
pub fn set_filter_safe_save_artifacts_cmd(enabled: bool) {
62+
set_filter_safe_save_artifacts(enabled);
63+
}
64+
65+
/// Update the SMB concurrency limit used by `SmbVolume::max_concurrent_ops()`.
66+
/// Clamped to `1..=32` by `set_smb_concurrency`. Pushed live from the frontend
67+
/// whenever `network.smbConcurrency` changes.
68+
#[tauri::command]
69+
pub fn set_smb_concurrency_cmd(value: u16) {
70+
set_smb_concurrency(value as usize);
71+
}
72+
4973
/// Update menu accelerator for a command.
5074
/// Called from frontend when keyboard shortcuts are changed.
5175
#[tauri::command]
@@ -111,6 +135,44 @@ mod tests {
111135
let _ = result;
112136
}
113137

138+
/// Covers the three live-apply commands in one test because they share
139+
/// process-global atomics — running them as separate `#[test]` fns would
140+
/// race under the default parallel test runner.
141+
#[test]
142+
fn test_live_apply_commands() {
143+
use std::sync::Mutex;
144+
// Serialize across any other test that might touch the same globals.
145+
static LOCK: Mutex<()> = Mutex::new(());
146+
let _guard = LOCK.lock().unwrap_or_else(|e| e.into_inner());
147+
148+
// smb_concurrency clamps 0 → 1 (min)
149+
set_smb_concurrency_cmd(0);
150+
assert_eq!(crate::file_system::smb_concurrency(), 1);
151+
152+
// smb_concurrency clamps 100 → 32 (max)
153+
set_smb_concurrency_cmd(100);
154+
assert_eq!(crate::file_system::smb_concurrency(), 32);
155+
156+
// smb_concurrency accepts values within 1..=32 unchanged
157+
set_smb_concurrency_cmd(7);
158+
assert_eq!(crate::file_system::smb_concurrency(), 7);
159+
160+
// direct_smb_connection round-trips
161+
set_direct_smb_connection(false);
162+
assert!(!crate::file_system::is_direct_smb_enabled());
163+
set_direct_smb_connection(true);
164+
assert!(crate::file_system::is_direct_smb_enabled());
165+
166+
// filter_safe_save_artifacts round-trips
167+
set_filter_safe_save_artifacts_cmd(false);
168+
assert!(!crate::file_system::is_filter_safe_save_artifacts_enabled());
169+
set_filter_safe_save_artifacts_cmd(true);
170+
assert!(crate::file_system::is_filter_safe_save_artifacts_enabled());
171+
172+
// Restore defaults so later tests see a predictable state.
173+
set_smb_concurrency_cmd(10);
174+
}
175+
114176
#[test]
115177
fn test_find_available_port() {
116178
// Should find some available port

apps/desktop/src-tauri/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,9 @@ pub fn run() {
984984
commands::settings::update_file_watcher_debounce,
985985
commands::settings::update_service_resolve_timeout,
986986
commands::settings::update_menu_accelerator,
987+
commands::settings::set_direct_smb_connection,
988+
commands::settings::set_filter_safe_save_artifacts_cmd,
989+
commands::settings::set_smb_concurrency_cmd,
987990
// Logging commands (frontend log bridge + runtime level control)
988991
commands::logging::batch_fe_logs,
989992
commands::logging::set_log_level,

0 commit comments

Comments
 (0)