🐛 The tray is generated repeatedly after the new window is locked and then entered https://github.com/siyuan-note/siyuan/issues/15357

This commit is contained in:
Daniel 2025-07-25 14:37:01 +08:00
parent 262957d4de
commit 917a5125af
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -678,6 +678,10 @@ for (let i = argStart; i < process.argv.length; i++) {
app.whenReady().then(() => {
const resetTrayMenu = (tray, lang, mainWindow) => {
if (!mainWindow || mainWindow.isDestroyed()) {
return;
}
const trayMenuTemplate = [{
label: mainWindow.isVisible() ? lang.hideWindow : lang.showWindow, click: () => {
showHideWindow(tray, lang, mainWindow);
@ -726,6 +730,10 @@ app.whenReady().then(() => {
}
};
const showHideWindow = (tray, lang, mainWindow) => {
if (!mainWindow || mainWindow.isDestroyed()) {
return;
}
if (!mainWindow.isVisible()) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
@ -1113,23 +1121,24 @@ app.whenReady().then(() => {
if (exitWS) {
return;
}
let tray;
if ("win32" === process.platform || "linux" === process.platform) {
// 系统托盘
tray = new Tray(path.join(appDir, "stage", "icon-large.png"));
tray.setToolTip(`${path.basename(data.workspaceDir)} - SiYuan v${appVer}`);
const mainWindow = getWindowByContentId(event.sender.id);
if (!mainWindow) {
return;
}
resetTrayMenu(tray, data.languages, mainWindow);
tray.on("click", () => {
showHideWindow(tray, data.languages, mainWindow);
});
}
workspaces.find(item => {
if (!item.workspaceDir) {
item.workspaceDir = data.workspaceDir;
let tray;
if ("win32" === process.platform || "linux" === process.platform) {
// 系统托盘
tray = new Tray(path.join(appDir, "stage", "icon-large.png"));
tray.setToolTip(`${path.basename(data.workspaceDir)} - SiYuan v${appVer}`);
const mainWindow = getWindowByContentId(event.sender.id);
if (!mainWindow || mainWindow.isDestroyed()) {
return;
}
resetTrayMenu(tray, data.languages, mainWindow);
tray.on("click", () => {
showHideWindow(tray, data.languages, mainWindow);
});
}
item.tray = tray;
return true;
}