From a674c66d637ce79198b83a933c59694800625e14 Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Wed, 8 Jul 2026 15:46:22 +0300 Subject: [PATCH] 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. --- src/main.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 985af34..47edfa5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -700,13 +700,19 @@ function toast(msg: string): void { // ---------- boot -async function boot(): Promise { +async function initSettings(): Promise { 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 { engine = new SumEngine({ precision: settings.precision, groupSeparator: settings.groupSeparator, @@ -714,10 +720,6 @@ async function boot(): Promise { 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 { editor.goToLine(line); }, }); +} + +async function initUI(): Promise { applySettings(); // sets the language before bindSettingsUI renders dynamic labels bindSettingsUI(); @@ -981,6 +986,12 @@ async function boot(): Promise { setInterval(() => { if (settings.autoUpdateEnabled) void checkUpdate(); }, 6 * 60 * 60 * 1000); } +async function boot(): Promise { + 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 { const result = await checkForUpdate();