Skip to content

Commit

Permalink
🎨 #12656
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 6, 2024
1 parent ca5d906 commit 0d03024
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const appVer = app.getVersion();
const confDir = path.join(app.getPath("home"), ".config", "siyuan");
const windowStatePath = path.join(confDir, "windowState.json");
let bootWindow;
let latestActiveWindow;
let firstOpen = false;
let workspaces = []; // workspaceDir, id, browserWindow, tray
let kernelPort = 6806;
Expand Down Expand Up @@ -700,7 +701,10 @@ app.whenReady().then(() => {
const hideWindow = (wnd) => {
// 通过 `Alt+M` 最小化后焦点回到先前的窗口 https://github.com/siyuan-note/siyuan/issues/7275
wnd.minimize();
wnd.hide();
// Mac 隐藏后无法再 Dock 中显示
if ("win32" === process.platform || "linux" === process.platform) {
wnd.hide();
}
};
const showHideWindow = (tray, lang, mainWindow) => {
if (!mainWindow.isVisible()) {
Expand Down Expand Up @@ -815,8 +819,10 @@ app.whenReady().then(() => {
if (!currentWindow) {
return;
}
latestActiveWindow = currentWindow;
currentWindow.on("focus", () => {
event.sender.send("siyuan-event", "focus");
latestActiveWindow = currentWindow;
});
currentWindow.on("blur", () => {
event.sender.send("siyuan-event", "blur");
Expand Down Expand Up @@ -1102,29 +1108,35 @@ app.whenReady().then(() => {
}
if (index === 0) {
globalShortcut.register(shortcut, () => {
let currentWorkspace;
const currentWebContentsId = (latestActiveWindow && !latestActiveWindow.isDestroyed()) ? latestActiveWindow.webContents.id : undefined
workspaces.find(workspaceItem => {
const mainWindow = workspaceItem.browserWindow;
if (event.sender.id === mainWindow.webContents.id) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
mainWindow.show(); // 按 `Alt+M` 后隐藏窗口,再次按 `Alt+M` 显示窗口后会卡住不能编辑 https://github.com/siyuan-note/siyuan/issues/8456
} else {
if (mainWindow.isVisible()) {
if (!mainWindow.isFocused()) {
mainWindow.show();
} else {
hideWindow(mainWindow);
}
} else {
mainWindow.show();
}
}
if ("win32" === process.platform || "linux" === process.platform) {
resetTrayMenu(workspaceItem.tray, data.languages, mainWindow);
}
if ((currentWebContentsId || event.sender.id) === workspaceItem.browserWindow.webContents.id) {
currentWorkspace = workspaceItem;
return true;
}
});
if (!currentWorkspace) {
return;
}
const mainWindow = currentWorkspace.browserWindow;
if (mainWindow.isMinimized()) {
mainWindow.restore();
mainWindow.show(); // 按 `Alt+M` 后隐藏窗口,再次按 `Alt+M` 显示窗口后会卡住不能编辑 https://github.com/siyuan-note/siyuan/issues/8456
} else {
if (mainWindow.isVisible()) {
if (!mainWindow.isFocused()) {
mainWindow.show();
} else {
hideWindow(mainWindow);
}
} else {
mainWindow.show();
}
}
if ("win32" === process.platform || "linux" === process.platform) {
resetTrayMenu(currentWorkspace.tray, data.languages, mainWindow);
}
});
} else {
globalShortcut.register(shortcut, () => {
Expand Down Expand Up @@ -1331,7 +1343,7 @@ app.on("second-instance", (event, argv) => {

app.on("activate", () => {
if (workspaces.length > 0) {
const mainWindow = workspaces[0].browserWindow;
const mainWindow = (latestActiveWindow && !latestActiveWindow.isDestroyed()) ? latestActiveWindow : workspaces[0].browserWindow;
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.show();
}
Expand Down

0 comments on commit 0d03024

Please sign in to comment.