From 448b04abf855d01e2f39ce02fdf2826c017a7fcf Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 2 Mar 2026 18:18:09 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/17065 --- app/src/dialog/processSystem.ts | 8 +------- app/src/index.ts | 5 ++++- app/src/mobile/util/onMessage.ts | 4 ++++ app/src/util/pathName.ts | 21 ++++++++++++++++++++- app/src/window/index.ts | 5 ++++- app/src/window/onWindowsMsg.ts | 19 +------------------ 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 016d6c636..7d30e01ef 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -240,13 +240,7 @@ export const lockScreen = (app: App) => { app.plugins.forEach(item => { item.eventBus.emit("lock-screen"); }); - /// #if BROWSER - fetchPost("/api/system/logoutAuth", {}, () => { - redirectToCheckAuth(); - }); - /// #else - ipcRenderer.send(Constants.SIYUAN_SEND_WINDOWS, {cmd: "lockscreen"}); - /// #endif + fetchPost("/api/system/logoutAuth"); }; export const kernelError = () => { diff --git a/app/src/index.ts b/app/src/index.ts index 3c6a1a927..22d432c36 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -7,7 +7,7 @@ import {account} from "./config/account"; import {addScript, addScriptSync} from "./protyle/util/addScript"; import {genUUID} from "./util/genID"; import {fetchGet, fetchPost} from "./util/fetch"; -import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "./util/pathName"; +import {addBaseURL, getIdFromSYProtocol, isSYProtocol, redirectToCheckAuth, setNoteBook} from "./util/pathName"; import {registerServiceWorker} from "./util/serviceWorker"; import {openFileById} from "./editor/util"; import { @@ -75,6 +75,9 @@ export class App { }); if (data) { switch (data.cmd) { + case "logoutAuth": + redirectToCheckAuth(); + break; case "setAppearance": updateAppearance(data.data); break; diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts index b8d3a2ab1..28d3814b5 100644 --- a/app/src/mobile/util/onMessage.ts +++ b/app/src/mobile/util/onMessage.ts @@ -11,6 +11,7 @@ import {reloadEmoji} from "../../emoji"; import {setLocalShorthandCount} from "../../util/noRelyPCFunction"; import {updateControlAlt} from "../../protyle/util/hotKey"; import {renderSnippet} from "../../config/util/snippets"; +import {redirectToCheckAuth} from "../../util/pathName"; let statusTimeout: number; const statusElement = document.querySelector("#status") as HTMLElement; @@ -18,6 +19,9 @@ const statusElement = document.querySelector("#status") as HTMLElement; export const onMessage = (app: App, data: IWebSocketData) => { if (data) { switch (data.cmd) { + case "logoutAuth": + redirectToCheckAuth(); + break; case "sendDeviceNotification": if (window.JSAndroid.sendNotification) { window.JSAndroid.sendNotification(data.data.title, data.data.body); diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index 12e9658b7..cc73bacb2 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -9,11 +9,15 @@ import {Constants} from "../constants"; /// #if !BROWSER import {ipcRenderer} from "electron"; /// #endif +/// #if !MOBILE +import {exportLayout} from "../layout/util"; +/// #endif import {showMessage} from "../dialog/message"; import {isOnlyMeta, isWindows, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; import {matchHotKey} from "../protyle/util/hotKey"; import {Menu} from "../plugin/Menu"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; +import {saveScroll} from "../protyle/scroll/saveScroll"; export const useShell = (cmd: "showItemInFolder" | "openPath", filePath: string) => { /// #if !BROWSER @@ -60,11 +64,26 @@ export const getIdFromSYProtocol = (url: string) => { }; /* redirect to auth page */ -export const redirectToCheckAuth = (to: string = window.location.href) => { +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/index.ts b/app/src/window/index.ts index 5716e267b..c993142e0 100644 --- a/app/src/window/index.ts +++ b/app/src/window/index.ts @@ -6,7 +6,7 @@ import {initBlockPopover} from "../block/popover"; import {addScript, addScriptSync} from "../protyle/util/addScript"; import {genUUID} from "../util/genID"; import {fetchGet, fetchPost} from "../util/fetch"; -import {addBaseURL, setNoteBook} from "../util/pathName"; +import {addBaseURL, redirectToCheckAuth, setNoteBook} from "../util/pathName"; import {openFileById} from "../editor/util"; import { processSync, @@ -58,6 +58,9 @@ class App { }); if (data) { switch (data.cmd) { + case "logoutAuth": + redirectToCheckAuth(); + break; case "setAppearance": updateAppearance(data.data); break; diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.ts index 267dea001..2e3d15188 100644 --- a/app/src/window/onWindowsMsg.ts +++ b/app/src/window/onWindowsMsg.ts @@ -36,26 +36,9 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => { }); } break; - case "lockscreen": - exportLayout({ - errorExit: false, - cb() { - fetchPost("/api/system/logoutAuth", {}, () => { - redirectToCheckAuth(); - }); - } - }); - break; case "lockscreenByMode": if (window.siyuan.config.system.lockScreenMode === 1) { - exportLayout({ - errorExit: false, - cb() { - fetchPost("/api/system/logoutAuth", {}, () => { - redirectToCheckAuth(); - }); - } - }); + redirectToCheckAuth(); } break; }