feat(native): the UI knows when it runs inside the app

Everything the server's UI does differently inside the iOS and Android app
lives under src/native and is inert in a browser.

Sign-in: SSO and the passkey button go through the system browser
(signInThroughBrowser), because identity providers refuse embedded
browsers and WebAuthn needs a domain association no build can have for
every server. The browser end is the new /native-handoff page: it signs
the user in if needed and hands the session over only after an explicit
tap, so a link carrying somebody else's challenge cannot pass a session
on silently. The verifier is hashed with @noble/hashes because
crypto.subtle is missing on the plain-http servers many home networks
use. An OIDC-only install no longer bounces to the IdP inside the
WebView, and passkey management is hidden in the app.

Downloads: the WebView cannot save a blob, so downloadBlob, downloadFile
and openFile write to the app cache and open the share sheet. The eight
places that built their own download anchor now use downloadBlob, which
they should have anyway.

The rest: "Change server" on the login page and in the account settings,
the splash hides after the first frame, Android's back button walks
history before it leaves the app, the status bar follows the scheme, and
on iOS the start page is refreshed and every chunk of the build (listed
in the new asset-manifest.json) is pulled into WebKit's cache so the app
can start without network.
This commit is contained in:
Maurice
2026-09-24 12:42:34 +02:00
parent c5765bbf15
commit ae0d4e4520
37 changed files with 1153 additions and 88 deletions
@@ -598,7 +598,7 @@ describe('AccountTab – Backup codes', () => {
expect(createObjectURL).toHaveBeenCalledWith(expect.any(Blob));
expect(downloadName).toBe('trek-mfa-backup-codes.txt');
expect(revokeObjectURL).toHaveBeenCalledWith('blob:codes');
await waitFor(() => expect(revokeObjectURL).toHaveBeenCalledWith('blob:codes'));
expect(document.querySelector('a[download]')).toBeNull();
createObjectURL.mockRestore();
+9 -11
View File
@@ -10,6 +10,9 @@ import { getApiErrorMessage } from '../../types'
import type { UserWithOidc } from '../../types'
import Section from './Section'
import PasskeysSection from './PasskeysSection'
import NativeServerSection from './NativeServerSection'
import { isNativeApp } from '../../native/platform'
import { downloadBlob } from '../../utils/fileDownload'
const MFA_BACKUP_SESSION_KEY = 'trek_mfa_backup_codes_pending'
@@ -100,15 +103,7 @@ export default function AccountTab(): React.ReactElement {
const downloadBackupCodes = () => {
if (!backupCodesText) return
const blob = new Blob([backupCodesText + '\n'], { type: 'text/plain;charset=utf-8' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = 'trek-mfa-backup-codes.txt'
document.body.appendChild(a)
a.click()
a.remove()
URL.revokeObjectURL(url)
downloadBlob(new Blob([backupCodesText + '\n'], { type: 'text/plain;charset=utf-8' }), 'trek-mfa-backup-codes.txt')
}
const printBackupCodes = () => {
@@ -160,6 +155,7 @@ export default function AccountTab(): React.ReactElement {
return (
<>
<NativeServerSection />
<Section title={t('settings.account')} icon={User}>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1.5">{t('settings.username')}</label>
@@ -405,8 +401,10 @@ export default function AccountTab(): React.ReactElement {
</div>
</div>
{/* Passkeys */}
<PasskeysSection demoMode={demoMode} />
{/* Passkeys. Not in the app: WebAuthn in its WebView needs a domain
association no build can have for every server, so they are managed
in the browser (signing in with one works through it too). */}
{!isNativeApp() && <PasskeysSection demoMode={demoMode} />}
{/* Avatar */}
<div className="flex items-center gap-4">
@@ -0,0 +1,33 @@
// FE-SETTINGS-NATIVE-SERVER-001 to FE-SETTINGS-NATIVE-SERVER-004
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent } from '../../../tests/helpers/render'
import NativeServerSection from './NativeServerSection'
import MSettingsServer from '../../mobile/screens/settings/MSettingsServer'
import { nativeServerHost } from '../../native/platform'
import { TrekShell } from '../../native/trekShell'
vi.mock('../../native/platform', () => ({ nativeServerHost: vi.fn() }))
vi.mock('../../native/trekShell', () => ({ TrekShell: { resetServer: vi.fn() } }))
beforeEach(() => {
vi.mocked(TrekShell.resetServer).mockReset().mockResolvedValue()
})
describe.each([
['desktop', NativeServerSection],
['mobile', MSettingsServer],
])('the %s server section', (_shell, Section) => {
it('renders nothing in a browser', () => {
vi.mocked(nativeServerHost).mockReturnValue(null)
const { container } = render(<Section />)
expect(container).toBeEmptyDOMElement()
})
it('names the server and leads back to the address screen', () => {
vi.mocked(nativeServerHost).mockReturnValue('trek.example.com')
render(<Section />)
expect(screen.getByText('This app is connected to trek.example.com.')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Change server' }))
expect(TrekShell.resetServer).toHaveBeenCalled()
})
})
@@ -0,0 +1,25 @@
import React from 'react'
import { Server } from 'lucide-react'
import { useTranslation } from '../../i18n'
import { nativeServerHost } from '../../native/platform'
import { TrekShell } from '../../native/trekShell'
import Section from './Section'
/** Only inside the iOS/Android app: which server it talks to, and the way to another one. */
export default function NativeServerSection(): React.ReactElement | null {
const { t } = useTranslation()
const host = nativeServerHost()
if (!host) return null
return (
<Section title={t('native.settings.server')} icon={Server}>
<p className="text-body text-content-secondary">{t('native.settings.serverHint', { server: host })}</p>
<button
type="button"
onClick={() => { void TrekShell.resetServer() }}
className="rounded-lg border border-edge bg-surface-card px-4 py-2 text-body font-medium text-content hover:bg-surface-hover"
>
{t('native.changeServer')}
</button>
</Section>
)
}