Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

HyperDownload talks to its Chrome Web Store extension too

gelenmedya34d0bb2cfc88
diff --git a/crates/rf-app/src/addons_page.rs b/crates/rf-app/src/addons_page.rs
index 8aebe54d..5eadbe4d 100644
--- a/crates/rf-app/src/addons_page.rs
+++ b/crates/rf-app/src/addons_page.rs
@@ -155,7 +155,9 @@ fn download_folder_card(p: &Palette, cx: &mut App) -> AnyElement {
.children(custom.then(|| {
button("hd-downloads-reset", p, t!("Varsayılan"), |_, cx| {
crate::settings::update(cx, |s| s.hd_downloads.clear());
- crate::hyperdownload::register_host_with(cx.global::<crate::settings::Settings>());
+ // (off this thread: the registration waits a moment for the add-on's own)
+ let now = cx.global::<crate::settings::Settings>().clone();
+ cx.background_spawn(async move { crate::hyperdownload::register_host_with(&now) }).detach();
})
}))
.child(button("hd-downloads", p, t!("Değiştir…"), |_, cx| {
@@ -168,7 +170,8 @@ fn download_folder_card(p: &Palette, cx: &mut App) -> AnyElement {
if let Ok(Some(path)) = rx.await {
let _ = cx.update(|cx| {
crate::settings::update(cx, |s| s.hd_downloads = path.to_string_lossy().into_owned());
- crate::hyperdownload::register_host_with(cx.global::<crate::settings::Settings>());
+ let now = cx.global::<crate::settings::Settings>().clone();
+ cx.background_spawn(async move { crate::hyperdownload::register_host_with(&now) }).detach();
});
}
})
diff --git a/crates/rf-app/src/hyperdownload.rs b/crates/rf-app/src/hyperdownload.rs
index 0676c775..991a9aba 100644
--- a/crates/rf-app/src/hyperdownload.rs
+++ b/crates/rf-app/src/hyperdownload.rs
@@ -16,8 +16,9 @@ pub const ID: &str = "hyperdownload";
/// rustyfiles: show this download as a card of the Status Center.
pub const FOLLOW_PREFIX: &str = "hd-follow:";
-/// The browser extension's id while it is loaded unpacked (from the key in its manifest); the stores' ids join it once it is published.
-const EXTENSION_IDS: &[&str] = &["pbnficneolckhnkmpagjimjbhjahcepa"];
+/// The browser extension's ids: while it is loaded unpacked (from the key in its manifest), and as the Chrome Web Store's item
+/// (made 2026-12-05; the store signs it with a key of its own, which gives it another id). The host talks to these only.
+const EXTENSION_IDS: &[&str] = &["pbnficneolckhnkmpagjimjbhjahcepa", "leelanjmdoobhhnljlciednenkgkbjjd"];
const HOST_NAME: &str = "com.gelenmedya.hyperdownload";
/// Where the browsers look for native messaging hosts (current user only).
@@ -57,11 +58,30 @@ pub fn register_host_with(settings: &crate::settings::Settings) {
let origins: Vec<String> = EXTENSION_IDS.iter().map(|id| format!("chrome-extension://{id}/")).collect();
let manifest = json!({ "name": HOST_NAME, "description": "HyperDownload, the download manager of rustyfiles", "path": exe, "type": "stdio", "allowed_origins": origins });
let manifest_path = dir.join("native-host.json");
- if std::fs::write(&manifest_path, serde_json::to_vec_pretty(&manifest).unwrap_or_default()).is_err() {
- return;
- }
// a copy with settings of its own (a test copy) never points the user's browsers at its add-on
- if std::env::var_os("RUSTYFILES_CONFIG_DIR").is_some_and(|d| !d.is_empty()) {
+ let test_copy = std::env::var_os("RUSTYFILES_CONFIG_DIR").is_some_and(|d| !d.is_empty());
+ if !test_copy {
+ // The add-on's own registration FIRST, and waited for: Firefox's host, "Open with" for .torrent files and magnet links
+ // when nothing else takes them (HyperDownload issues 6 and 7). It also writes the browsers' manifest, with the extension
+ // ids IT knows: an add-on older than a new id (the Chrome Web Store's, added 2026-12-05) would put the manifest back to its
+ // own list if it ran after ours, and the store's extension would say "Not connected". So ours is written after it, below.
+ let mut cmd = std::process::Command::new(&exe);
+ cmd.arg("--register");
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ cmd.creation_flags(CREATE_NO_WINDOW);
+ }
+ if let Ok(mut child) = cmd.spawn() {
+ // (a few registry writes and one small file: done long before this; a stuck one must not hold us for ever)
+ let until = Instant::now() + Duration::from_secs(3);
+ while Instant::now() < until && matches!(child.try_wait(), Ok(None)) {
+ std::thread::sleep(Duration::from_millis(30));
+ }
+ }
+ }
+ if std::fs::write(&manifest_path, serde_json::to_vec_pretty(&manifest).unwrap_or_default()).is_err() || test_copy {
return;
}
for key in HOST_KEYS {
@@ -69,17 +89,25 @@ pub fn register_host_with(settings: &crate::settings::Settings) {
let _ = k.set_string("", manifest_path.to_string_lossy().as_ref());
}
}
- // the add-on's own registration on top: Firefox's host, "Open with" for .torrent files and magnet links when nothing else takes
- // them (HyperDownload issues 6 and 7); an older add-on knows only the browsers' part, the same as above
- let mut cmd = std::process::Command::new(&exe);
- cmd.arg("--register");
- #[cfg(windows)]
- {
- use std::os::windows::process::CommandExt;
- const CREATE_NO_WINDOW: u32 = 0x0800_0000;
- cmd.creation_flags(CREATE_NO_WINDOW);
+}
+
+/// Whether the browsers' manifest beside the add-on allows every extension id this rustyfiles knows. Pure.
+fn manifest_allows_all(manifest: &Value) -> bool {
+ let allowed: Vec<&str> = manifest["allowed_origins"].as_array().map(|a| a.iter().filter_map(Value::as_str).collect()).unwrap_or_default();
+ EXTENSION_IDS.iter().all(|id| allowed.iter().any(|o| o.trim_end_matches('/') == format!("chrome-extension://{id}")))
+}
+
+/// At a start of rustyfiles: when the add-on is installed and its browsers' manifest does not allow an extension id this version
+/// knows (the manifest was written by an older rustyfiles, before the extension was in a store), it is written again. Without
+/// this an updated rustyfiles would only do so the next time IT starts the add-on, which someone who only downloads from the
+/// browser never does. Blocking (see [`register_host_with`]): call it off the interface thread.
+pub fn refresh_host_if_stale() {
+ let Some(exe) = crate::addons::program(ID) else { return };
+ let Some(dir) = exe.parent() else { return };
+ let current = std::fs::read(dir.join("native-host.json")).ok().and_then(|b| serde_json::from_slice::<Value>(&b).ok());
+ if !current.is_some_and(|m| manifest_allows_all(&m)) {
+ register_host();
}
- let _ = cmd.spawn();
}
/// Before the add-on is removed: the browsers forget the host.
@@ -650,6 +678,18 @@ pub fn download_source(source: Source, dir: PathBuf, cx: &mut gpui_kit::App) {
mod tests {
use super::*;
+ /// The store's extension can only talk to the program when the manifest names its id: a manifest an older rustyfiles wrote
+ /// (the unpacked id alone) is found wanting, one with every id is not.
+ #[test]
+ fn a_manifest_without_a_known_extension_id_is_written_again() {
+ let old = json!({ "allowed_origins": ["chrome-extension://pbnficneolckhnkmpagjimjbhjahcepa/"] });
+ assert!(!manifest_allows_all(&old));
+ let all: Vec<String> = EXTENSION_IDS.iter().map(|id| format!("chrome-extension://{id}/")).collect();
+ assert!(manifest_allows_all(&json!({ "allowed_origins": all })));
+ assert!(!manifest_allows_all(&json!({})));
+ assert!(EXTENSION_IDS.iter().all(|id| id.len() == 32 && id.bytes().all(|b| (b'a'..=b'p').contains(&b))), "an extension id is 32 letters a to p");
+ }
+
/// HyperDownload issue 1: the host file says the folder the settings HAVE, not the one a file read back a moment later had.
#[test]
fn the_host_file_names_the_folder_chosen_in_settings() {
diff --git a/crates/rf-app/src/lib.rs b/crates/rf-app/src/lib.rs
index 1c998713..8d71077e 100644
--- a/crates/rf-app/src/lib.rs
+++ b/crates/rf-app/src/lib.rs
@@ -1170,6 +1170,10 @@ pub fn main() {
// updates from GitHub Releases (installed copies only)
installer::set_beta_updates(cx.global::<settings::Settings>().beta_updates);
installer::spawn_checks(cx, |cx| cx.refresh_windows());
+ // HyperDownload's browser registration, when an older rustyfiles wrote it without an extension id this one knows
+ if std::env::var_os("RUSTYFILES_MULTI_INSTANCE").is_none() && !bar_preview {
+ let _ = std::thread::Builder::new().name("hd-host".into()).spawn(hyperdownload::refresh_host_if_stale);
+ }
// DirectLook ayrı süreç: önceden başlatılır ki ilk Boşluk beklemesin (testlerde değil)
if cx.global::<settings::Settings>().directlook_enabled && std::env::var_os("RUSTYFILES_MULTI_INSTANCE").is_none() && !bar_preview {
look::ipc::send(look::ipc::Msg::Wake, true);