Vanessa 2026-03-02 18:18:09 +08:00
parent 8c02c2cb93
commit 448b04abf8
6 changed files with 34 additions and 28 deletions

View file

@ -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 = () => {

View file

@ -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;

View file

@ -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);

View file

@ -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 = () => {

View file

@ -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;

View file

@ -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;
}