Skip to content

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

:sparkles: https://github.com/siyuan-note/siyuan/issues/4567

Vanessa77bd2634e140
diff --git a/app/electron/main.js b/app/electron/main.js
index 98cec7dbf0..4624a78674 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -657,12 +657,14 @@ app.whenReady().then(() => {
ipcMain.on('siyuan-export-close', (event, id) => {
BrowserWindow.fromId(id).webContents.send('siyuan-export-close', data)
})
- ipcMain.on('siyuan-quit', (id) => {
+ ipcMain.on('siyuan-quit', (event, id) => {
const mainWindow = BrowserWindow.fromId(id)
let tray
workspaces.find((item, index) => {
if (item.id === id) {
- mainWindow.destroy()
+ if (workspaces.length > 1) {
+ mainWindow.destroy()
+ }
tray = item.tray
workspaces.splice(index, 1)
return true
@@ -830,9 +832,11 @@ app.on('second-instance', (event, commandLine) => {
})
app.on('activate', () => {
- const mainWindow = workspaces[0].browserWindow
- if (mainWindow && !mainWindow.isDestroyed()) {
- mainWindow.show()
+ if (workspaces.length > 0) {
+ const mainWindow = workspaces[0].browserWindow
+ if (mainWindow && !mainWindow.isDestroyed()) {
+ mainWindow.show()
+ }
}
if (BrowserWindow.getAllWindows().length === 0) {
boot()
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts
index d0b081baea..4505835e62 100644
--- a/app/src/dialog/processSystem.ts
+++ b/app/src/dialog/processSystem.ts
@@ -93,7 +93,7 @@ export const exitSiYuan = () => {
buttonElement.addEventListener("click", () => {
fetchPost("/api/system/exit", {force: true}, () => {
/// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_QUIT);
+ ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
/// #else
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
window.location.href = "siyuan://api/system/exit";
@@ -117,7 +117,7 @@ export const exitSiYuan = () => {
}, 2000);
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
setTimeout(() => {
- ipcRenderer.send(Constants.SIYUAN_QUIT);
+ ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
}, 4000);
/// #endif
});
@@ -127,13 +127,13 @@ export const exitSiYuan = () => {
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
}, () => {
/// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_QUIT);
+ ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
/// #endif
});
});
} else { // 正常退出
/// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_QUIT);
+ ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
/// #else
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
window.location.href = "siyuan://api/system/exit";
diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts
index 779de61fb1..56f31f1868 100644
--- a/app/src/util/fetch.ts
+++ b/app/src/util/fetch.ts
@@ -1,6 +1,7 @@
import {Constants} from "../constants";
/// #if !BROWSER
import {ipcRenderer} from "electron";
+import {getCurrentWindow} from "@electron/remote";
/// #endif
import {processMessage} from "./processMessage";
import {kernelError} from "../dialog/processSystem";
@@ -48,7 +49,7 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || (
["/api/system/setUILayout"].includes(url) && data.exit // 内核中断,点关闭处理
)) {
- ipcRenderer.send(Constants.SIYUAN_QUIT);
+ ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
}
/// #endif
});
diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts
index 97e6e13a59..0c66afd09e 100644
--- a/app/src/util/onGetConfig.ts
+++ b/app/src/util/onGetConfig.ts
@@ -367,6 +367,7 @@ const initWindow = () => {
document.body.classList.add("body--blur");
});
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
+ console.log(event, url)
if (!/^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url)) {
return;
}