浏览代码

:art: https://github.com/siyuan-note/siyuan/issues/7042

Vanessa 2 年之前
父节点
当前提交
db6932c157

+ 8 - 0
app/electron/main.js

@@ -779,6 +779,14 @@ app.whenReady().then(() => {
     })
   })
 
+  ipcMain.on('siyuan-lock-screen', () => {
+    workspaces.forEach(item => {
+      const currentURL = new URL(item.browserWindow.getURL())
+      const server = getServer(currentURL.port)
+      fetch(server + '/api/system/logoutAuth', {method: 'POST'})
+    })
+  })
+
   if (firstOpen) {
     const firstOpenWindow = new BrowserWindow({
       width: screen.getPrimaryDisplay().size.width / 2,

+ 1 - 0
app/src/constants.ts

@@ -21,6 +21,7 @@ export abstract class Constants {
 
     // 渲染进程调主进程
     public static readonly SIYUAN_SHOW: string = "siyuan-show";
+    public static readonly SIYUAN_LOCK_SCREEN: string = "siyuan-lock-screen";
     public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
     public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
     public static readonly SIYUAN_QUIT: string = "siyuan-quit";

+ 11 - 1
app/src/dialog/processSystem.ts

@@ -10,7 +10,17 @@ import {Dialog} from "./index";
 import {isMobile} from "../util/functions";
 import {confirmDialog} from "./confirmDialog";
 import {getCurrentWindow} from "@electron/remote";
-import { getWorkspaceName } from "../menus/workspace";
+import {getWorkspaceName} from "../menus/workspace";
+
+export const lockScreen = () => {
+    /// #if BROWSER
+    fetchPost("/api/system/logoutAuth", {}, () => {
+        window.location.href = "/";
+    });
+    /// #else
+    ipcRenderer.send(Constants.SIYUAN_LOCK_SCREEN);
+    /// #endif
+}
 
 export const lockFile = (id: string) => {
     const html = `<div class="b3-dialog__scrim"></div>

+ 2 - 5
app/src/layout/status.ts

@@ -10,6 +10,7 @@ import {getCurrentWindow} from "@electron/remote";
 /// #endif
 /// #endif
 import {isBrowser} from "../util/functions";
+import {lockScreen} from "../dialog/processSystem";
 
 export const initStatus = () => {
     /// #if !MOBILE
@@ -83,11 +84,7 @@ export const initStatus = () => {
                 event.stopPropagation();
                 break;
             } else if (target.id === "barLock") {
-                exportLayout(false, () => {
-                    fetchPost("/api/system/logoutAuth", {}, () => {
-                        window.location.href = "/";
-                    });
-                });
+                lockScreen()
                 event.stopPropagation();
                 break;
             } else if (target.id === "barHelp") {

+ 2 - 4
app/src/mobile/util/menu.ts

@@ -9,7 +9,7 @@ import {mountHelp, newDailyNote, newNotebook} from "../../util/mount";
 import {repos} from "../../config/repos";
 import * as md5 from "blueimp-md5";
 import {showMessage} from "../../dialog/message";
-import {exitSiYuan} from "../../dialog/processSystem";
+import {exitSiYuan, lockScreen} from "../../dialog/processSystem";
 import {confirmDialog} from "../../dialog/confirmDialog";
 import {openHistory} from "../../history/history";
 import {Dialog} from "../../dialog";
@@ -535,9 +535,7 @@ ${accountHTML}
                     event.stopPropagation();
                     break;
                 } else if (target.id === "menuLock") {
-                    fetchPost("/api/system/logoutAuth", {}, () => {
-                        window.location.href = "/";
-                    });
+                    lockScreen();
                     event.preventDefault();
                     event.stopPropagation();
                     break;

+ 2 - 5
app/src/util/globalShortcut.ts

@@ -47,6 +47,7 @@ import {webFrame} from "electron";
 /// #endif
 import {openHistory} from "../history/history";
 import {openCard} from "../card/openCard";
+import {lockScreen} from "../dialog/processSystem";
 
 const getRightBlock = (element: HTMLElement, x: number, y: number) => {
     let index = 1;
@@ -534,11 +535,7 @@ export const globalShortcut = () => {
             return;
         }
         if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
-            exportLayout(false, () => {
-                fetchPost("/api/system/logoutAuth", {}, () => {
-                    window.location.href = "/";
-                });
-            });
+            lockScreen()
             event.preventDefault();
             return;
         }