fix: (tauri) open homeserver-url in user chip via opener plugin (#1277)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

on android/tauri: opening the homeserver url in the user chip replaces
sable.
fix: use the opener-plugin to follow the url, as in verification.tsx
https://github.com/SableClient/Sable/blob/444f2fc9c59900fb39ae621bc4badf75b9b0df78/src/app/features/settings/devices/Verification.tsx#L275-L285

on android: clicking in a youtube embed e.g. the video title replaces
the entire app with youtube
fix: on android specifically, make urls that do not lead to sable open
in the system browser
this doesn't work on other platforms, but is not needed for at least the
linux/cef version

Fixes #1295

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
7w1 authored and GitHub committed 2026-07-24 22:09:48 +00:00
commit aff701889b
3 files changed
+38 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
default: patch
---
tauri: make sure external links open in separate browser, instead of replacing the app
+24
View File
@@ -156,6 +156,30 @@ pub fn show_or_create_main_window(app: &AppHandle<crate::BrowserEngine>) -> 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);
@@ -2,6 +2,7 @@ import type { KeyboardEventHandler, MouseEventHandler } from 'react';
import type { CSSProperties } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { isTauri } from '@tauri-apps/api/core';
import FocusTrap from 'focus-trap-react';
import { isKeyHotkey } from 'is-hotkey';
import type { Room } from '$types/matrix-sdk';
@@ -173,8 +174,15 @@ export function ServerChip({
size="300"
radii="300"
onClick={() => {
window.open(`https://${server}`, '_blank');
const url = `https://${server}`;
close();
if (isTauri()) {
import('@tauri-apps/plugin-opener')
.then(({ openUrl }) => openUrl(url))
.catch(() => window.open(url, '_blank'));
return;
}
window.open(url, '_blank');
}}
className={css.UserHeroMenuItem}
style={heroMenuItemStyle(