From e62b160d5d1ae91d05b1e5808fb28bd4f7669297 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Wed, 8 Apr 2026 08:55:02 -0600 Subject: [PATCH] feat(login): add cancel buttons and captcha hint to OAuth flows WebView OAuth: cancel button appears during loading, captcha hint shows after 25s or when user closes WebView. Hint suggests trying system browser instead with one-click action. System browser OAuth: cancel link appears next to loading text, immediately aborts the wait. i18n: new keys captchaHint and trySystemBrowser in all 5 locales. cc --- src/lib/components/views/LoginView.svelte | 94 ++++++++++++++++++++++- src/lib/i18n/locales/de.json | 2 + src/lib/i18n/locales/en.json | 2 + src/lib/i18n/locales/es.json | 2 + src/lib/i18n/locales/fr.json | 2 + src/lib/i18n/locales/pt.json | 2 + 6 files changed, 102 insertions(+), 2 deletions(-) diff --git a/src/lib/components/views/LoginView.svelte b/src/lib/components/views/LoginView.svelte index 80c88b1b1..3675ce937 100644 --- a/src/lib/components/views/LoginView.svelte +++ b/src/lib/components/views/LoginView.svelte @@ -21,6 +21,8 @@ let isOAuthLoading = $state(false); let isSystemBrowserLoading = $state(false); + let showCaptchaHint = $state(false); + let captchaHintTimerId: ReturnType | null = null; let isInitializing = $state(true); let initStatus = $state('Connecting to Qobuz™...'); let error = $state(null); @@ -55,11 +57,12 @@ $effect(() => { initializeClient(); return () => { - // Cleanup timeout on unmount + // Cleanup timeouts on unmount if (timeoutId) { clearTimeout(timeoutId); timeoutId = null; } + clearCaptchaHintTimer(); }; }); @@ -217,12 +220,39 @@ error = $t('auth.v2NotInitialized'); } else if (response.error_code === 'oauth_cancelled') { error = null; + showCaptchaHint = true; } else { error = response.error || 'Login failed'; } return false; } + function clearCaptchaHintTimer() { + if (captchaHintTimerId) { + clearTimeout(captchaHintTimerId); + captchaHintTimerId = null; + } + } + + async function handleCancelOAuthLogin() { + clearCaptchaHintTimer(); + try { + await invoke('v2_cancel_oauth_login'); + } catch { /* best effort */ } + } + + async function handleCancelSystemBrowserLogin() { + try { + await invoke('v2_cancel_system_browser_oauth'); + } catch { /* best effort */ } + } + + async function handleCancelAndTrySystemBrowser() { + showCaptchaHint = false; + await handleCancelOAuthLogin(); + handleSystemBrowserLogin(); + } + async function handleOAuthLogin() { if (!get(qobuzTosAccepted)) { error = $t('legal.tosRequiredToLogin'); @@ -231,11 +261,20 @@ isOAuthLoading = true; error = null; + showCaptchaHint = false; try { await setTosAcceptance(true); } catch { /* continue */ } + // Start captcha hint timer (25s) + clearCaptchaHintTimer(); + captchaHintTimerId = setTimeout(() => { + if (isOAuthLoading) { + showCaptchaHint = true; + } + }, 25000); + try { const response = await invoke('v2_start_oauth_login'); console.log('[LoginView] v2_start_oauth_login: success =', response.success); @@ -245,6 +284,7 @@ error = formatErrorMessage(err); } finally { isOAuthLoading = false; + clearCaptchaHintTimer(); } } @@ -341,9 +381,34 @@ {/if} + {#if isOAuthLoading} + + {/if} + + {#if showCaptchaHint} +
+

{$t('auth.captchaHint')}

+ +
+ {/if} +