mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +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
|
// type: port/id
|
||||||
const exitApp = (type, id, errorWindowId) => {
|
const exitApp = (port, errorWindowId) => {
|
||||||
let tray;
|
let tray;
|
||||||
let mainWindow;
|
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) => {
|
workspaces.find((item, index) => {
|
||||||
if (type === "id") {
|
if (mainWindow.id === item.browserWindow.id) {
|
||||||
if (item.id === id) {
|
if (workspaces.length > 1) {
|
||||||
mainWindow = item.browserWindow;
|
item.browserWindow.destroy();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
workspaces.splice(index, 1);
|
||||||
|
tray = item.tray;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (tray && ("win32" === process.platform || "linux" === process.platform)) {
|
if (tray && ("win32" === process.platform || "linux" === process.platform)) {
|
||||||
|
|
@ -103,7 +101,6 @@ const exitApp = (type, id, errorWindowId) => {
|
||||||
|
|
||||||
if (errorWindowId) {
|
if (errorWindowId) {
|
||||||
BrowserWindow.getAllWindows().forEach((item) => {
|
BrowserWindow.getAllWindows().forEach((item) => {
|
||||||
writeLog(errorWindowId + " " + item.id);
|
|
||||||
if (errorWindowId !== item.id) {
|
if (errorWindowId !== item.id) {
|
||||||
item.destroy();
|
item.destroy();
|
||||||
}
|
}
|
||||||
|
|
@ -491,7 +488,7 @@ const initKernel = (workspace, port, lang) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
exitApp("port", currentKernelPort, errorWindowId);
|
exitApp(currentKernelPort, errorWindowId);
|
||||||
bootWindow.destroy();
|
bootWindow.destroy();
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
|
|
@ -666,8 +663,8 @@ app.whenReady().then(() => {
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-quit", (event, id) => {
|
ipcMain.on("siyuan-quit", (event, port) => {
|
||||||
exitApp("id", id)
|
exitApp(port);
|
||||||
});
|
});
|
||||||
ipcMain.on("siyuan-openwindow", (event, data) => {
|
ipcMain.on("siyuan-openwindow", (event, data) => {
|
||||||
const mainWindow = BrowserWindow.fromId(data.id);
|
const mainWindow = BrowserWindow.fromId(data.id);
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ export const exitSiYuan = () => {
|
||||||
buttonElement.addEventListener("click", () => {
|
buttonElement.addEventListener("click", () => {
|
||||||
fetchPost("/api/system/exit", {force: true}, () => {
|
fetchPost("/api/system/exit", {force: true}, () => {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||||
/// #else
|
/// #else
|
||||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||||
window.location.href = "siyuan://api/system/exit";
|
window.location.href = "siyuan://api/system/exit";
|
||||||
|
|
@ -135,7 +135,7 @@ export const exitSiYuan = () => {
|
||||||
}, 2000);
|
}, 2000);
|
||||||
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
|
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||||
}, 4000);
|
}, 4000);
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
|
|
@ -145,13 +145,13 @@ export const exitSiYuan = () => {
|
||||||
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else { // 正常退出
|
} else { // 正常退出
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||||
/// #else
|
/// #else
|
||||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||||
window.location.href = "siyuan://api/system/exit";
|
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" || (
|
if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || (
|
||||||
["/api/system/setUILayout"].includes(url) && data.errorExit // 内核中断,点关闭处理
|
["/api/system/setUILayout"].includes(url) && data.errorExit // 内核中断,点关闭处理
|
||||||
)) {
|
)) {
|
||||||
ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue