A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): offer other accounts when an instance is down at start
Hampus1bd38db5070d
diff --git a/fluxer_app/src/app/BootstrapErrorMount.tsx b/fluxer_app/src/app/BootstrapErrorMount.tsxindex de00b8cb5..a48482b31 100644--- a/fluxer_app/src/app/BootstrapErrorMount.tsx+++ b/fluxer_app/src/app/BootstrapErrorMount.tsx@@ -1,7 +1,8 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport {ensureActiveLocale, initI18n} from '@app/app/I18n';-import {BootstrapErrorScreen} from '@app/features/app/components/BootstrapErrorScreen';+import {BootstrapErrorKind, classifyBootstrapError} from '@app/features/app/components/BootstrapErrorKind';+import {type BootstrapAccounts, BootstrapErrorScreen} from '@app/features/app/components/BootstrapErrorScreen';import {AppI18nProvider} from '@app/features/i18n/components/AppI18nProvider';import {Logger} from '@app/features/platform/utils/AppLogger';import {i18n} from '@lingui/core';@@ -9,6 +10,24 @@ import ReactDOM from 'react-dom/client';const logger = new Logger('index');+async function loadBootstrapAccounts(): Promise<BootstrapAccounts | null> {+ try {+ const {default: SessionManager} = await import('@app/features/platform/state/AuthSession');+ const restoringAccountKey = SessionManager.restoringAccountKey;+ const accounts = SessionManager.accounts;+ return {+ restoring: accounts.find((account) => account.storageKey === restoringAccountKey) ?? null,+ others: accounts.filter(+ (account) => account.storageKey !== restoringAccountKey && account.isValid && account.instance !== undefined,+ ),+ restoreOnNextStart: (accountKey) => SessionManager.restoreAccountOnNextStart(accountKey),+ };+ } catch (error) {+ logger.warn('Failed to load the stored accounts for the bootstrap error screen:', error);+ return null;+ }+}+export async function reportBootstrapError(error: unknown): Promise<void> {const normalized = error instanceof Error ? error : new Error(String(error));logger.error('Failed to bootstrap app:', normalized);@@ -16,10 +35,14 @@ export async function reportBootstrapError(error: unknown): Promise<void> {if (!container) {throw new Error('Missing #root element');}+ const accounts =+ classifyBootstrapError(normalized, navigator.onLine) === BootstrapErrorKind.UNREACHABLE+ ? await loadBootstrapAccounts()+ : null;ensureActiveLocale();ReactDOM.createRoot(container).render(<AppI18nProvider i18n={i18n}>- <BootstrapErrorScreen error={normalized} data-flx="index.bootstrap-error-screen" />+ <BootstrapErrorScreen error={normalized} accounts={accounts} data-flx="index.bootstrap-error-screen" /></AppI18nProvider>,);globalThis.window?.electron?.notifyFirstContentPainted?.();diff --git a/fluxer_app/src/features/app/components/BootstrapErrorScreen.tsx b/fluxer_app/src/features/app/components/BootstrapErrorScreen.tsxindex 1ffc30467..ef7eed40a 100644--- a/fluxer_app/src/features/app/components/BootstrapErrorScreen.tsx+++ b/fluxer_app/src/features/app/components/BootstrapErrorScreen.tsx@@ -5,19 +5,35 @@ import styles from '@app/features/app/components/ErrorFallback.module.css';import {BLUESKY_PROVIDER_NAME, FLUXER_BLUESKY_HANDLE} from '@app/features/app/config/I18nDisplayConstants';import {resolveAppShellBranding} from '@app/features/app/state/AppShellBranding';import RuntimeConfig from '@app/features/app/state/RuntimeConfig';+import {+ ACCOUNT_DETAILS_UNAVAILABLE_DESCRIPTOR,+ getAccountDisplayLabels,+ resolveAccountInstanceLabel,+} from '@app/features/auth/AccountDisplayUtils';import {TRY_AGAIN_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import type {Account} from '@app/features/platform/state/AuthSession';import {ResetClientStateReason, resetClientState} from '@app/features/platform/state/ResetClientState';+import {Logger} from '@app/features/platform/utils/AppLogger';import {Button} from '@app/features/ui/button/Button';import {FluxerIcon} from '@app/features/ui/components/icons/FluxerIcon';import {ExternalUrls} from '@fluxer/constants/src/ExternalUrls';+import {MS_PER_SECOND} from '@fluxer/date_utils/src/DateConstants';import {Trans, useLingui} from '@lingui/react/macro';import type React from 'react';import {useCallback, useEffect, useState} from 'react';-const UNREACHABLE_RETRY_INTERVAL_MS = 30_000;+const UNREACHABLE_RETRY_INTERVAL_MS = 30 * MS_PER_SECOND;+const logger = new Logger('BootstrapErrorScreen');++export interface BootstrapAccounts {+ readonly restoring: Account | null;+ readonly others: ReadonlyArray<Account>;+ readonly restoreOnNextStart: (accountKey: string) => Promise<void>;+}interface BootstrapErrorScreenProps {error?: Error;+ accounts?: BootstrapAccounts | null;}function reloadApp(): void {@@ -28,7 +44,56 @@ function describeError(error: Error): string {return error.stack?.trim() || `${error.name}: ${error.message}`;}-export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error}) => {+function AccountChoices({accounts}: {accounts: BootstrapAccounts}) {+ const {i18n} = useLingui();+ const [pendingAccountKey, setPendingAccountKey] = useState<string | null>(null);+ const handleChoose = useCallback(+ (accountKey: string) => {+ setPendingAccountKey(accountKey);+ accounts.restoreOnNextStart(accountKey).then(reloadApp, (error: unknown) => {+ logger.error('Failed to choose another account on the bootstrap error screen:', error);+ setPendingAccountKey(null);+ });+ },+ [accounts],+ );+ return (+ <div className={styles.errorFallbackContent} data-flx="app.bootstrap-error-screen.account-choices">+ <h2 className={styles.errorFallbackSubtitle} data-flx="app.bootstrap-error-screen.account-choices-title">+ <Trans comment="Heading on the startup screen shown when the current account's instance cannot be reached. Lists the other signed-in accounts.">+ Use another account+ </Trans>+ </h2>+ <div className={styles.errorFallbackAccounts} data-flx="app.bootstrap-error-screen.account-choices-list">+ {accounts.others.map((account) => {+ const labels = getAccountDisplayLabels(account);+ const accountName = labels.available ? labels.tagLabel : i18n._(ACCOUNT_DETAILS_UNAVAILABLE_DESCRIPTOR);+ const instanceHost = resolveAccountInstanceLabel(account);+ return (+ <Button+ key={account.storageKey}+ variant="secondary"+ submitting={pendingAccountKey === account.storageKey}+ disabled={pendingAccountKey !== null}+ onClick={() => handleChoose(account.storageKey)}+ data-flx="app.bootstrap-error-screen.button.account-choice"+ >+ {instanceHost ? (+ <Trans comment="Button on the startup screen that restarts the app on another signed-in account. accountName is the account's display name and instanceHost the host of its instance, such as chat.example.com.">+ {accountName} on {instanceHost}+ </Trans>+ ) : (+ accountName+ )}+ </Button>+ );+ })}+ </div>+ </div>+ );+}++export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error, accounts = null}) => {const {i18n} = useLingui();const unreachable = classifyBootstrapError(error, navigator.onLine) === BootstrapErrorKind.UNREACHABLE;useEffect(() => {@@ -53,17 +118,38 @@ export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error}void import('@app/features/ui/commands/TextCopyCommands').then(({copy}) => copy(i18n, describeError(error), true))- .then(setCopied, () => setCopied(false));+ .then(setCopied, (copyError: unknown) => {+ logger.warn('Failed to load or run the bootstrap diagnostic copy action:', copyError);+ setCopied(false);+ });}, [error, i18n]);const handleReset = useCallback(() => {void resetClientState({reason: ResetClientStateReason.RESET_APP_DATA, keepDrafts: true}).finally(() =>window.location.reload(),);}, []);- const snapshot = RuntimeConfig.getSnapshotOrNull();- const productName = resolveAppShellBranding(snapshot).productName;+ const runtimeSnapshot = RuntimeConfig.getSnapshotOrNull();+ const storedInstance = accounts?.restoring?.instance ?? null;+ const productName = resolveAppShellBranding(runtimeSnapshot ?? storedInstance).productName;const statusPageUrl = RuntimeConfig.statusPageUrl;- const selfHosted = snapshot !== null && RuntimeConfig.isSelfHosted();+ const selfHosted =+ runtimeSnapshot !== null ? RuntimeConfig.isSelfHosted() : storedInstance?.features.self_hosted === true;+ const instanceHost = accounts?.restoring ? resolveAccountInstanceLabel(accounts.restoring) : null;+ const otherAccounts = unreachable && accounts !== null && accounts.others.length > 0 ? accounts : null;+ let description: React.ReactNode;+ if (unreachable && instanceHost) {+ description = (+ <Trans comment="Startup screen text when the current account's instance cannot be reached. instanceHost is its host, such as chat.example.com.">+ We couldn't reach {instanceHost}. Check your connection and try again.+ </Trans>+ );+ } else if (unreachable) {+ description = <Trans>Check your connection and try again.</Trans>;+ } else {+ description = (+ <Trans>{productName} failed to start properly. This could be due to corrupted data or a temporary issue.</Trans>+ );+ }return (<div className={styles.errorFallbackContainer} data-flx="app.bootstrap-error-screen.error-fallback-container"><FluxerIcon className={styles.errorFallbackIcon} data-flx="app.bootstrap-error-screen.error-fallback-icon" />@@ -72,13 +158,7 @@ export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error{unreachable ? <Trans>Can't connect</Trans> : <Trans>Failed to start</Trans>}</h1><p className={styles.errorFallbackDescription} data-flx="app.bootstrap-error-screen.error-fallback-description">- {unreachable ? (- <Trans>Check your connection and try again.</Trans>- ) : (- <Trans>- {productName} failed to start properly. This could be due to corrupted data or a temporary issue.- </Trans>- )}+ {description}</p>{error && !unreachable && (<p@@ -155,6 +235,9 @@ export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error</Button>)}</div>+ {otherAccounts ? (+ <AccountChoices accounts={otherAccounts} data-flx="app.bootstrap-error-screen.account-choices" />+ ) : null}</div>);};diff --git a/fluxer_app/src/features/app/components/ErrorFallback.module.css b/fluxer_app/src/features/app/components/ErrorFallback.module.cssindex 2c83cb135..f29e4f479 100644--- a/fluxer_app/src/features/app/components/ErrorFallback.module.css+++ b/fluxer_app/src/features/app/components/ErrorFallback.module.css@@ -30,6 +30,21 @@line-height: 2.25rem;}+.errorFallbackSubtitle {+ font-weight: 600;+ font-size: 1.125rem;+ line-height: 1.5rem;+}++.errorFallbackAccounts {+ display: flex;+ flex-direction: column;+ gap: var(--spacing-2);+ width: min(21rem, 100%);+ max-height: 40vh;+ overflow-y: auto;+}+.errorFallbackDescription {max-width: 21rem;color: var(--text-primary-muted);