mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
Merge pull request #1566 from TriliumNext/tray
Fix program crash during initial setup and the tray not showing.
This commit is contained in:
commit
e01dc5751a
@ -37,8 +37,13 @@ function setupPage(req: Request, res: Response) {
|
|||||||
async function handleElectronRedirect() {
|
async function handleElectronRedirect() {
|
||||||
const windowService = (await import("../services/window.js")).default;
|
const windowService = (await import("../services/window.js")).default;
|
||||||
const { app } = await import("electron");
|
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();
|
windowService.closeSetupWindow();
|
||||||
|
|
||||||
|
const tray = (await import("../services/tray.js")).default;
|
||||||
|
tray.createTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -95,6 +95,9 @@ function updateWindowVisibilityMap(allWindows: BrowserWindow[]) {
|
|||||||
|
|
||||||
|
|
||||||
function updateTrayMenu() {
|
function updateTrayMenu() {
|
||||||
|
if (!tray) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
const lastFocusedWindow = windowService.getLastFocusedWindow();
|
||||||
const allWindows = windowService.getAllWindows();
|
const allWindows = windowService.getAllWindows();
|
||||||
updateWindowVisibilityMap(allWindows);
|
updateWindowVisibilityMap(allWindows);
|
||||||
@ -299,6 +302,5 @@ function createTray() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
createTray,
|
createTray
|
||||||
updateTrayMenu
|
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,6 @@ import remoteMain from "@electron/remote/main/index.js";
|
|||||||
import { BrowserWindow, shell, type App, type BrowserWindowConstructorOptions, type WebContents } from "electron";
|
import { BrowserWindow, shell, type App, type BrowserWindowConstructorOptions, type WebContents } from "electron";
|
||||||
import { dialog, ipcMain } from "electron";
|
import { dialog, ipcMain } from "electron";
|
||||||
import { formatDownloadTitle, isDev, isMac, isWindows } from "./utils.js";
|
import { formatDownloadTitle, isDev, isMac, isWindows } from "./utils.js";
|
||||||
import tray from "./tray.js";
|
|
||||||
|
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import { dirname } from "path";
|
import { dirname } from "path";
|
||||||
@ -29,14 +28,14 @@ function trackWindowFocus(win: BrowserWindow) {
|
|||||||
allWindows = allWindows.filter(w => !w.isDestroyed() && w !== win);
|
allWindows = allWindows.filter(w => !w.isDestroyed() && w !== win);
|
||||||
allWindows.push(win);
|
allWindows.push(win);
|
||||||
if (!optionService.getOptionBool("disableTray")) {
|
if (!optionService.getOptionBool("disableTray")) {
|
||||||
tray.updateTrayMenu();
|
ipcMain.emit("reload-tray");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
allWindows = allWindows.filter(w => !w.isDestroyed());
|
allWindows = allWindows.filter(w => !w.isDestroyed());
|
||||||
if (!optionService.getOptionBool("disableTray")) {
|
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;
|
return allWindows.length > 0 ? allWindows[allWindows.length - 1] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllWindows(){
|
function getAllWindows() {
|
||||||
return allWindows;
|
return allWindows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user