From 88c571abfbd4f4653e8979953fa3687c0d834e66 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:32:03 +0400 Subject: [PATCH 1/2] fix(desktop): forward Windows second-instance auth URLs to webview --- src-tauri/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3762a71..8535b26 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,4 @@ -use tauri::{Manager, WebviewUrl, WebviewWindowBuilder}; +use tauri::{Emitter, Manager, WebviewUrl, WebviewWindowBuilder}; // OS credential-store identifier. Keys are whitelisted to a narrow pattern // so the webview can only ever read/write its own desktop-auth entries — @@ -99,7 +99,18 @@ pub fn run() { // deep-link plugin forwards the URL to it. let _ = app.handle() - .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { + .plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| { + // Windows may deliver the protocol URL as a second-instance + // argv rather than through the webview deep-link listener. + // Forward only our exact auth scheme; the JS flow+PKCE + // binding still validates the handoff before redemption. + for arg in &argv { + if let Ok(url) = tauri::Url::parse(arg) { + if url.scheme() == "dev-ledger" && url.host_str() == Some("auth") { + let _ = app.emit("desktop-auth-activation", arg.clone()); + } + } + } if let Some(w) = app.get_webview_window("main") { let _ = w.unminimize(); let _ = w.set_focus(); From ba53bd52b78757c67d0306f103ced57300337603 Mon Sep 17 00:00:00 2001 From: aliferous3 <94698925+Aliferous3@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:32:12 +0400 Subject: [PATCH 2/2] fix(desktop): listen for native Windows activation and dedupe handoff exchange --- src/desktop/auth.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/desktop/auth.ts b/src/desktop/auth.ts index 1f7e5f0..050374e 100644 --- a/src/desktop/auth.ts +++ b/src/desktop/auth.ts @@ -19,6 +19,7 @@ import { openUrl } from '@tauri-apps/plugin-opener'; import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link'; import { invoke } from '@tauri-apps/api/core'; +import { listen } from '@tauri-apps/api/event'; import { API_BASE, DESKTOP_SCHEME } from './runtime'; import { clearToken, loadToken, storeToken } from './keys'; @@ -31,6 +32,7 @@ import { clearToken, loadToken, storeToken } from './keys'; let pendingFlow: string | null = null; let pendingVerifier: string | null = null; let pendingRemember = false; +let exchangeInFlight = false; let noticeHandler: ((msg: string | null) => void) | null = null; export function onDesktopAuthNotice(cb: (msg: string | null) => void): () => void { @@ -96,6 +98,10 @@ async function handleAuthUrl(url: string): Promise { if (!pendingFlow || flow !== pendingFlow || !code || !pendingVerifier) { return; } + // The same URL may arrive through both the deep-link plugin and the + // Windows second-instance event. Redeem it at most once. + if (exchangeInFlight) return; + exchangeInFlight = true; const verifier = pendingVerifier; const remember = pendingRemember; pendingFlow = null; @@ -126,6 +132,8 @@ async function handleAuthUrl(url: string): Promise { window.location.reload(); } catch { notice('The Dev Ledger service is unreachable — sign-in could not finish.'); + } finally { + exchangeInFlight = false; } } @@ -136,6 +144,11 @@ async function handleAuthUrl(url: string): Promise { // registered. export async function initDesktopAuth(): Promise { await loadToken(); + await listen('desktop-auth-activation', (event) => { + if (typeof event.payload === 'string' && isAuthDeepLink(event.payload)) { + void handleAuthUrl(event.payload); + } + }).catch(() => {}); await onOpenUrl((urls) => { for (const u of urls) { if (isAuthDeepLink(u)) void handleAuthUrl(u);