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: apply proxy to all HTTP clients, marketplace registry fallback via jsDelivr and force-update for managed dependencies (#135, #140, #131, #128)

Tonhod0b9dc668242
diff --git a/src-tauri/omniget-core/src/core/dependencies.rs b/src-tauri/omniget-core/src/core/dependencies.rs
index 6e311696..b44c7ffb 100644
--- a/src-tauri/omniget-core/src/core/dependencies.rs
+++ b/src-tauri/omniget-core/src/core/dependencies.rs
@@ -193,6 +193,57 @@ pub async fn check_version(tool: &str) -> Option<String> {
result
}
+pub fn replace_managed_binary(
+ temp: &std::path::Path,
+ target: &std::path::Path,
+) -> anyhow::Result<()> {
+ if !target.exists() {
+ std::fs::rename(temp, target)
+ .map_err(|e| anyhow!("Failed to move {} into place: {}", target.display(), e))?;
+ return Ok(());
+ }
+
+ if cfg!(windows) {
+ let file_name = target
+ .file_name()
+ .and_then(|n| n.to_str())
+ .unwrap_or("binary")
+ .to_string();
+ let old = target.with_file_name(format!("{}.old", file_name));
+ let _ = std::fs::remove_file(&old);
+ if let Err(e) = std::fs::rename(target, &old) {
+ let _ = std::fs::remove_file(temp);
+ return Err(anyhow!(
+ "{} is in use by another process ({}). Wait for active downloads to finish or cancel them, then try again.",
+ file_name,
+ e
+ ));
+ }
+ if let Err(e) = std::fs::rename(temp, target) {
+ let _ = std::fs::rename(&old, target);
+ let _ = std::fs::remove_file(temp);
+ return Err(anyhow!("Failed to replace {}: {}", file_name, e));
+ }
+ let _ = std::fs::remove_file(&old);
+ Ok(())
+ } else {
+ std::fs::rename(temp, target)
+ .map_err(|e| anyhow!("Failed to replace {}: {}", target.display(), e))?;
+ Ok(())
+ }
+}
+
+pub async fn update_ffmpeg() -> anyhow::Result<PathBuf> {
+ if is_flatpak() {
+ return Err(anyhow!(
+ "FFmpeg is provided by the Flatpak runtime and cannot be updated from inside the app"
+ ));
+ }
+ let path = download_ffmpeg().await?;
+ crate::core::ytdlp::reset_ffmpeg_location_cache();
+ Ok(path)
+}
+
pub async fn ensure_ffmpeg() -> anyhow::Result<PathBuf> {
// Always ensure the managed binary exists — the standalone yt-dlp.exe
// cannot discover system FFmpeg from PATH.
@@ -272,6 +323,13 @@ async fn download_ffmpeg() -> anyhow::Result<PathBuf> {
let _ = std::fs::remove_file(&temp_path);
}
+ for name in [&ffmpeg_name, &ffprobe_name] {
+ let staged = bin_dir.join(format!("{}.new", name));
+ if staged.exists() {
+ replace_managed_binary(&staged, &bin_dir.join(name))?;
+ }
+ }
+
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
@@ -409,7 +467,7 @@ async fn extract_zip_ffmpeg(
let name = entry.name().to_string();
for target in &targets {
if name.ends_with(target) {
- let dest = bin_dir.join(target);
+ let dest = bin_dir.join(format!("{}.new", target));
let mut out = std::fs::File::create(&dest)?;
std::io::copy(&mut entry, &mut out)?;
break;
@@ -454,7 +512,7 @@ async fn extract_tar_xz_ffmpeg(
let file_name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
for target in &targets {
if file_name == *target {
- let dest = bin_dir.join(target);
+ let dest = bin_dir.join(format!("{}.new", target));
let mut out = std::fs::File::create(&dest)?;
std::io::copy(&mut entry, &mut out)?;
break;
diff --git a/src-tauri/omniget-core/src/core/hls_downloader.rs b/src-tauri/omniget-core/src/core/hls_downloader.rs
index 66a874fe..d942f6fd 100644
--- a/src-tauri/omniget-core/src/core/hls_downloader.rs
+++ b/src-tauri/omniget-core/src/core/hls_downloader.rs
@@ -32,15 +32,21 @@ impl Default for HlsDownloader {
impl HlsDownloader {
pub fn new() -> Self {
- Self::with_client(
+ let builder = crate::core::http_client::apply_global_proxy(
Client::builder()
.connect_timeout(Duration::from_secs(30))
.timeout(Duration::from_secs(300))
.pool_max_idle_per_host(50)
- .pool_idle_timeout(Duration::from_secs(30))
- .build()
- .unwrap(),
- )
+ .pool_idle_timeout(Duration::from_secs(30)),
+ );
+ let client = match builder.build() {
+ Ok(c) => c,
+ Err(e) => {
+ tracing::warn!("HLS client build failed, falling back to default: {}", e);
+ Client::new()
+ }
+ };
+ Self::with_client(client)
}
pub fn with_client(client: Client) -> Self {
diff --git a/src-tauri/src/commands/dependencies.rs b/src-tauri/src/commands/dependencies.rs
index 2b1d3fab..542ca2bd 100644
--- a/src-tauri/src/commands/dependencies.rs
+++ b/src-tauri/src/commands/dependencies.rs
@@ -57,18 +57,35 @@ pub async fn check_ytdlp_available() -> Result<bool, String> {
}
#[tauri::command]
-pub async fn install_dependency(name: String, variant: Option<String>) -> Result<String, String> {
+pub async fn install_dependency(
+ name: String,
+ variant: Option<String>,
+ force: Option<bool>,
+) -> Result<String, String> {
+ let force = force.unwrap_or(false);
match name.as_str() {
"yt-dlp" => {
- crate::core::ytdlp::ensure_ytdlp()
- .await
- .map_err(|e| e.to_string())?;
+ if force {
+ crate::core::ytdlp::update_ytdlp()
+ .await
+ .map_err(|e| e.to_string())?;
+ } else {
+ crate::core::ytdlp::ensure_ytdlp()
+ .await
+ .map_err(|e| e.to_string())?;
+ }
crate::core::ytdlp::reset_ytdlp_cache();
}
"FFmpeg" => {
- dependencies::ensure_ffmpeg()
- .await
- .map_err(|e| e.to_string())?;
+ if force {
+ dependencies::update_ffmpeg()
+ .await
+ .map_err(|e| e.to_string())?;
+ } else {
+ dependencies::ensure_ffmpeg()
+ .await
+ .map_err(|e| e.to_string())?;
+ }
crate::core::ytdlp::reset_ffmpeg_location_cache();
crate::core::ffmpeg::reset_ffmpeg_available_cache();
}
diff --git a/src-tauri/src/commands/plugins.rs b/src-tauri/src/commands/plugins.rs
index b5d6ceb4..fe4c64ac 100644
--- a/src-tauri/src/commands/plugins.rs
+++ b/src-tauri/src/commands/plugins.rs
@@ -197,8 +197,10 @@ pub async fn plugin_command(
manager.handle_command(&plugin_id, &command, args).await
}
-const REGISTRY_URL: &str =
- "https://raw.githubusercontent.com/tonhowtf/omniget-plugins/main/plugins.json";
+const REGISTRY_URLS: &[&str] = &[
+ "https://raw.githubusercontent.com/tonhowtf/omniget-plugins/main/plugins.json",
+ "https://cdn.jsdelivr.net/gh/tonhowtf/omniget-plugins@main/plugins.json",
+];
#[derive(Debug, Serialize)]
pub struct MarketplaceEntry {
@@ -219,30 +221,59 @@ pub struct MarketplaceEntry {
pub async fn fetch_marketplace_registry(
state: tauri::State<'_, Arc<tokio::sync::RwLock<PluginManager>>>,
) -> Result<Vec<MarketplaceEntry>, String> {
- let client = reqwest::Client::builder()
- .user_agent("OmniGet")
- .timeout(std::time::Duration::from_secs(15))
- .build()
- .map_err(|e| e.to_string())?;
-
- let response = client
- .get(REGISTRY_URL)
- .send()
- .await
- .map_err(|e| format!("Failed to fetch registry: {}", e))?;
-
- let body = response
- .text()
- .await
- .map_err(|e| format!("Failed to read registry: {}", e))?;
+ let client = crate::core::http_client::apply_global_proxy(
+ reqwest::Client::builder()
+ .user_agent("OmniGet")
+ .timeout(std::time::Duration::from_secs(15)),
+ )
+ .build()
+ .map_err(|e| e.to_string())?;
#[derive(Deserialize)]
struct RegistryFile {
plugins: Vec<RegistryEntry>,
}
- let registry: RegistryFile =
- serde_json::from_str(&body).map_err(|e| format!("Invalid registry: {}", e))?;
+ let mut registry: Option<RegistryFile> = None;
+ let mut last_err = String::from("Failed to fetch registry");
+
+ for url in REGISTRY_URLS {
+ let body = match client.get(*url).send().await {
+ Ok(resp) => match resp.error_for_status() {
+ Ok(resp) => match resp.text().await {
+ Ok(body) => body,
+ Err(e) => {
+ last_err = format!("Failed to read registry: {}", e);
+ tracing::warn!("registry fetch via {} failed: {}", url, last_err);
+ continue;
+ }
+ },
+ Err(e) => {
+ last_err = format!("Registry request failed: {}", e);
+ tracing::warn!("registry fetch via {} failed: {}", url, last_err);
+ continue;
+ }
+ },
+ Err(e) => {
+ last_err = format!("Failed to fetch registry: {}", e);
+ tracing::warn!("registry fetch via {} failed: {}", url, last_err);
+ continue;
+ }
+ };
+
+ match serde_json::from_str::<RegistryFile>(&body) {
+ Ok(parsed) => {
+ registry = Some(parsed);
+ break;
+ }
+ Err(e) => {
+ last_err = format!("Invalid registry: {}", e);
+ tracing::warn!("registry fetch via {} failed: {}", url, last_err);
+ }
+ }
+ }
+
+ let registry = registry.ok_or(last_err)?;
let installed = {
let manager = state.read().await;
@@ -309,17 +340,18 @@ pub async fn install_plugin_zip_from_repo(
return Err("Unsupported platform".to_string());
}
- let client = reqwest::Client::builder()
- .user_agent("OmniGet")
- .build()
- .map_err(|e| e.to_string())?;
+ let client = crate::core::http_client::apply_global_proxy(
+ reqwest::Client::builder().user_agent("OmniGet"),
+ )
+ .build()
+ .map_err(|e| e.to_string())?;
let api_url = format!("https://api.github.com/repos/{}/releases/latest", repo);
let release: GitHubRelease = client
.get(&api_url)
.send()
.await
- .map_err(|e| format!("Failed to fetch release: {}", e))?
+ .map_err(|e| format!("NetworkUnreachable|Failed to fetch release: {}", e))?
.json()
.await
.map_err(|e| format!("Invalid release response: {}", e))?;
@@ -334,10 +366,10 @@ pub async fn install_plugin_zip_from_repo(
.get(&asset.browser_download_url)
.send()
.await
- .map_err(|e| format!("Failed to download: {}", e))?
+ .map_err(|e| format!("NetworkUnreachable|Failed to download: {}", e))?
.bytes()
.await
- .map_err(|e| format!("Failed to read download: {}", e))?;
+ .map_err(|e| format!("NetworkUnreachable|Failed to read download: {}", e))?;
let plugin_dir = {
let manager = state.read().await;
@@ -452,11 +484,13 @@ pub async fn check_plugin_updates(
manager.installed_plugins().to_vec()
};
- let client = reqwest::Client::builder()
- .user_agent("OmniGet")
- .timeout(std::time::Duration::from_secs(15))
- .build()
- .map_err(|e| e.to_string())?;
+ let client = crate::core::http_client::apply_global_proxy(
+ reqwest::Client::builder()
+ .user_agent("OmniGet")
+ .timeout(std::time::Duration::from_secs(15)),
+ )
+ .build()
+ .map_err(|e| e.to_string())?;
let mut updates = Vec::new();
diff --git a/src/lib/updater.ts b/src/lib/updater.ts
index 05b814fc..6ff85299 100644
--- a/src/lib/updater.ts
+++ b/src/lib/updater.ts
@@ -1,6 +1,7 @@
import { check } from "@tauri-apps/plugin-updater";
import { relaunch } from "@tauri-apps/plugin-process";
import { storeChangelogForUpdate } from "$lib/stores/changelog-store.svelte";
+import { getSettings } from "$lib/stores/settings-store.svelte";
export interface UpdateInfo {
available: boolean;
@@ -8,9 +9,22 @@ export interface UpdateInfo {
body?: string;
}
+function proxyUrl(): string | undefined {
+ const proxy = getSettings()?.proxy;
+ if (!proxy?.enabled || !proxy.host || !proxy.port) return undefined;
+ const scheme =
+ proxy.proxy_type === "socks5" || proxy.proxy_type === "https"
+ ? proxy.proxy_type
+ : "http";
+ const auth = proxy.username
+ ? `${encodeURIComponent(proxy.username)}:${encodeURIComponent(proxy.password ?? "")}@`
+ : "";
+ return `${scheme}://${auth}${proxy.host}:${proxy.port}`;
+}
+
export async function checkForUpdate(): Promise<UpdateInfo> {
try {
- const update = await check();
+ const update = await check({ proxy: proxyUrl() });
if (update) {
return {
available: true,
@@ -25,7 +39,7 @@ export async function checkForUpdate(): Promise<UpdateInfo> {
}
export async function installUpdate(): Promise<void> {
- const update = await check();
+ const update = await check({ proxy: proxyUrl() });
if (update) {
if (update.body && update.version) {
storeChangelogForUpdate(update.body, update.version);
diff --git a/src/routes/marketplace/+page.svelte b/src/routes/marketplace/+page.svelte
index ebeb147a..d9b0a5e6 100644
--- a/src/routes/marketplace/+page.svelte
+++ b/src/routes/marketplace/+page.svelte
@@ -162,7 +162,10 @@
await invoke("install_plugin_from_registry", { pluginId: id, repo });
await refreshPlugins();
} catch (e: any) {
- const msg = typeof e === "string" ? e : e?.message ?? $t("common.error");
+ const raw = typeof e === "string" ? e : e?.message ?? $t("common.error");
+ const msg = raw.startsWith("NetworkUnreachable|")
+ ? $t("marketplace.install_network_error")
+ : raw;
showToast("error", msg);
}
installingId = null;
@@ -305,7 +308,8 @@
{:else if browseError}
<div class="empty">
<p>{$t("marketplace.browse_error")}</p>
- <button class="btn btn-secondary retry-btn" onclick={loadBrowse}>{$t("marketplace.browse")}</button>
+ <p class="error-hint">{$t("marketplace.browse_error_hint")}</p>
+ <button class="btn btn-secondary retry-btn" onclick={loadBrowse}>{$t("marketplace.browse_retry")}</button>
</div>
{:else if registry.length === 0}
<div class="empty">
@@ -456,6 +460,13 @@
gap: var(--padding);
}
+ .error-hint {
+ max-width: 420px;
+ font-size: 12.5px;
+ line-height: 1.5;
+ color: var(--gray);
+ }
+
.retry-btn {
padding: 8px 16px;
font-size: 13px;
diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte
index e423fbc6..c677727d 100644
--- a/src/routes/settings/+page.svelte
+++ b/src/routes/settings/+page.svelte
@@ -52,11 +52,19 @@
}
async function handleInstallDep(name: string, variant: string | null = null) {
+ const wasInstalled = deps.find((d) => d.name === name)?.installed ?? false;
installingDep = name;
try {
- await invoke("install_dependency", { name, variant });
+ const version = await invoke<string>("install_dependency", { name, variant, force: wasInstalled });
await loadDeps();
await refreshYtdlpStatus();
+ showToast(
+ "success",
+ $t(
+ wasInstalled ? "settings.dependencies.update_success" : "settings.dependencies.install_success",
+ { name, version },
+ ) as string,
+ );
} catch (e: any) {
showToast("error", typeof e === "string" ? e : e.message ?? $t("common.error"));
} finally {