split boot() into initSettings/initDataAndEngine/initUI

Boot had grown into one long function covering settings load, engine
and workspace setup, and all the UI wiring. Split along those natural
phase boundaries; boot() itself is now just the three awaits in order.
This commit is contained in:
Horizontal42 2026-07-08 15:46:22 +03:00
parent 216a18821c
commit a674c66d63

View file

@ -700,13 +700,19 @@ function toast(msg: string): void {
// ---------- boot
async function boot(): Promise<void> {
async function initSettings(): Promise<void> {
settings = await loadSettings();
if (!localStorage.getItem("summarum.langInit") && settings.language === "en") {
settings.language = detectLang();
localStorage.setItem("summarum.langInit", "1");
}
// snapshots run before the app writes anything
setDataDir(settings.dataDir);
await runBackups(settings.dataDir, settings.deletedRetentionDays);
}
async function initDataAndEngine(): Promise<void> {
engine = new SumEngine({
precision: settings.precision,
groupSeparator: settings.groupSeparator,
@ -714,10 +720,6 @@ async function boot(): Promise<void> {
dateFormat: settings.dateFormat,
});
// snapshots run before the app writes anything
setDataDir(settings.dataDir);
await runBackups(settings.dataDir, settings.deletedRetentionDays);
const stored = await loadAppData(settings.dataDir);
// a corrupt or foreign documents.json must not crash the boot
if (stored && Array.isArray(stored.docs) && stored.docs.length > 0 && stored.contents && typeof stored.contents === "object") {
@ -782,6 +784,9 @@ async function boot(): Promise<void> {
editor.goToLine(line);
},
});
}
async function initUI(): Promise<void> {
applySettings(); // sets the language before bindSettingsUI renders dynamic labels
bindSettingsUI();
@ -981,6 +986,12 @@ async function boot(): Promise<void> {
setInterval(() => { if (settings.autoUpdateEnabled) void checkUpdate(); }, 6 * 60 * 60 * 1000);
}
async function boot(): Promise<void> {
await initSettings();
await initDataAndEngine();
await initUI();
}
/** manual = true when the user clicked "Check for updates" — only then report "up to date" / "check failed" */
async function checkUpdate(manual = false): Promise<void> {
const result = await checkForUpdate();