forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
71 lines (64 loc) · 2.4 KB
/
Copy pathApp.tsx
File metadata and controls
71 lines (64 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useEffect, useLayoutEffect, useState } from 'react'
import { useAppStore, type UiScale } from '@shared/stores/appStore'
import FirstRunSetup from '@areas/setup/FirstRunSetup'
import MainLayout from '@shared/components/layout/MainLayout'
import { UpdateModal } from '@shared/components/ui/UpdateModal'
import { ErrorModal } from '@shared/components/ui/ErrorModal'
import { Toast } from '@shared/components/ui/Toast'
const UI_SCALE_FACTORS: Record<UiScale, number> = { small: 0.875, medium: 1, large: 1.25, 'very-large': 1.5 }
export default function App(): JSX.Element {
const { checkSetup, setupStatus, initApp, backendStatus, showError, useAtkinsonFont, uiScale } = useAppStore()
const [updateVersion, setUpdateVersion] = useState<string | null>(null)
const [currentVersion, setCurrentVersion] = useState<string>('')
useEffect(() => {
checkSetup()
window.electron.app.onError((message) => showError(message))
window.electron.updater.onMajorMinorAvailable(({ version }) => {
setUpdateVersion(`v${version}`)
})
return () => {
window.electron.app.offError()
window.electron.updater.offMajorMinorAvailable()
}
// eslint-disable-next-line react-hooks/exhaustive-deps -- run once on mount; store actions are stable
}, [])
// Apply before paint to avoid a flash of default font/size on launch.
useLayoutEffect(() => {
document.documentElement.style.setProperty(
'--app-font',
useAtkinsonFont
? "'Atkinson Hyperlegible', system-ui, sans-serif"
: "'Inter', system-ui, sans-serif"
)
window.electron.ui.setZoomFactor(UI_SCALE_FACTORS[uiScale])
}, [useAtkinsonFont, uiScale])
useEffect(() => {
if (setupStatus === 'done') initApp()
// eslint-disable-next-line react-hooks/exhaustive-deps -- react to setup transition only; initApp is stable
}, [setupStatus])
useEffect(() => {
if (backendStatus !== 'ready') return
window.electron.app.info().then(({ version }) => setCurrentVersion(version))
}, [backendStatus])
if (backendStatus === 'ready') return (
<>
<MainLayout />
{updateVersion && (
<UpdateModal
currentVersion={currentVersion}
latestVersion={updateVersion}
onDismiss={() => setUpdateVersion(null)}
/>
)}
<Toast />
<ErrorModal />
</>
)
return (
<>
<FirstRunSetup />
<Toast />
<ErrorModal />
</>
)
}