瀏覽代碼

:art: fix https://github.com/siyuan-note/siyuan/issues/9128

Vanessa 1 年之前
父節點
當前提交
eca0196bea
共有 3 個文件被更改,包括 16 次插入4 次删除
  1. 6 0
      app/electron/main.js
  2. 8 3
      app/src/boot/onGetConfig.ts
  3. 2 1
      app/src/layout/Wnd.ts

+ 6 - 0
app/electron/main.js

@@ -723,6 +723,12 @@ app.whenReady().then(() => {
         win.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + win.webContents.userAgent;
         win.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron " + win.webContents.userAgent;
         win.webContents.session.setSpellCheckerLanguages(["en-US"]);
         win.webContents.session.setSpellCheckerLanguages(["en-US"]);
         win.loadURL(data.url);
         win.loadURL(data.url);
+        win.on("close", (event) => {
+            if (win && !win.isDestroyed()) {
+                win.webContents.send("siyuan-save-close");
+            }
+            event.preventDefault();
+        });
         const targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
         const targetScreen = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
         if (mainScreen.id !== targetScreen.id) {
         if (mainScreen.id !== targetScreen.id) {
             win.setBounds(targetScreen.workArea);
             win.setBounds(targetScreen.workArea);

+ 8 - 3
app/src/boot/onGetConfig.ts

@@ -28,6 +28,7 @@ import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
 import {App} from "../index";
 import {App} from "../index";
 import {initWindowEvent} from "./globalEvent/event";
 import {initWindowEvent} from "./globalEvent/event";
 import {sendGlobalShortcut} from "./globalEvent/keydown";
 import {sendGlobalShortcut} from "./globalEvent/keydown";
+import {closeWindow} from "../window/closeWin";
 
 
 const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
 const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
     if (key1 === "general") {
     if (key1 === "general") {
@@ -297,10 +298,14 @@ export const initWindow = (app: App) => {
                 return;
                 return;
             }
             }
         });
         });
-        ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => {
-            winOnClose(currentWindow, close);
-        });
     }
     }
+    ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => {
+        if (isWindow()) {
+          closeWindow(app);
+        } else {
+            winOnClose(currentWindow, close);
+        }
+    });
     ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
     ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => {
         onWindowsMsg(ipcData);
         onWindowsMsg(ipcData);
     });
     });

+ 2 - 1
app/src/layout/Wnd.ts

@@ -36,6 +36,7 @@ import {focusByOffset, getSelectionOffset} from "../protyle/util/selection";
 import {Custom} from "./dock/Custom";
 import {Custom} from "./dock/Custom";
 import {App} from "../index";
 import {App} from "../index";
 import {unicode2Emoji} from "../emoji";
 import {unicode2Emoji} from "../emoji";
+import {closeWindow} from "../window/closeWin";
 
 
 export class Wnd {
 export class Wnd {
     private app: App;
     private app: App;
@@ -775,7 +776,7 @@ export class Wnd {
             if (!wnd) {
             if (!wnd) {
                 /// #if !BROWSER
                 /// #if !BROWSER
                 if (isWindow()) {
                 if (isWindow()) {
-                    getCurrentWindow().destroy();
+                    closeWindow(this.app);
                     return;
                     return;
                 }
                 }
                 /// #endif
                 /// #endif