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.

feat: add external data cache method to PluginHost and update dependencies

Tonhobd7a54d83279
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 01a4e8d7..ecf1c713 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -2080,6 +2080,12 @@ dependencies = [
"pin-project-lite",
]
+[[package]]
+name = "http-range"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
+
[[package]]
name = "httparse"
version = "1.10.1"
@@ -5399,6 +5405,7 @@ dependencies = [
"gtk",
"heck 0.5.0",
"http",
+ "http-range",
"jni",
"libc",
"log",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 20add563..074b6f45 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -17,7 +17,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2", features = [] }
[dependencies]
-tauri = { version = "2", features = ["tray-icon"] }
+tauri = { version = "2", features = ["protocol-asset", "tray-icon"] }
tauri-plugin-shell = "2"
tauri-plugin-store = "2"
tauri-plugin-dialog = "2"
diff --git a/src-tauri/omniget-plugin-sdk/src/host.rs b/src-tauri/omniget-plugin-sdk/src/host.rs
index 81a75bfc..e1052f30 100644
--- a/src-tauri/omniget-plugin-sdk/src/host.rs
+++ b/src-tauri/omniget-plugin-sdk/src/host.rs
@@ -10,6 +10,63 @@ pub trait PluginHost: Send + Sync {
fn proxy_config(&self) -> Option<ProxyConfig>;
fn tool_path(&self, tool: &str) -> Option<PathBuf>;
fn default_output_dir(&self) -> PathBuf;
+
+ /// Returns a writable directory for large, regenerable, versionable caches
+ /// that do NOT belong in `plugin_data_dir` (which is for backup-worthy user
+ /// data like settings, notes, presets).
+ ///
+ /// Intended for: CommunityDragon hash tables, downloaded CDN assets, ML model
+ /// caches, snapshots of expensive external APIs — anything sized in MB/GB that
+ /// the plugin can always re-fetch if deleted.
+ ///
+ /// Do NOT use for: user settings (use `save_settings`), personal data
+ /// (use `plugin_data_dir`), artifacts the user should see in their file
+ /// manager (use `default_output_dir`).
+ ///
+ /// # Parameters
+ ///
+ /// - `plugin_id`: the caller plugin's id. Host uses this to scope caches
+ /// per-plugin so different plugins never collide.
+ /// - `namespace`: an arbitrary plugin-controlled string used to partition
+ /// multiple caches inside the same plugin (e.g. `"lol-hashes"`,
+ /// `"cdragon-assets"`, `"patch-14-23"`). Typical shape is
+ /// `"{domain}-{version}"` so the plugin can purge old versions by
+ /// dropping one subdir.
+ ///
+ /// # Returns
+ ///
+ /// The full `PathBuf` to the directory. Unlike `plugin_data_dir` (which
+ /// returns a path without creating it), this method guarantees the
+ /// directory exists and is writable before returning — callers can write
+ /// immediately without a separate `create_dir_all` step.
+ ///
+ /// # Platform layout
+ ///
+ /// - Windows: `%LOCALAPPDATA%\wtf.tonho.omniget\external-cache\{plugin_id}\{namespace}\`
+ /// - Linux: `$XDG_CACHE_HOME/wtf.tonho.omniget/external-cache/{plugin_id}/{namespace}/` (falls back to `~/.cache/...`)
+ /// - macOS: `~/Library/Caches/wtf.tonho.omniget/external-cache/{plugin_id}/{namespace}/`
+ ///
+ /// These are the OS-canonical cache locations (non-roaming on Windows,
+ /// `$XDG_CACHE_HOME` on Linux, `Caches/` on macOS). They are deliberately
+ /// separate from `plugin_data_dir`, which lives under the roaming /
+ /// data directory and is expected to be backed up.
+ ///
+ /// # Lifecycle
+ ///
+ /// The host never cleans or expires these directories automatically. The
+ /// plugin owns its own retention policy — bump the namespace string when
+ /// the underlying data version changes and purge the old subdir when
+ /// appropriate.
+ ///
+ /// # Capability declaration
+ ///
+ /// Plugins that use this method should declare `"core:external-data-cache"`
+ /// in their `plugin.json` `capabilities` array for marketplace transparency.
+ /// Note: capability declarations are currently informational — the host
+ /// surfaces them to the user in the marketplace UI but does NOT enforce
+ /// them at runtime for any SDK method. A future host revision may
+ /// introduce uniform runtime enforcement for all capabilities at once.
+ fn external_data_cache(&self, plugin_id: &str, namespace: &str) -> anyhow::Result<PathBuf>;
}
#[derive(Debug, Clone)]
diff --git a/src-tauri/omniget-plugin-sdk/src/lib.rs b/src-tauri/omniget-plugin-sdk/src/lib.rs
index 38aade5d..7cf2c2f8 100644
--- a/src-tauri/omniget-plugin-sdk/src/lib.rs
+++ b/src-tauri/omniget-plugin-sdk/src/lib.rs
@@ -6,4 +6,4 @@ pub use host::*;
pub use manifest::*;
pub use plugin::*;
-pub const ABI_VERSION: u32 = 1;
+pub const ABI_VERSION: u32 = 2;
diff --git a/src-tauri/src/plugin_host.rs b/src-tauri/src/plugin_host.rs
index 374b9e52..22da92d9 100644
--- a/src-tauri/src/plugin_host.rs
+++ b/src-tauri/src/plugin_host.rs
@@ -105,4 +105,36 @@ impl<R: Runtime + 'static> PluginHost for PluginHostImpl<R> {
.or_else(dirs::home_dir)
.unwrap_or_else(|| PathBuf::from("."))
}
+
+ fn external_data_cache(&self, plugin_id: &str, namespace: &str) -> anyhow::Result<PathBuf> {
+ if plugin_id.is_empty() {
+ anyhow::bail!("external_data_cache: plugin_id must not be empty");
+ }
+ if namespace.is_empty() {
+ anyhow::bail!("external_data_cache: namespace must not be empty");
+ }
+ if plugin_id.contains(['/', '\\', ':', '\0']) || namespace.contains(['/', '\\', ':', '\0'])
+ {
+ anyhow::bail!(
+ "external_data_cache: plugin_id/namespace must not contain path separators or null bytes"
+ );
+ }
+
+ let base = dirs::cache_dir().ok_or_else(|| {
+ anyhow::anyhow!("external_data_cache: OS cache dir unavailable on this platform")
+ })?;
+ let dir = base
+ .join("wtf.tonho.omniget")
+ .join("external-cache")
+ .join(plugin_id)
+ .join(namespace);
+ std::fs::create_dir_all(&dir).map_err(|e| {
+ anyhow::anyhow!(
+ "external_data_cache: failed to create {}: {}",
+ dir.display(),
+ e
+ )
+ })?;
+ Ok(dir)
+ }
}
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json
index cbce5fc2..2c81a899 100644
--- a/src-tauri/tauri.conf.json
+++ b/src-tauri/tauri.conf.json
@@ -19,7 +19,11 @@
}
],
"security": {
- "csp": null
+ "csp": null,
+ "assetProtocol": {
+ "enable": true,
+ "scope": ["**"]
+ }
}
},
"plugins": {