From 85cdabd72b7754fcf920a505a081687f5f8c8286 Mon Sep 17 00:00:00 2001 From: NimBold Date: Tue, 16 Jun 2026 15:10:29 +0330 Subject: [PATCH] feat: implement settings engine with directory picker and aria2 configuration sync --- src-tauri/src/lib.rs | 29 +++++++++++++-- src/App.tsx | 2 +- src/components/SettingsView.tsx | 26 +++++++++++++ src/hooks/useDirectoryPicker.ts | 22 +++++++++++ src/store/settingsStore.ts | 66 +++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 src/hooks/useDirectoryPicker.ts create mode 100644 src/store/settingsStore.ts diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 16f3def..f255937 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1435,10 +1435,26 @@ pub fn run() { } crate::scheduler::spawn_scheduler(app.handle().clone()); + let mut global_speed_limit = String::new(); + { + use tauri_plugin_store::StoreExt; + if let Ok(store) = app.handle().store("store.bin") { + if let Some(settings_val) = store.get("settings") { + if let Some(settings_str) = settings_val.as_str() { + if let Ok(settings_json) = serde_json::from_str::(settings_str) { + if let Some(limit) = settings_json.get("globalSpeedLimit").and_then(|v| v.as_str()) { + global_speed_limit = limit.to_string(); + } + } + } + } + } + } + use tauri_plugin_shell::ShellExt; let aria2_process = match app.handle().shell().sidecar("aria2c") { - Ok(cmd) => { - cmd.arg("--enable-rpc=true") + Ok(mut cmd) => { + cmd = cmd.arg("--enable-rpc=true") .arg(format!("--rpc-listen-port={}", aria2_port)) .arg(format!("--rpc-secret={}", aria2_secret)) .arg("--rpc-listen-all=false") @@ -1447,8 +1463,13 @@ pub fn run() { .arg("--summary-interval=1") .arg("--console-log-level=warn") .arg("--download-result=hide") - .arg("--check-certificate=true") - .spawn() + .arg("--check-certificate=true"); + + if !global_speed_limit.is_empty() { + cmd = cmd.arg(format!("--max-overall-download-limit={}", global_speed_limit)); + } + + cmd.spawn() .map(|(_, child)| child) .ok() } diff --git a/src/App.tsx b/src/App.tsx index 93d6d56..d2e0f4f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -34,7 +34,7 @@ function App() { const doneCount = downloads.filter(download => download.status === 'completed').length; const schedulerRunning = useSettingsStore(state => state.schedulerRunning); const globalSpeedLimit = useSettingsStore(state => state.globalSpeedLimit); - const previousSpeedLimit = useRef(globalSpeedLimit); + const previousSpeedLimit = useRef(null); const maxConcurrentDownloads = useSettingsStore(state => state.maxConcurrentDownloads); const startSidebarResize = (event: React.PointerEvent) => { diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsx index 32a4521..5c73dd1 100644 --- a/src/components/SettingsView.tsx +++ b/src/components/SettingsView.tsx @@ -5,6 +5,7 @@ import { SettingsTab, useSettingsStore } from '../store/useSettingsStore'; +import { useDirectoryPicker } from '../hooks/useDirectoryPicker'; import { Download, Palette, Globe, Folder, Key, Moon, Terminal, Puzzle, Info, Plus, Trash2, Copy, RefreshCw, Code @@ -29,6 +30,7 @@ const settingsTabs: { type: SettingsTab; label: string; icon: typeof Download }[ export default function SettingsView() { const settings = useSettingsStore(); + const { pickDirectory } = useDirectoryPicker(); const activeTab = settings.activeSettingsTab; // Local state for versions @@ -537,6 +539,30 @@ export default function SettingsView() { {/* Locations Pane */} {activeTab === 'locations' && (
+
+
+ Default Download Path +
+ settings.setDefaultDownloadPath(e.target.value)} + className="app-control w-64 text-[11px] px-2" + placeholder="~/Downloads" + /> + +
+
+
+