|
2 | 2 |
|
3 | 3 | use tauri::{AppHandle, Manager}; |
4 | 4 |
|
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 | +}; |
6 | 8 | use crate::ignore_poison::IgnorePoison; |
7 | 9 | use crate::menu::{ |
8 | 10 | 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) { |
46 | 48 | // No-op on non-macOS platforms |
47 | 49 | } |
48 | 50 |
|
| 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 | + |
49 | 73 | /// Update menu accelerator for a command. |
50 | 74 | /// Called from frontend when keyboard shortcuts are changed. |
51 | 75 | #[tauri::command] |
@@ -111,6 +135,44 @@ mod tests { |
111 | 135 | let _ = result; |
112 | 136 | } |
113 | 137 |
|
| 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 | + |
114 | 176 | #[test] |
115 | 177 | fn test_find_available_port() { |
116 | 178 | // Should find some available port |
|
0 commit comments