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(migration): auto-migrate omniget database and clean legacy app on all platforms

IGECTa21e861fe400
diff --git a/src-tauri/nsis/installer-hooks.nsh b/src-tauri/nsis/installer-hooks.nsh
new file mode 100644
index 00000000..f6137427
--- /dev/null
+++ b/src-tauri/nsis/installer-hooks.nsh
@@ -0,0 +1,17 @@
+!macro NSIS_HOOK_PREINSTALL
+ ; Terminate running OmniGet process so uninstaller can remove files without locks
+ DetailPrint "Stopping running instances of OmniGet..."
+ nsExec::Exec 'taskkill /F /IM "omniget.exe"'
+ nsExec::Exec 'taskkill /F /IM "OmniGet.exe"'
+ Sleep 1000
+
+ ; Remove previous per-user OmniGet installation if present
+ IfFileExists "$LOCALAPPDATA\Programs\OmniGet\uninstall.exe" 0 +3
+ DetailPrint "Removing previous OmniGet installation..."
+ ExecWait '"$LOCALAPPDATA\Programs\OmniGet\uninstall.exe" /S _?=$LOCALAPPDATA\Programs\OmniGet'
+
+ ; Remove previous machine-wide OmniGet installation if present
+ IfFileExists "$PROGRAMFILES\OmniGet\uninstall.exe" 0 +3
+ DetailPrint "Removing previous machine-wide OmniGet installation..."
+ ExecWait '"$PROGRAMFILES\OmniGet\uninstall.exe" /S _?=$PROGRAMFILES\OmniGet'
+!macroend
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 8453c615..0ad84a1e 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -665,6 +665,8 @@ pub fn run() {
// native-messaging code left under `~/.config/...` so Chrome and
// Firefox stop trying to start the legacy host process.
extension_storage::cleanup_legacy_native_messaging();
+ migrate_legacy_omniget_data();
+ cleanup_legacy_omniget_artifacts();
// Cookie Manager: reparticiona `chrome-extension-cookies.txt` legacy em
// `cookies/<domain>/_default.txt` (CK-1). Quando o registry já tem
@@ -1333,3 +1335,114 @@ pub fn run() {
}
});
}
+
+fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> std::io::Result<()> {
+ std::fs::create_dir_all(dst)?;
+ for entry in std::fs::read_dir(src)? {
+ let entry = entry?;
+ let path = entry.path();
+ let dest_path = dst.join(entry.file_name());
+ if path.is_dir() {
+ copy_dir_recursive(&path, &dest_path)?;
+ } else if !dest_path.exists() {
+ let _ = std::fs::copy(&path, &dest_path);
+ }
+ }
+ Ok(())
+}
+
+fn migrate_legacy_omniget_data() {
+ let Some(data_dir) = dirs::data_dir() else {
+ return;
+ };
+ let legacy_dir = data_dir.join("com.openselena.omniget");
+ let target_dir = data_dir.join("com.openselena.libreget");
+
+ if !legacy_dir.exists() || !legacy_dir.is_dir() {
+ return;
+ }
+
+ let _ = std::fs::create_dir_all(&target_dir);
+
+ // If libreget.db does not exist or is empty (<= 4096 bytes), adopt omniget.db
+ let target_db = target_dir.join("libreget.db");
+ let legacy_db = legacy_dir.join("omniget.db");
+ let should_migrate_db = !target_db.exists()
+ || std::fs::metadata(&target_db)
+ .map(|m| m.len() <= 4096)
+ .unwrap_or(false);
+
+ if should_migrate_db && legacy_db.exists() {
+ tracing::info!("Migrating legacy omniget database to libreget.db");
+ let _ = std::fs::copy(&legacy_db, &target_db);
+ let legacy_wal = legacy_dir.join("omniget.db-wal");
+ let target_wal = target_dir.join("libreget.db-wal");
+ if legacy_wal.exists() {
+ let _ = std::fs::copy(&legacy_wal, &target_wal);
+ }
+ let legacy_shm = legacy_dir.join("omniget.db-shm");
+ let target_shm = target_dir.join("libreget.db-shm");
+ if legacy_shm.exists() {
+ let _ = std::fs::copy(&legacy_shm, &target_shm);
+ }
+ }
+
+ // Migrate settings, state files, and sessions
+ let files = [
+ "settings.json",
+ "media-snapshots.json",
+ "queue.wal",
+ "telegram_plugin_state.json",
+ "telegram.session",
+ "study.db",
+ ];
+ for f in files {
+ let src = legacy_dir.join(f);
+ let dst = target_dir.join(f);
+ if src.exists() && !dst.exists() {
+ let _ = std::fs::copy(&src, &dst);
+ }
+ }
+
+ // Migrate cookies
+ let src_cookies = legacy_dir.join("cookies");
+ let dst_cookies = target_dir.join("cookies");
+ if src_cookies.exists() && !dst_cookies.exists() {
+ let _ = copy_dir_recursive(&src_cookies, &dst_cookies);
+ }
+}
+
+fn cleanup_legacy_omniget_artifacts() {
+ #[cfg(target_os = "linux")]
+ {
+ if let Some(data_dir) = dirs::data_dir() {
+ let target = data_dir.join("applications/omniget-handler.desktop");
+ if target.exists() {
+ let _ = std::fs::remove_file(&target);
+ }
+ }
+ }
+
+ #[cfg(target_os = "macos")]
+ {
+ let candidates = [
+ "/Applications/OmniGet.app",
+ &format!(
+ "{}/Applications/OmniGet.app",
+ std::env::var("HOME").unwrap_or_default()
+ ),
+ ];
+ for path in &candidates {
+ if std::path::Path::new(path).exists() {
+ let script = format!(
+ r#"tell application "Finder" to delete (POSIX file "{}")"#,
+ path
+ );
+ let _ = std::process::Command::new("osascript")
+ .arg("-e")
+ .arg(&script)
+ .output();
+ }
+ }
+ }
+}
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index 287381d7..62f3d8ef 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -80,6 +80,11 @@
"entitlements": "Entitlements.plist",
"minimumSystemVersion": "10.15"
},
+ "windows": {
+ "nsis": {
+ "installerHooks": "./nsis/installer-hooks.nsh"
+ }
+ },
"linux": {
"appimage": {
"bundleMediaFramework": true
@@ -89,6 +94,10 @@
"libasound2"
],
"desktopTemplate": "./desktop.template",
+ "provides": [
+ "omni-get",
+ "omniget"
+ ],
"replaces": [
"omni-get",
"omniget"
@@ -100,6 +109,10 @@
},
"rpm": {
"desktopTemplate": "./desktop.template",
+ "provides": [
+ "omni-get",
+ "omniget"
+ ],
"obsoletes": [
"omni-get",
"omniget"