Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Fix program crash during initial setup and the tray not showing.
SiriusXT4c063251e0d5
diff --git a/src/routes/setup.ts b/src/routes/setup.tsindex 9ccb4cf337..5bb0f56c91 100644--- a/src/routes/setup.ts+++ b/src/routes/setup.ts@@ -37,8 +37,13 @@ function setupPage(req: Request, res: Response) {async function handleElectronRedirect() {const windowService = (await import("../services/window.js")).default;const { app } = await import("electron");- windowService.createMainWindow(app);++ // Wait for the main window to be created before closing the setup window to prevent triggering `window-all-closed`.+ await windowService.createMainWindow(app);windowService.closeSetupWindow();++ const tray = (await import("../services/tray.js")).default;+ tray.createTray();}export default {diff --git a/src/services/tray.ts b/src/services/tray.tsindex 2933e49fc9..82137174d6 100644--- a/src/services/tray.ts+++ b/src/services/tray.ts@@ -95,6 +95,9 @@ function updateWindowVisibilityMap(allWindows: BrowserWindow[]) {function updateTrayMenu() {+ if (!tray) {+ return;+ }const lastFocusedWindow = windowService.getLastFocusedWindow();const allWindows = windowService.getAllWindows();updateWindowVisibilityMap(allWindows);@@ -299,6 +302,5 @@ function createTray() {}export default {- createTray,- updateTrayMenu+ createTray};diff --git a/src/services/window.ts b/src/services/window.tsindex 12c125b6d3..a575d27d60 100644--- a/src/services/window.ts+++ b/src/services/window.ts@@ -11,7 +11,6 @@ import remoteMain from "@electron/remote/main/index.js";import { BrowserWindow, shell, type App, type BrowserWindowConstructorOptions, type WebContents } from "electron";import { dialog, ipcMain } from "electron";import { formatDownloadTitle, isDev, isMac, isWindows } from "./utils.js";-import tray from "./tray.js";import { fileURLToPath } from "url";import { dirname } from "path";@@ -29,14 +28,14 @@ function trackWindowFocus(win: BrowserWindow) {allWindows = allWindows.filter(w => !w.isDestroyed() && w !== win);allWindows.push(win);if (!optionService.getOptionBool("disableTray")) {- tray.updateTrayMenu();+ ipcMain.emit("reload-tray");}});win.on("closed", () => {allWindows = allWindows.filter(w => !w.isDestroyed());if (!optionService.getOptionBool("disableTray")) {- tray.updateTrayMenu();+ ipcMain.emit("reload-tray");}});}@@ -326,7 +325,7 @@ function getLastFocusedWindow() {return allWindows.length > 0 ? allWindows[allWindows.length - 1] : null;}-function getAllWindows(){+function getAllWindows() {return allWindows;}