Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/12656

Vanessa0d030242380e
diff --git a/app/electron/main.js b/app/electron/main.js
index 1eaf3de1bf..c912e3b865 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -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;
@@ -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()) {
@@ -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");
@@ -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, () => {
@@ -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();
}