From 9bc8679fb7fb3748b5704e81366773efc5259a60 Mon Sep 17 00:00:00 2001 From: litruv Date: Sun, 1 Nov 2026 11:44:17 +1100 Subject: [PATCH] Replace the native confirm and alert with an in-app dialog. [skip build] --- src/app/components/DialogHost.tsx | 49 ++++++++++++++++++++ src/app/pages/App.tsx | 3 +- src/app/pages/client/ClientNonUIFeatures.tsx | 2 + src/app/state/dialog.ts | 19 ++++++++ src/app/utils/backgroundSync.ts | 8 ++-- src/client/initMatrix.ts | 24 +++++----- 6 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 src/app/components/DialogHost.tsx create mode 100644 src/app/state/dialog.ts diff --git a/src/app/components/DialogHost.tsx b/src/app/components/DialogHost.tsx new file mode 100644 index 00000000..0120f9fb --- /dev/null +++ b/src/app/components/DialogHost.tsx @@ -0,0 +1,49 @@ +import FocusTrap from 'focus-trap-react'; +import { useAtom } from 'jotai'; +import { Box, Button, Dialog, Overlay, OverlayBackdrop, OverlayCenter, config, Text } from 'folds'; +import { dialogAtom } from '../state/dialog'; +import { stopPropagation } from '../utils/keyboard'; + +export function DialogHost() { + const [dialog, setDialog] = useAtom(dialogAtom); + + if (!dialog) return null; + + const close = (answer: boolean) => { + setDialog(null); + dialog.resolve(answer); + }; + + return ( + }> + + close(false), + clickOutsideDeactivates: true, + escapeDeactivates: stopPropagation, + }} + > + + + + {dialog.message} + + + {dialog.confirm && ( + + )} + + + + + + + + ); +} diff --git a/src/app/pages/App.tsx b/src/app/pages/App.tsx index e920a991..aa60ede6 100644 --- a/src/app/pages/App.tsx +++ b/src/app/pages/App.tsx @@ -4,6 +4,7 @@ import { OverlayContainerProvider, PopOutContainerProvider, TooltipContainerProv import { RouterProvider } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { dialogStore } from '../state/dialog'; import { ClientConfigLoader } from '../components/ClientConfigLoader'; import { ClientConfigProvider } from '../hooks/useClientConfig'; import { ConfigConfigError, ConfigConfigLoading } from './ConfigConfig'; @@ -35,7 +36,7 @@ function App() { {(clientConfig) => ( - + diff --git a/src/app/pages/client/ClientNonUIFeatures.tsx b/src/app/pages/client/ClientNonUIFeatures.tsx index c2d78804..7bb9002e 100644 --- a/src/app/pages/client/ClientNonUIFeatures.tsx +++ b/src/app/pages/client/ClientNonUIFeatures.tsx @@ -61,6 +61,7 @@ import { materializeSharedFile, } from '../../utils/androidShare'; import { UpdatesDialogHost } from '../../components/updates-dialog'; +import { DialogHost } from '../../components/DialogHost'; /** * Applies the selected emoji style font to the document. @@ -701,6 +702,7 @@ export function ClientNonUIFeatures({ children }: ClientNonUIFeaturesProps) { {children} + ); } diff --git a/src/app/state/dialog.ts b/src/app/state/dialog.ts new file mode 100644 index 00000000..57afd09f --- /dev/null +++ b/src/app/state/dialog.ts @@ -0,0 +1,19 @@ +import { atom, createStore } from 'jotai'; + +export type Dialog = { + message: string; + // Confirm needs an affirmative answer; information-only dialogs just close. + confirm: boolean; + resolve: (answer: boolean) => void; +}; + +// Non-React callers (client init, background sync) must write the store the app renders +// with, so App.tsx passes this one to JotaiProvider. +export const dialogStore = createStore(); + +export const dialogAtom = atom(null); + +export const promptDialog = (message: string, confirm = false): Promise => + new Promise((resolve) => { + dialogStore.set(dialogAtom, { message, confirm, resolve }); + }); diff --git a/src/app/utils/backgroundSync.ts b/src/app/utils/backgroundSync.ts index 30a05c1f..829f505a 100644 --- a/src/app/utils/backgroundSync.ts +++ b/src/app/utils/backgroundSync.ts @@ -1,5 +1,6 @@ import type { PluginListenerHandle } from '@capacitor/core'; import type { IPusherRequest, MatrixClient } from 'matrix-js-sdk'; +import { promptDialog } from '../state/dialog'; const CAPACITOR_CORE_MODULE_ID = '@capacitor/core'; @@ -366,14 +367,11 @@ class AndroidUnifiedPushManager { if (typeof window === 'undefined') return; - try { - const openDocs = window.confirm(`${message}\n\nOpen distributor list now?`); + promptDialog(`${message}\n\nOpen distributor list now?`, true).then((openDocs) => { if (openDocs) { window.open(docsUrl, '_blank', 'noopener,noreferrer'); } - } catch { - window.alert(message); - } + }); } /** Install plugin listeners once for the active Matrix client. */ diff --git a/src/client/initMatrix.ts b/src/client/initMatrix.ts index d9461c6d..4ead03e5 100644 --- a/src/client/initMatrix.ts +++ b/src/client/initMatrix.ts @@ -5,6 +5,7 @@ import { clearNavToActivePathStore } from '../app/state/navToActivePath'; import { Session, getSessionStoreName } from '../app/state/sessions'; import { getSettings } from '../app/state/settings'; import { recordPacket } from '../app/state/debugPackets'; +import { promptDialog } from '../app/state/dialog'; const MAX_BODY = 8192; @@ -242,17 +243,18 @@ const setupKeyConflictHandler = (mx: MatrixClient, session: Session): void => { // Notify user and reload setTimeout(() => { - if ( - confirm( - 'Detected encryption key conflict. The app needs to reset your encryption session. You may need to re-verify your devices after this. Continue?', - ) - ) { - deleteRustCryptoDatabase(session).then(() => { - window.location.reload(); - }); - } else { - handlingKeyConflict = false; - } + promptDialog( + 'Detected encryption key conflict. The app needs to reset your encryption session. You may need to re-verify your devices after this. Continue?', + true, + ).then((continueFix) => { + if (continueFix) { + deleteRustCryptoDatabase(session).then(() => { + window.location.reload(); + }); + } else { + handlingKeyConflict = false; + } + }); }, 100); } }