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
This commit is contained in:
6 files changed
+102
-2
No files matched your search
@@ -21,6 +21,8 @@
|
||||
|
||||
let isOAuthLoading = $state(false);
|
||||
let isSystemBrowserLoading = $state(false);
|
||||
let showCaptchaHint = $state(false);
|
||||
let captchaHintTimerId: ReturnType<typeof setTimeout> | null = null;
|
||||
let isInitializing = $state(true);
|
||||
let initStatus = $state('Connecting to Qobuz™...');
|
||||
let error = $state<string | null>(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<OAuthResponse>('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}
|
||||
</button>
|
||||
|
||||
{#if isOAuthLoading}
|
||||
<p class="cancel-link">
|
||||
<small>
|
||||
<button type="button" class="link-button" onclick={handleCancelOAuthLogin}>
|
||||
{$t('actions.cancel')}
|
||||
</button>
|
||||
</small>
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if showCaptchaHint}
|
||||
<div class="captcha-hint">
|
||||
<p>{$t('auth.captchaHint')}</p>
|
||||
<button type="button" class="link-button captcha-hint-action" onclick={handleCancelAndTrySystemBrowser}>
|
||||
{$t('auth.trySystemBrowser')}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<p class="system-browser-link">
|
||||
{#if isSystemBrowserLoading}
|
||||
<small><span class="link-button">{$t('auth.systemBrowserLoading')}</span></small>
|
||||
<small>
|
||||
<span class="link-button">{$t('auth.systemBrowserLoading')}</span>
|
||||
|
||||
<button type="button" class="link-button" onclick={handleCancelSystemBrowserLogin}>
|
||||
{$t('actions.cancel')}
|
||||
</button>
|
||||
</small>
|
||||
{:else}
|
||||
<small>
|
||||
<button
|
||||
@@ -618,6 +683,31 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cancel-link {
|
||||
margin-top: -12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.captcha-hint {
|
||||
text-align: center;
|
||||
padding: 12px 16px;
|
||||
background-color: var(--warning-bg);
|
||||
border: 1px solid var(--warning-border);
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.captcha-hint p {
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.captcha-hint-action {
|
||||
font-weight: 500;
|
||||
color: var(--accent-primary) !important;
|
||||
}
|
||||
|
||||
.offline-link {
|
||||
margin-top: 4px;
|
||||
text-align: center;
|
||||
|
||||
@@ -1446,6 +1446,8 @@
|
||||
"oauthLoading": "Browser wird geöffnet...",
|
||||
"systemBrowserButton": "Stattdessen Systembrowser verwenden",
|
||||
"systemBrowserLoading": "Warte auf Anmeldung...",
|
||||
"captchaHint": "Probleme mit dem Captcha? Der eingebaute Browser unterstützt es möglicherweise nicht gut.",
|
||||
"trySystemBrowser": "Abbrechen und Systembrowser verwenden",
|
||||
"activeSubscriptionRequired": "QBZ erfordert ein aktives Qobuz™-Abonnement. Ihre Anmeldedaten werden direkt an Qobuz™ gesendet.",
|
||||
"APIUse": "Diese Anwendung verwendet die Qobuz-API, ist jedoch nicht von Qobuz zertifiziert."
|
||||
},
|
||||
|
||||
@@ -1469,6 +1469,8 @@
|
||||
"oauthLoading": "Opening browser...",
|
||||
"systemBrowserButton": "Use your system browser instead",
|
||||
"systemBrowserLoading": "Waiting for login...",
|
||||
"captchaHint": "Having trouble with captcha? The built-in browser may not support it well.",
|
||||
"trySystemBrowser": "Cancel and try your system browser instead",
|
||||
"activeSubscriptionRequired": "QBZ requires an active Qobuz™ subscription. Your credentials are sent directly to Qobuz™.",
|
||||
"APIUse": "This application uses the Qobuz API but is not certified by Qobuz."
|
||||
},
|
||||
|
||||
@@ -1469,6 +1469,8 @@
|
||||
"oauthLoading": "Abriendo navegador...",
|
||||
"systemBrowserButton": "Usar tu navegador del sistema",
|
||||
"systemBrowserLoading": "Esperando inicio de sesión...",
|
||||
"captchaHint": "¿Problemas con el captcha? El navegador integrado puede no soportarlo bien.",
|
||||
"trySystemBrowser": "Cancelar y usar tu navegador del sistema",
|
||||
"activeSubscriptionRequired": "QBZ requiere una suscripción activa a Qobuz™. Tus datos de acceso se envían directamente a Qobuz™.",
|
||||
"APIUse": "Esta aplicación utiliza la API de Qobuz, pero no está certificada por Qobuz."
|
||||
},
|
||||
|
||||
@@ -1446,6 +1446,8 @@
|
||||
"oauthLoading": "Ouverture du navigateur...",
|
||||
"systemBrowserButton": "Utiliser votre navigateur système",
|
||||
"systemBrowserLoading": "En attente de connexion...",
|
||||
"captchaHint": "Des difficultés avec le captcha ? Le navigateur intégré peut ne pas bien le gérer.",
|
||||
"trySystemBrowser": "Annuler et utiliser votre navigateur système",
|
||||
"activeSubscriptionRequired": "QBZ requiert un abonnement à Qobuz™ actif. Vos identifiants sont directement envoyés à Qobuz™.",
|
||||
"APIUse": "Cette application utilise l'API Qobuz™ mais n'est pas certifiée par Qobuz™."
|
||||
},
|
||||
|
||||
@@ -1469,6 +1469,8 @@
|
||||
"oauthLoading": "Abrindo navegador...",
|
||||
"systemBrowserButton": "Usar o navegador do sistema",
|
||||
"systemBrowserLoading": "Aguardando login...",
|
||||
"captchaHint": "Problemas com o captcha? O navegador integrado pode não suportá-lo bem.",
|
||||
"trySystemBrowser": "Cancelar e usar o navegador do sistema",
|
||||
"activeSubscriptionRequired": "O QBZ requer uma assinatura ativa do Qobuz™. Suas credenciais são enviadas diretamente ao Qobuz™.",
|
||||
"APIUse": "Este aplicativo utiliza a API do Qobuz, mas não é certificado pelo Qobuz."
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user