Replace the native confirm and alert with an in-app dialog. [skip build]
Checks / checks (push) Successful in 2m8s
Trigger cinny-mobile / dispatch (push) Successful in 2s

This commit is contained in:
2026-11-01 11:44:17 +11:00
parent 6805762834
commit 9bc8679fb7
6 changed files with 88 additions and 17 deletions
+49
View File
@@ -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 (
<Overlay open backdrop={<OverlayBackdrop />}>
<OverlayCenter>
<FocusTrap
focusTrapOptions={{
initialFocus: false,
onDeactivate: () => close(false),
clickOutsideDeactivates: true,
escapeDeactivates: stopPropagation,
}}
>
<Dialog variant="Surface">
<Box style={{ padding: config.space.S400 }} direction="Column" gap="400">
<Text priority="400" style={{ whiteSpace: 'pre-line' }}>
{dialog.message}
</Text>
<Box direction="Row" gap="200">
{dialog.confirm && (
<Button variant="Secondary" onClick={() => close(false)} radii="300">
<Text size="B300">Cancel</Text>
</Button>
)}
<Button variant="Primary" onClick={() => close(dialog.confirm)} radii="300">
<Text size="B300">{dialog.confirm ? 'Confirm' : 'OK'}</Text>
</Button>
</Box>
</Box>
</Dialog>
</FocusTrap>
</OverlayCenter>
</Overlay>
);
}
+2 -1
View File
@@ -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) => (
<ClientConfigProvider value={clientConfig}>
<QueryClientProvider client={queryClient}>
<JotaiProvider>
<JotaiProvider store={dialogStore}>
<RouterProvider router={createRouter(clientConfig, screenSize)} />
</JotaiProvider>
</QueryClientProvider>
@@ -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) {
<AndroidShareIntentHandler />
{children}
<UpdatesDialogHost />
<DialogHost />
</>
);
}
+19
View File
@@ -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<Dialog | null>(null);
export const promptDialog = (message: string, confirm = false): Promise<boolean> =>
new Promise((resolve) => {
dialogStore.set(dialogAtom, { message, confirm, resolve });
});
+3 -5
View File
@@ -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. */
+13 -11
View File
@@ -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);
}
}