From 0a6503c1a4878caacc7945701bc3d65ec8830b02 Mon Sep 17 00:00:00 2001 From: lunar-seal Date: Fri, 24 Jul 2026 22:18:23 +0200 Subject: [PATCH] fix: open external links on android in system browser --- .changeset/fix-homeserver-external-link.md | 5 ----- .changeset/fix-tauri-external-link.md | 5 +++++ src-tauri/src/lib.rs | 24 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) delete mode 100644 .changeset/fix-homeserver-external-link.md create mode 100644 .changeset/fix-tauri-external-link.md diff --git a/.changeset/fix-homeserver-external-link.md b/.changeset/fix-homeserver-external-link.md deleted file mode 100644 index 9dca15968..000000000 --- a/.changeset/fix-homeserver-external-link.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -default: patch ---- - -tauri: use external browser to follow homeserver url in profile chip \ No newline at end of file diff --git a/.changeset/fix-tauri-external-link.md b/.changeset/fix-tauri-external-link.md new file mode 100644 index 000000000..4d2297a7d --- /dev/null +++ b/.changeset/fix-tauri-external-link.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +tauri: make sure external links open in separate browser, instead of replacing the app \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 527663833..048a1924c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -141,6 +141,30 @@ pub fn show_or_create_main_window(app: &AppHandle) -> taur .use_https_scheme(true) .background_color(tauri::window::Color(0x1A, 0x1C, 0x28, 0xFF)); + // Only android: intercept navigation to external URLs and open them in the system browser + // Other platforms: might need other URI schemes, and on_navigation might get called on iframe urls + // (as of now, the following is confirmed not to work with linux/webkit2gtk) + #[cfg(target_os = "android")] + let builder = { + let nav_handle = app.clone(); + builder.on_navigation(move |url| { + let internal = url.scheme() == "tauri" + || url.host_str() == Some("tauri.localhost") + || (cfg!(dev) && url.host_str() == Some("localhost")); + if !internal { + // open in new thread + // open_url blocks on the ui thread but we are on the ui thread... + let handle = nav_handle.clone(); + let url = url.to_string(); + std::thread::spawn(move || { + use tauri_plugin_opener::OpenerExt; + let _ = handle.opener().open_url(url, None::<&str>); + }); + } + internal + }) + }; + #[cfg(desktop)] let title = main_window_title(app);