Repository navigation
fix(app): open links in terminal output through the opener plugin - #41
Conversation
WebLinksAddon's default handler does window.open inside the webview, where a Tauri app has no browser to fall back on. Pass a handler that routes http(s) links through @tauri-apps/plugin-opener like the About page does, and ignore other schemes so printed output cannot navigate the webview. Fixes emberterm#39
arifintahu
left a comment
There was a problem hiding this comment.
Requested changes
Thanks for the fix. The approach is right: routing http(s) links through the opener plugin and dropping other schemes. I also checked it on a dev build (pnpm dev). Ctrl-clicking https://example.com in the terminal opened it in the system browser, so the checkbox in your test plan is covered. One change is needed before merge.
1. Surface openUrl failures (required)
In packages/app/src/terminal/links.ts, openUrl(uri).catch(console.error) swallows the error. If the opener rejects (scope denies the URL, no default browser, IPC error), Ctrl-click does nothing and the user sees nothing. CLAUDE.md says: "Catch IPC errors and expose them as component state — never silently swallow."
Please show a toast on failure using the existing toast updater in stores/app.ts. Please also add a Vitest case where openUrl rejects and the toast is raised.
2. Optional, can be a follow-up
- Parse the URI with
new URL(uri)and checkprotocol, instead of the prefix regex. A barehttps://currently passes the check. - Move
import { openExternalLink } from "./links.js"inGrid.sveltenext to the other local imports, away from the xterm addon imports.
|
Done in 94969b3:
|
arifintahu
left a comment
There was a problem hiding this comment.
Approved. The earlier requests are fixed: openUrl failures now raise a toast, there is a Vitest case for the rejection path, the scheme check parses with new URL and allows only http(s), and the import order is fixed. On the PR head, Vitest passes (152 tests) and svelte-check reports 0 errors. Minor, not blocking: the toast shows the full URL, so a very long link gives a long toast.
|
Thanks for the fixes. Merging now. |
Problem
Ctrl-clicking a URL in the terminal output goes through xterm's
WebLinksAddondefault handler, i.e.window.openinside the Tauri webview, instead of the system browser. Fixes #39. The app already opens external links through@tauri-apps/plugin-opener(seesettings/AboutSettings.svelte).Root cause
packages/app/src/terminal/Grid.svelteloadednew WebLinksAddon()with no handler, so the addon fell back to its built-inwindow.open. Theopener:defaultpermission is already granted inpackages/desktop/capabilities/default.json; only the wiring was missing.Fix
Add
packages/app/src/terminal/links.tswithopenExternalLink(event, uri), which forwardshttp(s)URLs toopenUrlfrom@tauri-apps/plugin-opener(case-insensitive on the scheme) and ignores every other scheme, then pass it as theWebLinksAddonhandler inGrid.svelte. Other schemes are dropped rather than falling back towindow.open, so printed terminal output cannot triggerfile://or other webview-navigating schemes. CHANGELOG updated under[Unreleased].Testing
packages/app/src/terminal/links.test.ts(Vitest, 3 tests: http/https forwarded toopenUrl, case-insensitive scheme, non-http(s) schemes ignored). It failed before the fix (module missing) and passes after.pnpm exec vitest runinpackages/app: 22 files / 151 tests pass.svelte-checkinpackages/app: 0 errors (9 pre-existing warnings inProfileEditor.svelte, untouched by this change).vite buildfor@emberterm/uiand@emberterm/app: success.cargo fmt/clippy/test) were not run: no Rust toolchain on this machine and the change touches no Rust file; CI will cover them.