mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 08:57:02 +02:00
feat(setup): add a nice banner when DB not initialized
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user