feat(setup): add a nice banner when DB not initialized

This commit is contained in:
Elian Doran
2026-03-26 18:21:44 +02:00
parent afe597c811
commit b574237dfb
3 changed files with 26 additions and 2 deletions

View File

@@ -180,7 +180,7 @@ async function onReady() {
tray.createTray();
} else {
getLog().info(t("sql_init.db_not_initialized_desktop"));
getLog().banner(t("sql_init.db_not_initialized_desktop"));
await windowService.createSetupWindow();
}

View File

@@ -66,7 +66,7 @@ async function startApplication() {
await startTriliumServer();
if (!sql_init.isDbInitialized()) {
getLog().info(t("sql_init.db_not_initialized_server", { port }));
getLog().banner(t("sql_init.db_not_initialized_server", { port }));
}
}

View File

@@ -12,6 +12,30 @@ export default class LogService {
console.error("ERROR: ", message);
}
banner(message: string) {
const maxContent = 76; // 80 - 4 (border + padding)
const words = message.split(" ");
const lines: string[] = [];
let current = "";
for (const word of words) {
const candidate = current ? `${current} ${word}` : word;
if (candidate.length > maxContent) {
if (current) lines.push(current);
current = word;
} else {
current = candidate;
}
}
if (current) lines.push(current);
const width = Math.min(Math.max(...lines.map((l) => l.length)), maxContent) + 4;
const top = `${"═".repeat(width)}`;
const mid = lines.map((l) => `${l.padEnd(width - 4)}`).join("\n");
const bot = `${"═".repeat(width)}`;
console.log(`\n${top}\n${mid}\n${bot}\n`);
}
}
let log: LogService;