Merge pull request #1566 from TriliumNext/tray

Fix program crash during initial setup and the tray not showing.
This commit is contained in:
Elian Doran 2025-03-30 14:50:11 +03:00 committed by GitHub
commit e01dc5751a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View File

@ -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 {

View File

@ -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
};

View File

@ -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");
}
});
}