diff --git a/app/electron/main.js b/app/electron/main.js index bf89e71d1..1c82eb900 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -59,7 +59,7 @@ try { } // type: port/id -const exitApp = (type, id) => { +const exitApp = (type, id, errorWindowId) => { let tray; let mainWindow; workspaces.find((item, index) => { @@ -108,7 +108,15 @@ const exitApp = (type, id) => { } catch (e) { writeLog(e); } - app.exit(); + if (errorWindowId) { + BrowserWindow.getAll().forEach((item) => { + if (errorWindowId !== item.id) { + item.destroy(); + } + }); + } else { + app.exit(); + } globalShortcut.unregisterAll(); writeLog("exited ui"); } @@ -150,6 +158,7 @@ const showErrorWindow = (title, content) => { }, }); errWindow.show(); + return errWindow.id; }; const writeLog = (out) => { @@ -496,23 +505,22 @@ const initKernel = (workspace, port, lang) => { ); const currentKernelPid = kernelProcess.pid; - const currentKernelPort = kernelPort; - writeLog("booted kernel process [pid=" + currentKernelPid + ", port=" + currentKernelPort + "]"); - + writeLog("booted kernel process [pid=" + currentKernelPid + ", port=" + kernelPort + "]"); kernelProcess.on("close", (code) => { - writeLog(`kernel [pid=${currentKernelPid}, port=${currentKernelPort}] exited with code [${code}]`); + writeLog(`kernel [pid=${currentKernelPid}, port=${kernelPort}] exited with code [${code}]`); if (0 !== code) { + let errorWindowId; switch (code) { case 20: - showErrorWindow("⚠️ 数据库被锁定 The database is locked", + errorWindowId = showErrorWindow("⚠️ 数据库被锁定 The database is locked", "
数据库文件正在被其他进程占用,请检查是否同时存在多个内核进程(SiYuan Kernel)服务相同的工作空间。
The database file is being occupied by other processes, please check whether there are multiple kernel processes (SiYuan Kernel) serving the same workspace at the same time.
"); break; case 21: - showErrorWindow("⚠️ 监听端口 " + kernelPort + " 失败 Failed to listen to port " + kernelPort, + errorWindowId = showErrorWindow("⚠️ 监听端口 " + kernelPort + " 失败 Failed to listen to port " + kernelPort, "
监听 " + kernelPort + " 端口失败,请确保程序拥有网络权限并不受防火墙和杀毒软件阻止。
Failed to listen to port " + kernelPort + ", please make sure the program has network permissions and is not blocked by firewalls and antivirus software.
"); break; case 22: - showErrorWindow("⚠️ 创建配置目录失败 Failed to create config directory", + errorWindowId = showErrorWindow("⚠️ 创建配置目录失败 Failed to create config directory", "
思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。
SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.
"); break; case 24: // 工作空间已被锁定,尝试切换到第一个打开的工作空间 @@ -520,7 +528,7 @@ const initKernel = (workspace, port, lang) => { showWindow(workspaces[0].browserWindow); } - showErrorWindow("⚠️ 工作空间已被锁定 The workspace is locked", + errorWindowId = showErrorWindow("⚠️ 工作空间已被锁定 The workspace is locked", "
该工作空间正在被使用。
The workspace is in use.
"); break; case 25: @@ -528,20 +536,20 @@ const initKernel = (workspace, port, lang) => { "
创建工作空间目录失败。
Failed to create workspace directory.
"); break; case 26: - showErrorWindow("⚠️ 文件系统读写错误 File system access error", + errorWindowId = showErrorWindow("⚠️ 文件系统读写错误 File system access error", "
请检查文件系统权限,并确保没有其他程序正在读写文件;
请勿使用第三方同步盘进行数据同步,否则数据会被损坏(iCloud/OneDrive/Dropbox/Google Drive/坚果云/百度网盘/腾讯微云等)
Please check file system permissions and make sure no other programs are reading or writing to the file;
Do not use a third-party sync disk for data sync, otherwise the data will be damaged (OneDrive/Dropbox/Google Drive/Nutstore/Baidu Netdisk/Tencent Weiyun, etc.)
"); break; case 0: case 1: // Fatal error break; default: - showErrorWindow("⚠️ 内核因未知原因退出 The kernel exited for unknown reasons", + errorWindowId = showErrorWindow("⚠️ 内核因未知原因退出 The kernel exited for unknown reasons", `
思源内核因未知原因退出 [code=${code}],请尝试重启操作系统后再启动思源。如果该问题依然发生,请检查杀毒软件是否阻止思源内核启动。
SiYuan Kernel exited for unknown reasons [code=${code}], please try to reboot your operating system and then start SiYuan again. If occurs this problem still, please check your anti-virus software whether kill the SiYuan Kernel.
`); break; } - exitApp("port", currentKernelPort); + exitApp("port", kernelPort, errorWindowId); bootWindow.destroy(); resolve(false); }