Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Vanessadb6932c15777
diff --git a/app/electron/main.js b/app/electron/main.js
index b9a265df8f..c3f277e6fc 100644
--- a/app/electron/main.js
+++ b/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,
diff --git a/app/src/constants.ts b/app/src/constants.ts
index e82540e0a2..61cf0b31b8 100644
--- a/app/src/constants.ts
+++ b/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";
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts
index 9edab4f468..af20f6adfe 100644
--- a/app/src/dialog/processSystem.ts
+++ b/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>
diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts
index f9b248a69c..b6e20b3465 100644
--- a/app/src/layout/status.ts
+++ b/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") {
diff --git a/app/src/mobile/util/menu.ts b/app/src/mobile/util/menu.ts
index 6fb8afa877..aa95eebb6c 100644
--- a/app/src/mobile/util/menu.ts
+++ b/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;
diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts
index 065e25977f..f9cad2c50c 100644
--- a/app/src/util/globalShortcut.ts
+++ b/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;
}