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(native-host): detect portable mode before handling Chrome messages

InstaZDLL3097cb7d399c
diff --git a/src-tauri/src/native_host.rs b/src-tauri/src/native_host.rs
index 7ed28a0b..79ca95a3 100644
--- a/src-tauri/src/native_host.rs
+++ b/src-tauri/src/native_host.rs
@@ -65,12 +65,47 @@ pub fn should_run_as_native_host() -> bool {
}
pub fn run_native_host() -> anyhow::Result<()> {
+ detect_portable_mode();
let request = read_message()?;
let response = handle_request(request);
write_message(&response)?;
Ok(())
}
+/// Detect portable mode by reading the native-host config to locate the main
+/// app executable, then checking its parent directory for portable markers.
+/// This mirrors the `check_portable_mode()` logic in `main.rs` so that
+/// `app_data_dir()` resolves to the portable data directory when the native
+/// host process is launched by Chrome.
+fn detect_portable_mode() {
+ let exe = match std::env::current_exe() {
+ Ok(p) => p,
+ Err(_) => return,
+ };
+ let host_dir = match exe.parent() {
+ Some(d) => d,
+ None => return,
+ };
+ let config_bytes = match fs::read(host_dir.join(HOST_CONFIG_NAME)) {
+ Ok(b) => b,
+ Err(_) => return,
+ };
+ let config: NativeHostConfig = match serde_json::from_slice(&config_bytes) {
+ Ok(c) => c,
+ Err(_) => return,
+ };
+ let app_dir = match Path::new(&config.app_path).parent() {
+ Some(d) => d,
+ None => return,
+ };
+ if app_dir.join("portable.txt").exists() || app_dir.join(".portable").exists() {
+ let data_dir = app_dir.join("data");
+ let _ = 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());
+ }
+}
+
pub fn ensure_registered() -> anyhow::Result<()> {
let current_exe = std::env::current_exe()?;
let integration_dir = chrome_integration_dir();