mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
refactor: Extract boot phases in main.ts
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
984275711a
commit
013d188c0a
1 changed files with 16 additions and 5 deletions
21
src/main.ts
21
src/main.ts
|
|
@ -681,13 +681,19 @@ function toast(msg: string): void {
|
||||||
|
|
||||||
// ---------- boot
|
// ---------- boot
|
||||||
|
|
||||||
async function boot(): Promise<void> {
|
async function initSettings(): Promise<void> {
|
||||||
settings = await loadSettings();
|
settings = await loadSettings();
|
||||||
if (!localStorage.getItem("summarum.langInit") && settings.language === "en") {
|
if (!localStorage.getItem("summarum.langInit") && settings.language === "en") {
|
||||||
settings.language = detectLang();
|
settings.language = detectLang();
|
||||||
localStorage.setItem("summarum.langInit", "1");
|
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({
|
engine = new SumEngine({
|
||||||
precision: settings.precision,
|
precision: settings.precision,
|
||||||
groupSeparator: settings.groupSeparator,
|
groupSeparator: settings.groupSeparator,
|
||||||
|
|
@ -695,10 +701,6 @@ async function boot(): Promise<void> {
|
||||||
dateFormat: settings.dateFormat,
|
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);
|
const stored = await loadAppData(settings.dataDir);
|
||||||
// a corrupt or foreign documents.json must not crash the boot
|
// 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") {
|
if (stored && Array.isArray(stored.docs) && stored.docs.length > 0 && stored.contents && typeof stored.contents === "object") {
|
||||||
|
|
@ -763,6 +765,9 @@ async function boot(): Promise<void> {
|
||||||
editor.goToLine(line);
|
editor.goToLine(line);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initUI(): Promise<void> {
|
||||||
|
|
||||||
applySettings(); // sets the language before bindSettingsUI renders dynamic labels
|
applySettings(); // sets the language before bindSettingsUI renders dynamic labels
|
||||||
bindSettingsUI();
|
bindSettingsUI();
|
||||||
|
|
@ -962,6 +967,12 @@ async function boot(): Promise<void> {
|
||||||
setInterval(() => { if (settings.autoUpdateEnabled) void checkUpdate(); }, 6 * 60 * 60 * 1000);
|
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" */
|
/** manual = true when the user clicked "Check for updates" — only then report "up to date" / "check failed" */
|
||||||
async function checkUpdate(manual = false): Promise<void> {
|
async function checkUpdate(manual = false): Promise<void> {
|
||||||
const result = await checkForUpdate();
|
const result = await checkForUpdate();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue