diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index efd9aa0c2..68f60c396 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -202,7 +202,7 @@ export const initWindow = async (app: App) => { } }); ipcRenderer.on(Constants.SIYUAN_SEND_WINDOWS, (e, ipcData: IWebSocketData) => { - onWindowsMsg(ipcData); + onWindowsMsg(ipcData, app); }); ipcRenderer.on(Constants.SIYUAN_HOTKEY, (e, data) => { let matchCommand = false; diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index b1bde49df..9a5372aae 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -233,14 +233,27 @@ export const setDefRefCount = (data: { } }; -export const lockScreen = (app: App) => { +export const lockScreen = async (app: App) => { if (window.siyuan.config.readonly) { return; } app.plugins.forEach(item => { item.eventBus.emit("lock-screen"); }); - fetchPost("/api/system/logoutAuth"); + /// #if !MOBILE + exportLayout({ + errorExit: false, + cb() { + fetchPost("/api/system/logoutAuth"); + } + }); + /// #else + if (window.siyuan.mobile.editor) { + await saveScroll(window.siyuan.mobile.editor.protyle); + fetchPost("/api/system/logoutAuth"); + } + /// #endif + }; export const kernelError = () => { diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index cc73bacb2..23a1de1a4 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -65,25 +65,10 @@ export const getIdFromSYProtocol = (url: string) => { /* redirect to auth page */ export const redirectToCheckAuth = async (to: string = window.location.href) => { - /// #if !MOBILE - exportLayout({ - errorExit: false, - cb() { - const url = new URL(window.location.origin); - url.pathname = "/check-auth"; - url.searchParams.set("to", to); - window.location.href = url.href; - } - }); - /// #else - if (window.siyuan.mobile.editor) { - await saveScroll(window.siyuan.mobile.editor.protyle); - } const url = new URL(window.location.origin); url.pathname = "/check-auth"; url.searchParams.set("to", to); window.location.href = url.href; - /// #endif }; export const addBaseURL = () => { diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.ts index 950651470..91870ff70 100644 --- a/app/src/window/onWindowsMsg.ts +++ b/app/src/window/onWindowsMsg.ts @@ -1,7 +1,8 @@ import {getInstanceById} from "../layout/util"; import {Tab} from "../layout/Tab"; -import {redirectToCheckAuth} from "../util/pathName"; import {isWindow} from "../util/functions"; +import {lockScreen} from "../dialog/processSystem"; +import {App} from "../index"; const closeTab = (ipcData: IWebSocketData) => { const tab = getInstanceById(ipcData.data); @@ -9,7 +10,7 @@ const closeTab = (ipcData: IWebSocketData) => { tab.parent.removeTab(ipcData.data); } }; -export const onWindowsMsg = (ipcData: IWebSocketData) => { +export const onWindowsMsg = (ipcData: IWebSocketData, app: App) => { switch (ipcData.cmd) { case "closetab": closeTab(ipcData); @@ -37,7 +38,7 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => { break; case "lockscreenByMode": if (window.siyuan.config.system.lockScreenMode === 1) { - redirectToCheckAuth(); + lockScreen(app); } break; }