From 108cad82d0767a70b71b1b10986832af890aa970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Andr=C3=A9?= Date: Fri, 20 Mar 2026 23:48:29 +0100 Subject: [PATCH] fix(tauri): restore external links in the folder picker (#225) ## Summary - restore the GitHub and Discord links on the folder picker in the Tauri app - open those links through the desktop opener bridge instead of relying on browser-only navigation behavior - include the capability/schema updates needed for the opener path ## Testing - npm run typecheck --workspace @codenomad/ui - cargo check --manifest-path packages/tauri-app/src-tauri/Cargo.toml --- .../src-tauri/capabilities/main-window.json | 1 + .../src-tauri/gen/schemas/capabilities.json | 2 +- .../src/components/folder-selection-view.tsx | 22 ++++++++---------- packages/ui/src/lib/external-url.ts | 23 +++++++++++++++++++ 4 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 packages/ui/src/lib/external-url.ts diff --git a/packages/tauri-app/src-tauri/capabilities/main-window.json b/packages/tauri-app/src-tauri/capabilities/main-window.json index 7480caa3..e32bfa28 100644 --- a/packages/tauri-app/src-tauri/capabilities/main-window.json +++ b/packages/tauri-app/src-tauri/capabilities/main-window.json @@ -11,6 +11,7 @@ "core:menu:default", "dialog:allow-open", "opener:allow-default-urls", + "opener:allow-open-url", "notification:allow-is-permission-granted", "notification:allow-request-permission", "notification:allow-notify", diff --git a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json index 7a9624eb..1e595706 100644 --- a/packages/tauri-app/src-tauri/gen/schemas/capabilities.json +++ b/packages/tauri-app/src-tauri/gen/schemas/capabilities.json @@ -1 +1 @@ -{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*","http://tauri.localhost/*","https://tauri.localhost/*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","core:webview:allow-set-webview-zoom"]}} \ No newline at end of file +{"main-window-native-dialogs":{"identifier":"main-window-native-dialogs","description":"Grant the main window access to required core features and native dialog commands.","remote":{"urls":["http://127.0.0.1:*","http://localhost:*","http://tauri.localhost/*","https://tauri.localhost/*"]},"local":true,"windows":["main"],"permissions":["core:default","core:menu:default","dialog:allow-open","opener:allow-default-urls","opener:allow-open-url","notification:allow-is-permission-granted","notification:allow-request-permission","notification:allow-notify","notification:allow-show","core:webview:allow-set-webview-zoom"]}} diff --git a/packages/ui/src/components/folder-selection-view.tsx b/packages/ui/src/components/folder-selection-view.tsx index ad833fed..e7e9cfa2 100644 --- a/packages/ui/src/components/folder-selection-view.tsx +++ b/packages/ui/src/components/folder-selection-view.tsx @@ -13,8 +13,11 @@ import { formatCompactCount } from "../lib/formatters" import { useI18n, type Locale } from "../lib/i18n" import { showAlertDialog } from "../stores/alerts" import { openSettings, settingsOpen } from "../stores/settings-screen" +import { openExternalUrl } from "../lib/external-url" const codeNomadLogo = new URL("../images/CodeNomad-Icon.png", import.meta.url).href +const GITHUB_URL = "https://github.com/NeuralNomadsAI/CodeNomad" +const DISCORD_URL = "https://discord.com/channels/1391832426048651334/1458412028325793887/1464701235683917945" interface FolderSelectionViewProps { @@ -232,11 +235,6 @@ const FolderSelectionView: Component = (props) => { props.onSelectFolder(path, selectedBinary()) } - const openExternalLink = (url: string) => { - if (typeof window === "undefined") return - window.open(url, "_blank", "noopener,noreferrer") - } - async function handleBrowse() { if (isLoading()) return setFocusMode("new") @@ -425,7 +423,7 @@ const FolderSelectionView: Component = (props) => {

CodeNomad

= (props) => { title={t("folderSelection.links.github")} onClick={(event) => { event.preventDefault() - openExternalLink("https://github.com/NeuralNomadsAI/CodeNomad") + void openExternalUrl(GITHUB_URL, "folder-selection") }} > = (props) => { title={t("folderSelection.links.githubStars")} onClick={(event) => { event.preventDefault() - openExternalLink("https://github.com/NeuralNomadsAI/CodeNomad") + void openExternalUrl(GITHUB_URL, "folder-selection") }} > @@ -456,7 +454,7 @@ const FolderSelectionView: Component = (props) => { = (props) => { title={t("folderSelection.links.discord")} onClick={(event) => { event.preventDefault() - openExternalLink( - "https://discord.com/channels/1391832426048651334/1458412028325793887/1464701235683917945", - ) + void openExternalUrl(DISCORD_URL, "folder-selection") }} > diff --git a/packages/ui/src/lib/external-url.ts b/packages/ui/src/lib/external-url.ts new file mode 100644 index 00000000..b0e7ca8b --- /dev/null +++ b/packages/ui/src/lib/external-url.ts @@ -0,0 +1,23 @@ +import { isTauriHost } from "./runtime-env" + +export async function openExternalUrl(url: string, context = "ui"): Promise { + if (typeof window === "undefined") { + return + } + + if (isTauriHost()) { + try { + const { openUrl } = await import("@tauri-apps/plugin-opener") + await openUrl(url) + return + } catch (error) { + console.warn(`[${context}] unable to open via system opener`, error) + } + } + + try { + window.open(url, "_blank", "noopener,noreferrer") + } catch (error) { + console.warn(`[${context}] unable to open external url`, error) + } +}