Sfoglia il codice sorgente

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

Vanessa 2 anni fa
parent
commit
77bd2634e1

+ 9 - 5
app/electron/main.js

@@ -657,12 +657,14 @@ app.whenReady().then(() => {
   ipcMain.on('siyuan-export-close', (event, id) => {
   ipcMain.on('siyuan-export-close', (event, id) => {
     BrowserWindow.fromId(id).webContents.send('siyuan-export-close', data)
     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)
     const mainWindow = BrowserWindow.fromId(id)
     let tray
     let tray
     workspaces.find((item, index) => {
     workspaces.find((item, index) => {
       if (item.id === id) {
       if (item.id === id) {
-        mainWindow.destroy()
+        if (workspaces.length > 1) {
+          mainWindow.destroy()
+        }
         tray = item.tray
         tray = item.tray
         workspaces.splice(index, 1)
         workspaces.splice(index, 1)
         return true
         return true
@@ -830,9 +832,11 @@ app.on('second-instance', (event, commandLine) => {
 })
 })
 
 
 app.on('activate', () => {
 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) {
   if (BrowserWindow.getAllWindows().length === 0) {
     boot()
     boot()

+ 4 - 4
app/src/dialog/processSystem.ts

@@ -93,7 +93,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);
+                        ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
                         /// #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";
@@ -117,7 +117,7 @@ export const exitSiYuan = () => {
                     }, 2000);
                     }, 2000);
                     // 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
                     // 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
                     setTimeout(() => {
                     setTimeout(() => {
-                        ipcRenderer.send(Constants.SIYUAN_QUIT);
+                        ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
                     }, 4000);
                     }, 4000);
                     /// #endif
                     /// #endif
                 });
                 });
@@ -127,13 +127,13 @@ export const exitSiYuan = () => {
                     execInstallPkg: 1 //  0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
                     execInstallPkg: 1 //  0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
                 }, () => {
                 }, () => {
                     /// #if !BROWSER
                     /// #if !BROWSER
-                    ipcRenderer.send(Constants.SIYUAN_QUIT);
+                    ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
                     /// #endif
                     /// #endif
                 });
                 });
             });
             });
         } else { // 正常退出
         } else { // 正常退出
             /// #if !BROWSER
             /// #if !BROWSER
-            ipcRenderer.send(Constants.SIYUAN_QUIT);
+            ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
             /// #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";

+ 2 - 1
app/src/util/fetch.ts

@@ -1,6 +1,7 @@
 import {Constants} from "../constants";
 import {Constants} from "../constants";
 /// #if !BROWSER
 /// #if !BROWSER
 import {ipcRenderer} from "electron";
 import {ipcRenderer} from "electron";
+import {getCurrentWindow} from "@electron/remote";
 /// #endif
 /// #endif
 import {processMessage} from "./processMessage";
 import {processMessage} from "./processMessage";
 import {kernelError} from "../dialog/processSystem";
 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" || (
         if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || (
             ["/api/system/setUILayout"].includes(url) && data.exit // 内核中断,点关闭处理
             ["/api/system/setUILayout"].includes(url) && data.exit // 内核中断,点关闭处理
         )) {
         )) {
-            ipcRenderer.send(Constants.SIYUAN_QUIT);
+            ipcRenderer.send(Constants.SIYUAN_QUIT, getCurrentWindow().id);
         }
         }
         /// #endif
         /// #endif
     });
     });

+ 1 - 0
app/src/util/onGetConfig.ts

@@ -367,6 +367,7 @@ const initWindow = () => {
         document.body.classList.add("body--blur");
         document.body.classList.add("body--blur");
     });
     });
     ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
     ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
+        console.log(event, url)
         if (!/^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url)) {
         if (!/^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url)) {
             return;
             return;
         }
         }