Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/app-frame.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('top navigation stays blocked and allow restores clipboard, camera, microph
})

test('desktop app iframes use the policy; pdf previews stay empty-sandboxed', () => {
const desk = readFileSync(new URL('../web/src/desktop/Desktop.tsx', import.meta.url), 'utf8')
const desk = readFileSync(new URL('../web/src/desktop/AppFrame.tsx', import.meta.url), 'utf8')
const files = readFileSync(new URL('../web/src/screens/Files.tsx', import.meta.url), 'utf8')
assert.equal(desk.match(/<InstalledAppFrame\b/g)?.length, 3)
assert.match(desk, /sandbox=\{sandbox\}/)
Expand Down
39 changes: 39 additions & 0 deletions test/bundle-split.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import assert from 'node:assert/strict'
import {readdirSync, readFileSync} from 'node:fs'
import {join, relative} from 'node:path'
import {test} from 'node:test'
import {fileURLToPath} from 'node:url'

// The phone layout never shows the desktop shell or the Files screen, so the first download should
// not carry them. Vite keeps a module in the main bundle if any module there imports it statically,
// even when App.tsx loads it lazily, so these tests look for such imports.
const SRC = fileURLToPath(new URL('../web/src/', import.meta.url))

function sources(dir) {
return readdirSync(dir, {withFileTypes: true}).flatMap((e) => {
const p = join(dir, e.name)
if (e.isDirectory()) return sources(p)
return /\.(ts|tsx)$/.test(e.name) ? [p] : []
})
}

// Static imports only: `import ... from 'x'`, not `import type`, not `import('x')`.
function staticImporters(target) {
const pattern = new RegExp(`^import (?!type )[^'"]*?from ['"][./]+(?:[\\w-]+/)*${target}['"]`, 'm')
return sources(SRC)
.filter((p) => pattern.test(readFileSync(p, 'utf8')))
.map((p) => relative(SRC, p))
.sort()
}

test('the desktop shell is loaded lazily, and screens reach its window API through desktop/context', () => {
const app = readFileSync(join(SRC, 'App.tsx'), 'utf8')
assert.ok(/const Desktop = lazy\(\(\) => import\('\.\/desktop\/Desktop'\)/.test(app), 'App.tsx loads Desktop with lazy()')
// Settings → Appearance (Personalize) is itself a lazy screen, so it may use the desktop's item list.
assert.deepEqual(staticImporters('Desktop'), ['desktop/Personalize.tsx'])
})

test('the Files screen is only loaded lazily; single-file uploads use fileUpload', () => {
assert.deepEqual(staticImporters('Files'), [])
assert.match(readFileSync(join(SRC, 'AddFile.tsx'), 'utf8'), /import \{uploadOne\} from '\.\/fileUpload'/)
})
10 changes: 5 additions & 5 deletions test/signed-in-shell.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ test('desktop and System sign-out keep bootstrap and surface a failed logout', a
})

test('the apps window says the app session lasts 30 days', async () => {
const desktop = await read('../web/src/desktop/Desktop.tsx')
assert.match(desktop, /apps \(30 days\)/)
assert.match(desktop, /for the next 30 days/)
assert.doesNotMatch(desktop, /apps \(7 days\)/)
assert.doesNotMatch(desktop, /next 7 days/)
const frame = await read('../web/src/desktop/AppFrame.tsx')
assert.match(frame, /apps \(30 days\)/)
assert.match(frame, /for the next 30 days/)
assert.doesNotMatch(frame, /apps \(7 days\)/)
assert.doesNotMatch(frame, /next 7 days/)
})
2 changes: 1 addition & 1 deletion web/src/AddFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {useRef, useState, type ReactNode} from 'react'

import {mutate} from './api'
import {Icon} from './icons'
import {uploadOne} from './screens/Files'
import {uploadOne} from './fileUpload'
import {haptic, useToast} from './ui'
import {uploadDirectory} from './uploadDirectory'

Expand Down
9 changes: 7 additions & 2 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {APP_TITLE, pageTitle} from './pageTitle'
import {Apps} from './screens/Apps'
import {Connect, Login} from './screens/Auth'
import {Home} from './screens/Home'
import {Desktop} from './desktop/Desktop'
import {TransferDetailHost} from './transfers/TransferJobs'
import {MovePinSettle} from './fleet/MovePinSettle'
import {resetDeskConfig} from './desktop/config'
Expand All @@ -39,6 +38,8 @@ import {AssistantLookContext, cleanLook, DEFAULT_LOOK, type AssistantLook} from
import {StatViewProvider} from './fleet/StatRegion'
import {AssistantCharacterWidget} from './character/widgets'

// The desktop shell is only for the desktop layout; the phone layout never loads it.
const Desktop = lazy(() => import('./desktop/Desktop').then((m) => ({default: m.Desktop})))
const Clips = lazy(() => import('./screens/Clips').then((m) => ({default: m.Clips})))
const Files = lazy(() => import('./screens/Files').then((m) => ({default: m.Files})))
const Machines = lazy(() => import('./screens/Machines').then((m) => ({default: m.Machines})))
Expand Down Expand Up @@ -155,7 +156,11 @@ export function App() {
<BootstrapContext.Provider value={b}>
<AssistantLookContext.Provider value={lookValue}>
<StatViewProvider prefs={prefs} setPrefs={setPrefs}>
{layout.desktop ? <Desktop boot={b} prefs={prefs} setPrefs={setPrefs} onSignedOut={refresh} reopenAssistant={reopenAssistant} /> : <Shell boot={b} prefs={prefs} setPrefs={setPrefs} onSignedOut={refresh} reopenAssistant={reopenAssistant} />}
{layout.desktop ? (
<Suspense fallback={<ScreenFallback />}>
<Desktop boot={b} prefs={prefs} setPrefs={setPrefs} onSignedOut={refresh} reopenAssistant={reopenAssistant} />
</Suspense>
) : <Shell boot={b} prefs={prefs} setPrefs={setPrefs} onSignedOut={refresh} reopenAssistant={reopenAssistant} />}
{askLayout ? <WelcomeForUser prefs={prefs} setPrefs={setPrefs} onDone={() => setAskLayout(false)} /> : <WhatsNewOnUpdate version={b.touch.version} onDone={() => setWhatsNewDone(true)} />}
<InstallerPrompt ready={whatsNewDone} />
</StatViewProvider>
Expand Down
2 changes: 1 addition & 1 deletion web/src/AppSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
import {askApp, explainProbe, openApp, webStatus} from './openApp'
import {mutate, query, type UserApp} from './api'
import {appUrl, useAction, useBootstrap, useUser} from './data'
import {useDesktop} from './desktop/Desktop'
import {useDesktop} from './desktop/context'
import {isOwner} from './isOwner'
import {Icon, type IconName} from './icons'
import {rovingKeyDown, TAB_SELECTOR} from './roving'
Expand Down
2 changes: 1 addition & 1 deletion web/src/AppViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createPortal} from 'react-dom'

import {mutate, type UserApp} from './api'
import {appUrl, useBootstrap} from './data'
import {AppFrame} from './desktop/Desktop'
import {AppFrame} from './desktop/AppFrame'
import {useDialogFocus} from './focus'
import {Icon} from './icons'
import {AppIcon, haptic, lockPageScroll, usePortalRoot, useToast} from './ui'
Expand Down
2 changes: 1 addition & 1 deletion web/src/ImportDiskImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Icon} from './icons'
import {MachineStepper} from './MachineStepper'
import {defaultCores, hostMaxMemoryGb, nextDiskGb} from './machineForm'
import {osLook} from './osLook'
import {uploadOne} from './screens/Files'
import {uploadOne} from './fileUpload'
import {bytes, Field, haptic} from './ui'
import {uploadDirectory} from './uploadDirectory'

Expand Down
2 changes: 1 addition & 1 deletion web/src/containers/ContainerDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {lazy, Suspense, useEffect, useState, type ReactNode} from 'react'
import {useQuery} from '@tanstack/react-query'

import {mutate, query} from '../api'
import {useDesktop} from '../desktop/Desktop'
import {useDesktop} from '../desktop/context'
import {openMachineTerminal} from '../desktop/openScreen'
import {useBootstrap, useUser} from '../data'
import {containerFleetId, SERVER_FLEET_ID} from '../fleet/list'
Expand Down
Loading
Loading