Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix(portable): anchor the settings store to the portable data dir

Antonio Leandro03e183f9bf6f
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 7823f88f..e0b716e3 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -8,6 +8,19 @@ fn check_portable_mode() {
let _ = std::fs::create_dir_all(&data_dir);
std::env::set_var("OMNIGET_PORTABLE", "1");
std::env::set_var("OMNIGET_DATA_DIR", data_dir.to_string_lossy().to_string());
+
+ // Older versions resolved the settings store against Tauri's
+ // own AppData dir, so portable users' settings landed in the
+ // OS profile. Adopt that file once if the portable dir has none.
+ let portable_settings = data_dir.join("settings.json");
+ if !portable_settings.exists() {
+ if let Some(os_settings) = dirs::data_dir()
+ .map(|d| d.join("wtf.tonho.omniget").join("settings.json"))
+ .filter(|p| p.exists())
+ {
+ let _ = std::fs::copy(&os_settings, &portable_settings);
+ }
+ }
}
}
}
diff --git a/src-tauri/src/storage/config.rs b/src-tauri/src/storage/config.rs
index fee784bf..6121db37 100644
--- a/src-tauri/src/storage/config.rs
+++ b/src-tauri/src/storage/config.rs
@@ -6,8 +6,19 @@ use crate::models::settings::AppSettings;
const STORE_PATH: &str = "settings.json";
const STORE_KEY: &str = "app_settings";
+/// Absolute path of the settings store, anchored to the app data dir that
+/// honors OMNIGET_DATA_DIR. A relative store path resolves against Tauri's
+/// own AppData dir, which ignores the portable-mode override — the store
+/// writers and the standalone readers below would then use different files.
+fn store_path() -> std::path::PathBuf {
+ match crate::core::paths::app_data_dir() {
+ Some(dir) => dir.join(STORE_PATH),
+ None => std::path::PathBuf::from(STORE_PATH),
+ }
+}
+
pub fn load_settings(app: &AppHandle) -> AppSettings {
- let store = match app.store(STORE_PATH) {
+ let store = match app.store(store_path()) {
Ok(s) => s,
Err(_) => return AppSettings::default(),
};
@@ -42,7 +53,7 @@ pub fn load_settings_standalone() -> AppSettings {
}
pub fn save_settings(app: &AppHandle, settings: &AppSettings) -> anyhow::Result<()> {
- let store = app.store(STORE_PATH)?;
+ let store = app.store(store_path())?;
let val = serde_json::to_value(settings)?;
store.set(STORE_KEY, val);
store.save()?;