Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#642: open Help/About links in the system browser on the desktop

vangel76b24225afd378
diff --git a/Cargo.lock b/Cargo.lock
index d94a44573..6e6f3fb0a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1685,6 +1685,7 @@ dependencies = [
"objc2 0.6.4",
"objc2-app-kit 0.3.2",
"objc2-foundation 0.3.2",
+ "open",
"rfd",
"serde_json",
"sys-locale",
@@ -3231,6 +3232,25 @@ dependencies = [
"generic-array",
]
+[[package]]
+name = "is-docker"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "is-wsl"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
+dependencies = [
+ "is-docker",
+ "once_cell",
+]
+
[[package]]
name = "itertools"
version = "0.15.0"
@@ -4156,6 +4176,16 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
+[[package]]
+name = "open"
+version = "5.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa576c76302b7b808eecc68061e67336c47833ef9d22caa74dda10fa9675eebc"
+dependencies = [
+ "is-wsl",
+ "libc",
+]
+
[[package]]
name = "openssl-probe"
version = "0.2.1"
diff --git a/apps/filmcraft/Cargo.toml b/apps/filmcraft/Cargo.toml
index cf1cfff55..ee774c861 100644
--- a/apps/filmcraft/Cargo.toml
+++ b/apps/filmcraft/Cargo.toml
@@ -34,6 +34,8 @@ rfd = { workspace = true }
cpal = "0.16"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
sys-locale = "0.3"
+# Help menu / About / Discord links in the system browser (MIT; as PhotoCraft).
+open = "5"
[dev-dependencies]
glob = "0.3"
diff --git a/apps/filmcraft/src/main.rs b/apps/filmcraft/src/main.rs
index 8e9668d6d..96a12a786 100644
--- a/apps/filmcraft/src/main.rs
+++ b/apps/filmcraft/src/main.rs
@@ -237,6 +237,10 @@ fn main() -> eframe::Result {
app.hooks.pick_folder_at =
Some(Box::new(|dir: &str| rfd::FileDialog::new().set_directory(dir).pick_folder().map(|p| p.to_string_lossy().into_owned())));
app.hooks.open_path = Some(Box::new(open_path));
+ // Help menu, About and Discord links (#642): eframe is built without its `links`
+ // feature, so `ctx.open_url` does nothing on the desktop. Detached, so a launcher
+ // that waits for the browser never freezes the UI.
+ app.hooks.open_url = Some(Box::new(|url: &str| open::that_detached(url).map_err(|e| e.to_string())));
// Settings ▸ General ▸ Interface Language ▸ System Language (#218).
app.hooks.cursor_screen_position = Some(Box::new(filmcraft_platform::cursor::cursor_screen_position));
app.hooks.system_languages = Some(Box::new(|| sys_locale::get_locales().collect()));
diff --git a/crates/ui-egui/src/header.rs b/crates/ui-egui/src/header.rs
index e3ccfda26..721e35cfa 100644
--- a/crates/ui-egui/src/header.rs
+++ b/crates/ui-egui/src/header.rs
@@ -147,7 +147,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
if resp.clicked() {
- crate::links::open(ui.ctx(), crate::links::DISCORD);
+ crate::links::open(app, ui.ctx(), crate::links::DISCORD);
}
}
let popup_id = egui::Id::new("workspaces-popup");
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 857f42a56..e5a9b1b8b 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -139,6 +139,10 @@ pub struct HostHooks {
/// Open a file in its default application, or (`true`) reveal it in the file manager (Edit ▸
/// Edit Original, Help ▸ Reveal Log Files).
pub open_path: Option<Box<dyn FnMut(&str, bool) -> Result<(), String>>>,
+ /// Open a URL in the system browser (Help menu links, About dialog, Discord button, Import
+ /// screen). Without it, or when it fails, links go through `egui::Context::open_url`, which
+ /// opens a new tab on the web (the native egui backend is built without its `links` feature).
+ pub open_url: Option<Box<dyn FnMut(&str) -> Result<(), String>>>,
/// The operating system's light or dark appearance when egui cannot report it (Linux desktops
/// whose Wayland compositor sends no theme to winit). Without it, or without an answer, Auto
/// uses `egui::Context::system_theme`.
diff --git a/crates/ui-egui/src/links.rs b/crates/ui-egui/src/links.rs
index 641463d52..6d980e6c8 100644
--- a/crates/ui-egui/src/links.rs
+++ b/crates/ui-egui/src/links.rs
@@ -31,8 +31,17 @@ pub fn url_for(command: &str) -> Option<&'static str> {
ALL.iter().find(|(id, _, _)| *id == command).map(|(_, _, u)| *u)
}
-/// Open `url` in the system browser (a new tab on the web).
-pub fn open(ctx: &egui::Context, url: &str) {
+/// Open `url` in the system browser (a new tab on the web). The desktop host's
+/// [`HostHooks::open_url`](crate::HostHooks::open_url) opens it; without the hook, or when it
+/// fails, it goes through `ctx.open_url`, which only does something on the web: the native egui
+/// backend is built without its `links` feature, so there it would only log (#642).
+pub fn open(app: &mut crate::FilmcraftApp, ctx: &egui::Context, url: &str) {
+ if let Some(f) = app.hooks.open_url.as_mut() {
+ match f(url) {
+ Ok(()) => return,
+ Err(e) => log::warn!("can't open {url} in the browser: {e}"),
+ }
+ }
ctx.open_url(egui::OpenUrl::new_tab(url));
}
@@ -48,4 +57,35 @@ mod tests {
assert_eq!(url_for("help.discord"), Some(DISCORD));
assert_eq!(url_for("help.nope"), None);
}
+
+ #[test]
+ fn links_open_through_the_host_hook() {
+ // #642: on the desktop every link (Help menu, About, Discord button, Import screen) must
+ // reach the host's browser opener; `ctx.open_url` alone is a no-op natively.
+ use std::cell::RefCell;
+ use std::rc::Rc;
+ let opened: Rc<RefCell<Vec<String>>> = Rc::default();
+ let rec = opened.clone();
+ let mut app = crate::FilmcraftApp::new(filmcraft_engine::Session::default());
+ app.hooks.open_url = Some(Box::new(move |u: &str| {
+ rec.borrow_mut().push(u.to_string());
+ Ok(())
+ }));
+ let ctx = egui::Context::default();
+ for (id, _, url) in ALL {
+ let r = crate::menus::invoke(&mut app, &ctx, id, serde_json::json!({})).unwrap();
+ assert_eq!(r["url"], url, "{id}");
+ assert_eq!(opened.borrow().last().map(String::as_str), Some(url), "{id}");
+ }
+ open(&mut app, &ctx, DISCORD);
+ assert_eq!(opened.borrow().last().map(String::as_str), Some(DISCORD));
+ assert_eq!(opened.borrow().len(), ALL.len() + 1);
+
+ // A failing opener falls back to `ctx.open_url` instead of losing the click.
+ app.hooks.open_url = Some(Box::new(|_: &str| Err("no browser".into())));
+ open(&mut app, &ctx, ISSUES);
+ let fallback: Vec<String> =
+ ctx.output(|o| o.commands.iter().filter_map(|c| if let egui::OutputCommand::OpenUrl(u) = c { Some(u.url.clone()) } else { None }).collect());
+ assert_eq!(fallback, [ISSUES]);
+ }
}
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 9dff12d38..82b25306e 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -404,7 +404,7 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, mut params:
}
id if crate::links::url_for(id).is_some() => {
let url = crate::links::url_for(id).unwrap_or_default();
- crate::links::open(ctx, url);
+ crate::links::open(app, ctx, url);
app.ui.status = tlf!("Opened {url}", url);
return Ok(json!({"url": url}));
}
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index eed8fd28f..38d2af0ec 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -471,7 +471,7 @@ fn about_tab(app: &mut FilmcraftApp, ui: &mut egui::Ui) {
fg,
);
if resp.clicked() {
- links::open(ui.ctx(), url);
+ links::open(app, ui.ctx(), url);
}
};
link(ui, "discord", Icon::Chat, tl!("Join the ArtCraft Discord"), links::DISCORD, true);
diff --git a/crates/ui-egui/src/panels/import_mode.rs b/crates/ui-egui/src/panels/import_mode.rs
index 5d78e93e6..ef68c0aab 100644
--- a/crates/ui-egui/src/panels/import_mode.rs
+++ b/crates/ui-egui/src/panels/import_mode.rs
@@ -67,7 +67,7 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
crate::icons::paint(ui.painter(), Rect::from_center_size(pos2(r.min.x + 20.0, r.center().y), vec2(16.0, 16.0)), icon, fg);
ui.painter().galley(pos2(r.min.x + 34.0, r.center().y - g.size().y / 2.0), g, fg);
if resp.clicked() {
- crate::links::open(&ctx, url);
+ crate::links::open(app, &ctx, url);
}
x = r.max.x + 12.0;
}
diff --git a/crates/ui-egui/src/panels/keyboard.rs b/crates/ui-egui/src/panels/keyboard.rs
index 674769d6f..dfc960aad 100644
--- a/crates/ui-egui/src/panels/keyboard.rs
+++ b/crates/ui-egui/src/panels/keyboard.rs
@@ -210,7 +210,7 @@ pub fn route(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, params: &Val
}
"graphics.beginTextEditing" => begin_text_editing(app),
"help.filmcraftHelp" => {
- crate::links::open(ctx, HELP_URL);
+ crate::links::open(app, ctx, HELP_URL);
Ok(json!({"url": HELP_URL}))
}
"app.quit" => {
diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs
index 41395d861..fd2d7b8dd 100644
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@ -739,7 +739,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) -> bool {
ui.horizontal(|ui| {
ui.add_space(20.0);
if button(app, ui, "settings.help", tl!("Help"), false) {
- crate::links::open(ctx, &format!("{}/blob/main/docs/project-files.md#settings", crate::links::GITHUB));
+ crate::links::open(app, ctx, &format!("{}/blob/main/docs/project-files.md#settings", crate::links::GITHUB));
}
if button(app, ui, "settings.reset", tl!("Reset…"), false) {
// this category back to its defaults (OK applies it)