From 225dfbf50512dbf61b07e84e5de4553e1454929d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 4 Sep 2023 10:06:15 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9087 --- app/electron/main.js | 8 ++++++++ app/src/config/about.ts | 4 +++- app/src/constants.ts | 2 +- app/src/window/onWindowsMsg.ts | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index 7a3c4046e04..b3bfc3b8735 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -1024,3 +1024,11 @@ powerMonitor.on("shutdown", () => { net.fetch(getServer(currentURL.port) + "/api/system/exit", {method: "POST"}); }); }); + + +powerMonitor.on("lock-screen", () => { + writeLog("system lock-screen"); + BrowserWindow.getAllWindows().forEach(item => { + item.webContents.send("siyuan-send_windows", {cmd: "lockscreenByMode"}); + }); +}); diff --git a/app/src/config/about.ts b/app/src/config/about.ts index c141fdd7bfd..ecf4a12f424 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -312,7 +312,9 @@ export const about = { }); const lockScreenModeElement = about.element.querySelector("#lockScreenMode") as HTMLInputElement; lockScreenModeElement.addEventListener("change", () => { - fetchPost("/api/system/setFollowSystemLockScreen", {lockScreenMode: lockScreenModeElement.checked ? 1 : 0}); + fetchPost("/api/system/setFollowSystemLockScreen", {lockScreenMode: lockScreenModeElement.checked ? 1 : 0}, () => { + window.siyuan.config.system.lockScreenMode = lockScreenModeElement.checked ? 1 : 0; + }); }); const googleAnalyticsElement = about.element.querySelector("#googleAnalytics") as HTMLInputElement; googleAnalyticsElement.addEventListener("change", () => { diff --git a/app/src/constants.ts b/app/src/constants.ts index 26c220f6672..ed4485c0d22 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -32,7 +32,7 @@ export abstract class Constants { public static readonly SIYUAN_INIT: string = "siyuan-init"; public static readonly SIYUAN_OPENURL: string = "siyuan-openurl"; public static readonly SIYUAN_OPENWINDOW: string = "siyuan-openwindow"; - public static readonly SIYUAN_SEND_WINDOWS: string = "siyuan-send_windows"; // 主窗口和各新窗口之间的通信,{cmd: "closetab"|"lockscreen", data: {}}) + public static readonly SIYUAN_SEND_WINDOWS: string = "siyuan-send_windows"; // 主窗口和各新窗口之间的通信,{cmd: "closetab"|"lockscreen"|"lockscreenByMode", data: {}}) public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close"; public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf"; public static readonly SIYUAN_EXPORT_CLOSE: string = "siyuan-export-close"; diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.ts index d065482846a..d39b67fd05f 100644 --- a/app/src/window/onWindowsMsg.ts +++ b/app/src/window/onWindowsMsg.ts @@ -26,5 +26,19 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => { } }); break; + case "lockscreenByMode": + if (window.siyuan.config.system.lockScreenMode === 1) { + exportLayout({ + reload: false, + onlyData: false, + errorExit: false, + cb() { + fetchPost("/api/system/logoutAuth", {}, () => { + redirectToCheckAuth(); + }); + } + }); + } + break; } };