mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
This commit is contained in:
parent
07d5a6cd2f
commit
b524a3c72f
3 changed files with 27 additions and 30 deletions
|
|
@ -51,31 +51,29 @@ try {
|
|||
}
|
||||
|
||||
// type: port/id
|
||||
const exitApp = (type, id, errorWindowId) => {
|
||||
const exitApp = (port, errorWindowId) => {
|
||||
let tray;
|
||||
let mainWindow;
|
||||
|
||||
// 关闭端口相同的所有非主窗口
|
||||
BrowserWindow.getAllWindows().forEach((item) => {
|
||||
const currentURL = new URL(item.getURL())
|
||||
if (port.toString() === currentURL.port.toString()) {
|
||||
if (currentURL.href.indexOf("/stage/build/app/?v=") > -1) {
|
||||
mainWindow = item;
|
||||
} else {
|
||||
item.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
workspaces.find((item, index) => {
|
||||
if (type === "id") {
|
||||
if (item.id === id) {
|
||||
mainWindow = item.browserWindow;
|
||||
if (workspaces.length > 1) {
|
||||
item.browserWindow.destroy();
|
||||
}
|
||||
workspaces.splice(index, 1);
|
||||
tray = item.tray;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
const currentURL = new URL(item.browserWindow.getURL());
|
||||
if (currentURL.port.toString() === id.toString()) {
|
||||
mainWindow = item.browserWindow;
|
||||
if (workspaces.length > 1) {
|
||||
item.browserWindow.destroy();
|
||||
}
|
||||
workspaces.splice(index, 1);
|
||||
tray = item.tray;
|
||||
return true;
|
||||
if (mainWindow.id === item.browserWindow.id) {
|
||||
if (workspaces.length > 1) {
|
||||
item.browserWindow.destroy();
|
||||
}
|
||||
workspaces.splice(index, 1);
|
||||
tray = item.tray;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (tray && ("win32" === process.platform || "linux" === process.platform)) {
|
||||
|
|
@ -103,7 +101,6 @@ const exitApp = (type, id, errorWindowId) => {
|
|||
|
||||
if (errorWindowId) {
|
||||
BrowserWindow.getAllWindows().forEach((item) => {
|
||||
writeLog(errorWindowId + " " + item.id);
|
||||
if (errorWindowId !== item.id) {
|
||||
item.destroy();
|
||||
}
|
||||
|
|
@ -491,7 +488,7 @@ const initKernel = (workspace, port, lang) => {
|
|||
break;
|
||||
}
|
||||
|
||||
exitApp("port", currentKernelPort, errorWindowId);
|
||||
exitApp(currentKernelPort, errorWindowId);
|
||||
bootWindow.destroy();
|
||||
resolve(false);
|
||||
}
|
||||
|
|
@ -666,8 +663,8 @@ app.whenReady().then(() => {
|
|||
shell.openExternal(url);
|
||||
});
|
||||
});
|
||||
ipcMain.on("siyuan-quit", (event, id) => {
|
||||
exitApp("id", id)
|
||||
ipcMain.on("siyuan-quit", (event, port) => {
|
||||
exitApp(port);
|
||||
});
|
||||
ipcMain.on("siyuan-openwindow", (event, data) => {
|
||||
const mainWindow = BrowserWindow.fromId(data.id);
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ export const exitSiYuan = () => {
|
|||
buttonElement.addEventListener("click", () => {
|
||||
fetchPost("/api/system/exit", {force: true}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||
/// #else
|
||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||
window.location.href = "siyuan://api/system/exit";
|
||||
|
|
@ -135,7 +135,7 @@ export const exitSiYuan = () => {
|
|||
}, 2000);
|
||||
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
|
||||
setTimeout(() => {
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||
}, 4000);
|
||||
/// #endif
|
||||
});
|
||||
|
|
@ -145,13 +145,13 @@ export const exitSiYuan = () => {
|
|||
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
||||
}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||
/// #endif
|
||||
});
|
||||
});
|
||||
} else { // 正常退出
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||
/// #else
|
||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||
window.location.href = "siyuan://api/system/exit";
|
||||
|
|
|
|||
|
|
@ -49,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.errorExit // 内核中断,点关闭处理
|
||||
)) {
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||
}
|
||||
/// #endif
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue