An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Store the desktop settings window preference in conf.json https://github.com/siyuan-note/siyuan/pull/20183
Jeffrey Chen8120c1c780cf
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.syindex 691cfc9dcf..43c77f61a4 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100906-0u4zfq3.sy@@ -6,7 +6,7 @@"id": "20200924100906-0u4zfq3","title": "Window and Tab","type": "doc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 2,"Properties": {"id": "20260809170000-fdf0e30",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1233,7 +1233,7 @@"HeadingLevel": 3,"Properties": {"id": "20260930192450-5l394sc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1251,12 +1251,12 @@"Type": "NodeParagraph","Properties": {"id": "20260930192450-jc5b7ix",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{"Type": "NodeText",- "Data": "The desktop client opens settings in an independent window by default. It can be moved, resized, and minimized. In "+ "Data": "The desktop client opens settings in the main window by default. In "},{"Type": "NodeTextMark",@@ -1283,7 +1283,7 @@},{"Type": "NodeText",- "Data": ", turn this switch off to open settings in the main window; the change applies the next time settings are opened. You can also open settings with the configured shortcut from a detached document window. You can keep it open while scrolling, switching, and editing documents. Opening settings again focuses the existing window. Setting changes synchronize with other windows in the same workspace. Bulk cleanup of unreferenced assets or databases and settings import temporarily block interaction while they run. The browser uses a settings dialog, and mobile uses a settings page. Legacy plugin settings open in their owning window and bring it to the foreground; plugins that opt in open in an independent window. In an independent settings window, press "+ "Data": ", turn this switch on to open settings in an independent window that can be moved, resized, and minimized; the change applies the next time settings are opened. You can also open settings with the configured shortcut from a detached document window. You can keep it open while scrolling, switching, and editing documents. Opening settings again focuses the existing window. Setting changes synchronize with other windows in the same workspace. Bulk cleanup of unreferenced assets or databases and settings import temporarily block interaction while they run. The browser uses a settings dialog, and mobile uses a settings page. Legacy plugin settings open in their owning window and bring it to the foreground; plugins that opt in open in an independent window. In an independent settings window, press "},{"Type": "NodeTextMark",diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.syindex 8d83b5197c..ecb9e698db 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200822191536-rm6hwid.sy@@ -6,7 +6,7 @@"id": "20200822191536-rm6hwid","title": "窗口和页签","type": "doc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 2,"Properties": {"id": "20260809170000-d150748",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1237,7 +1237,7 @@"HeadingLevel": 3,"Properties": {"id": "20260930192450-4myh8mr",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1255,12 +1255,12 @@"Type": "NodeParagraph","Properties": {"id": "20260930192450-lqv7jpo",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{"Type": "NodeText",- "Data": "桌面客户端默认在独立窗口中打开设置,可以移动、调整大小和最小化。通过 "+ "Data": "桌面客户端默认在主窗口中打开设置。通过 "},{"Type": "NodeTextMark",@@ -1287,7 +1287,7 @@},{"Type": "NodeText",- "Data": " 开关可控制是否在独立窗口中打开设置界面;关闭后在主窗口内打开,下次打开设置界面时生效。文档新窗口也支持使用已配置的设置快捷键打开设置。保持设置窗口打开时,仍可滚动、切换和编辑文档。再次打开设置会聚焦已有窗口。配置修改会同步到当前工作空间的其他窗口;批量清理未引用附件、清理未引用数据库和导入配置期间会临时阻塞操作。浏览器端使用设置对话框,移动端使用设置页面。旧插件设置在其所属窗口中打开,并将该窗口切到前台;适配独立窗口的插件则在新窗口中打开。在设置独立窗口中,可按 "+ "Data": " 开关可控制是否在独立窗口中打开设置界面,开启后可以移动、调整大小和最小化;下次打开设置界面时生效。文档新窗口也支持使用已配置的设置快捷键打开设置。保持设置窗口打开时,仍可滚动、切换和编辑文档。再次打开设置会聚焦已有窗口。配置修改会同步到当前工作空间的其他窗口;批量清理未引用附件、清理未引用数据库和导入配置期间会临时阻塞操作。浏览器端使用设置对话框,移动端使用设置页面。旧插件设置在其所属窗口中打开,并将该窗口切到前台;适配独立窗口的插件则在新窗口中打开。在设置独立窗口中,可按 "},{"Type": "NodeTextMark",diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.syindex eb93df3408..c2bc8537ea 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123216-tlxw66f.sy@@ -6,7 +6,7 @@"id": "20211226123216-tlxw66f","title": "視窗和分頁","type": "doc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -44,7 +44,7 @@"HeadingLevel": 2,"Properties": {"id": "20260809170000-3a8f750",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1237,7 +1237,7 @@"HeadingLevel": 3,"Properties": {"id": "20260930192450-1xrty7u",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1255,12 +1255,12 @@"Type": "NodeParagraph","Properties": {"id": "20260930192450-635bol5",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{"Type": "NodeText",- "Data": "桌面用戶端預設在獨立視窗中開啟設定,可以移動、調整大小及最小化。透過 "+ "Data": "桌面用戶端預設在主視窗中開啟設定。透過 "},{"Type": "NodeTextMark",@@ -1287,7 +1287,7 @@},{"Type": "NodeText",- "Data": " 開關可控制是否在獨立視窗中開啟設定介面;關閉後在主視窗內開啟,下次開啟設定介面時生效。文件新視窗也支援使用已設定的設定快捷鍵開啟設定。保持設定視窗開啟時,仍可捲動、切換及編輯文件。再次開啟設定會聚焦已有視窗。設定變更會同步至目前工作空間的其他視窗;批次清理未引用附件、清理未引用資料庫及匯入設定期間會暫時阻擋操作。瀏覽器版使用設定對話框,行動版使用設定頁面。舊版外掛程式的設定會在其所屬視窗中開啟,並將該視窗切到前景;支援獨立視窗的外掛程式則在新視窗中開啟。在獨立設定視窗中,可按 "+ "Data": " 開關可控制是否在獨立視窗中開啟設定介面,開啟後可以移動、調整大小及最小化;下次開啟設定介面時生效。文件新視窗也支援使用已設定的設定快捷鍵開啟設定。保持設定視窗開啟時,仍可捲動、切換及編輯文件。再次開啟設定會聚焦已有視窗。設定變更會同步至目前工作空間的其他視窗;批次清理未引用附件、清理未引用資料庫及匯入設定期間會暫時阻擋操作。瀏覽器版使用設定對話框,行動版使用設定頁面。舊版外掛程式的設定會在其所屬視窗中開啟,並將該視窗切到前景;支援獨立視窗的外掛程式則在新視窗中開啟。在獨立設定視窗中,可按 "},{"Type": "NodeTextMark",diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.syindex dd90fa2919..2e4c45df6b 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-7yv4y5z.sy@@ -7,7 +7,7 @@"id": "20240530101000-7yv4y5z","title": "ウィンドウとタブ","type": "doc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -45,7 +45,7 @@"HeadingLevel": 2,"Properties": {"id": "20260809170000-5b80d49",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1242,7 +1242,7 @@"HeadingLevel": 3,"Properties": {"id": "20260930192450-sbtyvdc",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{@@ -1260,12 +1260,12 @@"Type": "NodeParagraph","Properties": {"id": "20260930192450-wdavx3g",- "updated": "20261001054930"+ "updated": "20261007101500"},"Children": [{"Type": "NodeText",- "Data": "デスクトップクライアントでは、設定は既定で独立したウィンドウで開き、移動、サイズ変更、最小化ができます。"+ "Data": "デスクトップクライアントでは、設定は既定でメインウィンドウ内で開きます。"},{"Type": "NodeTextMark",@@ -1292,7 +1292,7 @@},{"Type": "NodeText",- "Data": " をオフにすると、メインウィンドウ内で設定が開きます。変更は次回設定画面を開くときに適用されます。独立したドキュメントウィンドウからも、設定済みのショートカットで設定を開けます。設定を開いたまま、ドキュメントのスクロール、切り替え、編集ができます。設定を再度開くと、既存のウィンドウにフォーカスします。設定の変更は同じワークスペースのほかのウィンドウにも反映されます。未参照の添付ファイルやデータベースの一括削除、設定のインポート中は操作が一時的にブロックされます。ブラウザー版では設定ダイアログ、モバイル版では設定ページを使用します。従来のプラグイン設定は元のウィンドウで開き、そのウィンドウを最前面に表示します。独立した設定ウィンドウに対応したプラグインは、新しいウィンドウで開きます。独立した設定ウィンドウでは、"+ "Data": " をオンにすると、設定は独立したウィンドウで開き、移動、サイズ変更、最小化ができます。変更は次回設定画面を開くときに適用されます。独立したドキュメントウィンドウからも、設定済みのショートカットで設定を開けます。設定を開いたまま、ドキュメントのスクロール、切り替え、編集ができます。設定を再度開くと、既存のウィンドウにフォーカスします。設定の変更は同じワークスペースのほかのウィンドウにも反映されます。未参照の添付ファイルやデータベースの一括削除、設定のインポート中は操作が一時的にブロックされます。ブラウザー版では設定ダイアログ、モバイル版では設定ページを使用します。従来のプラグイン設定は元のウィンドウで開き、そのウィンドウを最前面に表示します。独立した設定ウィンドウに対応したプラグインは、新しいウィンドウで開きます。独立した設定ウィンドウでは、"},{"Type": "NodeTextMark",diff --git a/app/src/config/index.ts b/app/src/config/index.tsindex 4f93e1845d..229201dffd 100644--- a/app/src/config/index.ts+++ b/app/src/config/index.ts@@ -26,7 +26,6 @@ import {getHostCapabilities} from "../util/hostCapabilities";import {unmountWorkspaceStorage} from "./tabs/workspaceStorage";/// #if !MOBILEimport {openNativeSettings} from "./setting/nativeWindow";-import {getSettingsWindowMode} from "./setting/windowMode";import {isSettingsWindow} from "./setting/windowContext";import {fitSettingsWindowDialog} from "./setting/windowDialog";/// #endif@@ -143,7 +142,8 @@ export const openSetting = (app: App, tab?: TSettingTab, options?: {aiProvider?:if (aiProvider === "chatgpt") { openChatGPTProvider(); }/// #else/// #if !BROWSER- if (!isSettingsWindow() && getSettingsWindowMode() === 1) {+ // 是否在独立窗口中打开设置界面,仅桌面端 Electron 客户端生效+ if (!isSettingsWindow() && window.siyuan.config.system.settingsWindow) {void openNativeSettings(app, aiProvider ? {tab, aiProvider} : {tab});return;}@@ -207,7 +207,7 @@ export const openBazaarReadme = async (app: App, bazaarType: TBazaarType, itemNa}/// #if !BROWSER && !MOBILE- if (!isSettingsWindow() && getSettingsWindowMode() === 1) {+ if (!isSettingsWindow() && window.siyuan.config.system.settingsWindow) {await openNativeSettings(app, {tab: "bazaar", readme: {type: bazaarType, from, resource}});return;}diff --git a/app/src/config/setting/windowMode.test.ts b/app/src/config/openSetting.test.tssimilarity index 69%rename from app/src/config/setting/windowMode.test.tsrename to app/src/config/openSetting.test.tsindex 1d4ff1a1ca..05be02cdca 100644--- a/app/src/config/setting/windowMode.test.ts+++ b/app/src/config/openSetting.test.ts@@ -1,77 +1,73 @@import * as assert from "node:assert/strict";import {readFileSync} from "node:fs";+import {resolve} from "node:path";import {test} from "node:test";import {runInNewContext} from "node:vm";import {createSourceFile, isVariableStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";const {parse} = require("ifdef-loader/preprocessor");+// openSetting / openBazaarReadme 按工作空间偏好决定默认打开位置:独立窗口或主窗口内对话框const fixture = (browser = false, mobile = false) => {- const storage: Record<string, unknown> = {};- const saved: unknown[] = [];const calls: unknown[][] = [];- const source = readFileSync("src/config/setting/windowMode.ts", "utf8");- const mode = {} as {getSettingsWindowMode: () => number; setSettingsWindowMode: (value: unknown) => void};- const compilerOptions = {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021};- runInNewContext(transpileModule(source, {compilerOptions}).outputText, {- exports: mode, window: {siyuan: {storage}}, require: () => ({- Constants: {LOCAL_SETTINGS_WINDOW_MODE: "mode"}, setStorageVal: (...args: unknown[]) => saved.push(args),- }),- });- const index = createSourceFile("index.ts", parse(readFileSync("src/config/index.ts", "utf8"),+ const system: Record<string, unknown> = {settingsWindow: false};+ const config = {bazaar: {trust: true}, system};+ const index = createSourceFile("index.ts", parse(readFileSync(resolve(process.cwd(), "src/config/index.ts"), "utf8"),{BROWSER: browser, MOBILE: mobile}, false, true), ScriptTarget.ES2021, true);const declarations = index.statements.filter(statement => isVariableStatement(statement) &&statement.declarationList.declarations.some(item => ["openSetting", "openBazaarReadme"].includes(item.name.getText(index))));const entry = {} as {openSetting: (app: unknown, tab?: string, options?: {aiProvider?: "chatgpt"}) => void;openBazaarReadme: (app: unknown, type: string, name: string, from: string) => Promise<void>};let native = false;- runInNewContext(transpileModule(declarations.map(item => item.getText(index)).join("\n"), {compilerOptions}).outputText, {- exports: entry, ...mode, isSettingsWindow: () => native,+ runInNewContext(transpileModule(declarations.map(item => item.getText(index)).join("\n"),+ {compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021}}).outputText, {+ exports: entry, isSettingsWindow: () => native,isBazaarAvailable: () => true, getHostCapabilities: () => ({documentImportExport: true}),openNativeSettings: (...args: unknown[]) => calls.push(["native", ...args]),openSettingDialog: (...args: unknown[]) => calls.push(["dialog", ...args]),openMobileSetting: (...args: unknown[]) => calls.push(["mobile", ...args]),openChatGPTProvider: () => calls.push(["chatgpt"]),- window: {siyuan: {dialogs: [{element: {getAttribute: () => "settings"}}], config: {bazaar: {trust: true}}}},+ window: {siyuan: {dialogs: [{element: {getAttribute: () => "settings"}}], config}},Constants: {DIALOG_SETTING: "settings"}, switchSettingTab: (...args: unknown[]) => calls.push(["switch", ...args]),fetchSyncPost: async () => ({code: 0, data: {packages: [{name: "plugin"}]}}),getFrontend: () => "desktop", withMountedBazaar: async () => calls.push(["readme"]),});- return {storage, saved, calls, mode, entry, setNative: () => { native = true; }};+ return {calls, entry,+ setPreference: (value: unknown) => { system.settingsWindow = value; },+ setNative: () => { native = true; }};};-test("settings mode defaults to a native window, persists valid choices and ignores invalid values", () => {- const f = fixture();- assert.equal(f.mode.getSettingsWindowMode(), 1);- for (const value of [null, false, "0", 2]) f.mode.setSettingsWindowMode(value);- assert.equal(f.saved.length, 0);- f.mode.setSettingsWindowMode(0);- assert.equal(f.mode.getSettingsWindowMode(), 0);- assert.equal(JSON.stringify(f.saved), JSON.stringify([["mode", 0]]));- f.mode.setSettingsWindowMode(1);- assert.equal(f.mode.getSettingsWindowMode(), 1);-});-test("settings and marketplace readmes follow the current workspace preference", async () => {const f = fixture();const app = {};f.entry.openSetting(app, "app");await f.entry.openBazaarReadme(app, "plugins", "plugin", "downloaded");- assert.deepEqual(f.calls.map(item => item[0]), ["native", "native"]);+ assert.deepEqual(f.calls.map(item => item[0]), ["dialog", "dialog", "readme"]);f.calls.length = 0;- f.storage.mode = 0;+ f.setPreference(true);f.entry.openSetting(app, "app");await f.entry.openBazaarReadme(app, "plugins", "plugin", "downloaded");- assert.deepEqual(f.calls.map(item => item[0]), ["dialog", "dialog", "readme"]);+ assert.deepEqual(f.calls.map(item => item[0]), ["native", "native"]);f.calls.length = 0;f.setNative();f.entry.openSetting(app, "app");assert.deepEqual(f.calls.map(item => item[0]), ["switch"]);});+test("only a truthy workspace preference opens the independent settings window", () => {+ for (const [stored, expected] of [[false, "dialog"], [0, "dialog"], ["", "dialog"],+ [true, "native"], [1, "native"]] as const) {+ const f = fixture();+ f.setPreference(stored);+ f.entry.openSetting({});+ assert.equal(f.calls[0][0], expected, `stored ${JSON.stringify(stored)}`);+ }+});+test("browser and mobile keep their own settings UI regardless of the native preference", () => {for (const [browser, mobile, expected] of [[true, false, "dialog"], [true, true, "mobile"]] as const) {const f = fixture(browser, mobile);+ f.setPreference(true);f.entry.openSetting({});assert.equal(f.calls[0][0], expected);}@@ -79,10 +75,11 @@ test("browser and mobile keep their own settings UI regardless of the native pretest("ChatGPT navigation reaches the native settings command and dialog entry", () => {const f = fixture();+ f.setPreference(true);f.entry.openSetting({}, "ai", {aiProvider: "chatgpt"});assert.equal(JSON.stringify(f.calls[0][2]), JSON.stringify({tab: "ai", aiProvider: "chatgpt"}));f.calls.length = 0;- f.storage.mode = 0;+ f.setPreference(false);f.entry.openSetting({}, "ai", {aiProvider: "chatgpt"});assert.deepEqual(f.calls.map(item => item[0]), ["dialog", "chatgpt"]);const mobile = fixture(true, true);diff --git a/app/src/config/setting/windowMode.ts b/app/src/config/setting/windowMode.tsdeleted file mode 100644index 7ac5045b13..0000000000--- a/app/src/config/setting/windowMode.ts+++ /dev/null@@ -1,10 +0,0 @@-import {Constants} from "../../constants";-import {setStorageVal} from "../../protyle/util/compatibility";--export const getSettingsWindowMode = () => window.siyuan.storage[Constants.LOCAL_SETTINGS_WINDOW_MODE] === 0 ? 0 : 1;--export const setSettingsWindowMode = (value: unknown) => {- if (value !== 0 && value !== 1) return;- window.siyuan.storage[Constants.LOCAL_SETTINGS_WINDOW_MODE] = value;- setStorageVal(Constants.LOCAL_SETTINGS_WINDOW_MODE, value);-};diff --git a/app/src/config/tabs/appRuntime.test.ts b/app/src/config/tabs/appRuntime.test.tsnew file mode 100644index 0000000000..c1cb6d91f4--- /dev/null+++ b/app/src/config/tabs/appRuntime.test.ts@@ -0,0 +1,59 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import {resolve} from "node:path";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";++const {parse} = require("ifdef-loader/preprocessor");++// sendAppSetting 只负责 submit 与本地回写;桌面分支的 ipc / 布局依赖在 BROWSER+MOBILE 下被裁剪+const fixture = () => {+ const posted: unknown[][] = [];+ const system: Record<string, unknown> = {};+ const api = {} as {sendAppSetting: (controlId: string, value: unknown) => void};+ const source = readFileSync(resolve(process.cwd(), "src/config/tabs/appRuntime.ts"), "utf8");+ runInNewContext(transpileModule(parse(source, {BROWSER: true, MOBILE: true}, false, true),+ {compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021}}).outputText, {+ exports: api,+ console: {warn: (): void => undefined},+ window: {siyuan: {config: {system}}},+ require: (name: string) => {+ if (name === "../../util/fetch") {+ return {fetchPost: (url: string, payload: unknown, cb?: () => void) => {+ posted.push([url, payload]);+ cb?.();+ }};+ }+ if (name === "../../constants") {+ return {Constants: {}};+ }+ if (name === "../../dialog/processSystem") {+ return {exitSiYuan: (): void => undefined};+ }+ throw new Error("unexpected module: " + name);+ },+ });+ return {posted, system, api};+};++test("settings window preference submits the boolean and mirrors it locally", () => {+ const f = fixture();+ f.api.sendAppSetting("system.settingsWindow", true);+ assert.equal(f.system.settingsWindow, true);+ f.api.sendAppSetting("system.settingsWindow", false);+ assert.equal(f.system.settingsWindow, false);+ f.api.sendAppSetting("system.settingsWindow", undefined);+ assert.equal(f.system.settingsWindow, false);+ assert.equal(JSON.stringify(f.posted), JSON.stringify([+ ["/api/system/setSettingsWindow", {settingsWindow: true}],+ ["/api/system/setSettingsWindow", {settingsWindow: false}],+ ["/api/system/setSettingsWindow", {settingsWindow: false}],+ ]));+});++test("unknown control ids are reported instead of silently posting", () => {+ const f = fixture();+ f.api.sendAppSetting("system.unknown", true);+ assert.equal(JSON.stringify(f.posted), "[]");+});diff --git a/app/src/config/tabs/appRuntime.ts b/app/src/config/tabs/appRuntime.tsindex dcc105bcf9..7d3266ad02 100644--- a/app/src/config/tabs/appRuntime.ts+++ b/app/src/config/tabs/appRuntime.ts@@ -73,6 +73,13 @@ export const sendAppSetting = (controlId: string, value: unknown) => {});break;}+ case "system.settingsWindow": {+ const settingsWindow = Boolean(value) as Config.ISystem["settingsWindow"];+ fetchPost("/api/system/setSettingsWindow", {settingsWindow}, () => {+ window.siyuan.config.system.settingsWindow = settingsWindow;+ });+ break;+ }default:console.warn(`[config] sendAppSetting: unhandled controlId "${controlId}"`);break;diff --git a/app/src/config/tabs/appTab.test.ts b/app/src/config/tabs/appTab.test.tsindex 928f1d39c6..03c0c83156 100644--- a/app/src/config/tabs/appTab.test.ts+++ b/app/src/config/tabs/appTab.test.ts@@ -67,7 +67,7 @@ test("settings window mode is configurable only in the Electron desktop client",for (const [browser, mobile] of [[false, false], [true, false], [true, true], [false, true]]) {const switches: string[] = [];getAccessibilitySlot(browser, mobile, undefined, "unused", switches);- assert.equal(switches.includes("settingsWindowMode"), !browser && !mobile);+ assert.equal(switches.includes("system.settingsWindow"), !browser && !mobile);}});diff --git a/app/src/config/tabs/appTab.ts b/app/src/config/tabs/appTab.tsindex 32c302c5fc..9a9f2d5ee1 100644--- a/app/src/config/tabs/appTab.ts+++ b/app/src/config/tabs/appTab.ts@@ -3,9 +3,6 @@ import {ipcRenderer} from "electron";import * as path from "path";/// #endifimport type {SettingTabBuilder} from "../setting/builder";-/// #if !BROWSER && !MOBILE-import {getSettingsWindowMode, setSettingsWindowMode} from "../setting/windowMode";-/// #endifimport {runSettingsMaintenance} from "../setting/maintenance";import {confirmResetSettings} from "../setting/reset";import {Constants} from "../../constants";@@ -194,11 +191,10 @@ const registerAppGeneralGroup = (tab: SettingTabBuilder) => {const group = tab.group("general", window.siyuan.languages.configGroupGeneral);/// #if !BROWSER && !MOBILE- group.switch("settingsWindowMode", {+ group.switch("system.settingsWindow", {title: window.siyuan.languages.settingsWindowMode,desc: window.siyuan.languages.settingsWindowModeTip,- readConfig: () => getSettingsWindowMode() === 1,- save: (value) => setSettingsWindowMode(value ? 1 : 0),+ save: (value) => sendAppSetting("system.settingsWindow", value),});/// #endif/// #if !BROWSERdiff --git a/app/src/constants.ts b/app/src/constants.tsindex 2526db5e4b..93193676ca 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -176,7 +176,6 @@ export abstract class Constants {// localstoragepublic static readonly LOCAL_ZOOM = "local-zoom";- public static readonly LOCAL_SETTINGS_WINDOW_MODE = "local-settings-window-mode";public static readonly LOCAL_SEARCHDATA = "local-searchdata";public static readonly LOCAL_SEARCHKEYS = "local-searchkeys";public static readonly LOCAL_SEARCHASSET = "local-searchasset";diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex 0109c6fdca..e137fec3c1 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -2088,6 +2088,8 @@ export type SettingVariables = { "items": Array<SettingVariable | null> | null;export type SettingVariablesInput = { "items"?: Array<SettingVariableInput | null> | null; };+export type SettingsWindowRequestInput = { "settingsWindow": boolean; };+export type Shorthand = { "hCreated": string; "oId": string; "shorthandContent": string; "shorthandDesc": string; "shorthandFrom": number; "shorthandMd": string; "shorthandTitle": string; "shorthandURL": string; };export type ShorthandPage = { "pagination": ShorthandPagination; "shorthands": Array<Shorthand | null>; };@@ -2290,7 +2292,7 @@ export type SystemStat = { "assetsSize": number; "blockCount": number; "cAssetsSexport type SystemSync = { "assetDownloadMode": number; "cloudName": string; "enabled": boolean; "generateConflictDoc": boolean; "interval": number; "lan": SystemLANSync | null; "local": SystemLocal | null; "mode": number; "perception": boolean; "provider": number; "s3": SystemS3 | null; "stat": string; "synced": number; "webdav": SystemWebDAV | null; };-export type SystemSystem = { "appDir": string; "autoLaunch2": number; "confDir": string; "container": string; "dataDir": string; "disabledFeatures": Array<string> | null; "downloadInstallPkg": boolean; "encryptedNotebookFollowSystemLock": boolean; "homeDir": string; "id": string; "isMicrosoftStore": boolean; "kernelVersion": string; "lockScreenMode": number; "microsoftDefenderExcluded": boolean; "name": string; "networkProxy": SystemNetworkProxy | null; "networkServe": boolean; "networkServeTLS": boolean; "os": string; "osPlatform": string; "safeMode": boolean; "updateChannel"?: string; "workspaceDir": string; };+export type SystemSystem = { "appDir": string; "autoLaunch2": number; "confDir": string; "container": string; "dataDir": string; "disabledFeatures": Array<string> | null; "downloadInstallPkg": boolean; "encryptedNotebookFollowSystemLock": boolean; "homeDir": string; "id": string; "isMicrosoftStore": boolean; "kernelVersion": string; "lockScreenMode": number; "microsoftDefenderExcluded": boolean; "name": string; "networkProxy": SystemNetworkProxy | null; "networkServe": boolean; "networkServeTLS": boolean; "os": string; "osPlatform": string; "safeMode": boolean; "settingsWindow": boolean; "updateChannel"?: string; "workspaceDir": string; };export type SystemTag = { "sort": number; };@@ -5804,6 +5806,11 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": SystemOIDC | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "structJSON";};+ "/api/system/setSettingsWindow": {+ request: SettingsWindowRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/system/setUILayout": {request: SystemUILayoutRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex 90b153bdd6..0ffa43e4d3 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -2103,6 +2103,11 @@ declare namespace Config {* Whether the current boot is in safe mode (disables code snippets, plugins, custom theme and icon)*/safeMode: boolean;+ /**+ * 是否在独立窗口中打开设置界面,仅桌面 Electron 客户端生效,默认 false。+ * 该工作空间偏好保存在 conf.json,不读取旧的 local-settings-window-mode;重置设置时恢复为 false。+ */+ settingsWindow: boolean;/*** The absolute path of the workspace directory*/diff --git a/kernel/api/contract_basics_test.go b/kernel/api/contract_basics_test.goindex 3e522ebb28..0a534189b8 100644--- a/kernel/api/contract_basics_test.go+++ b/kernel/api/contract_basics_test.go@@ -75,6 +75,7 @@ func TestAPIContractBasicRequests(t *testing.T) {{"/api/system/setNetworkServeTLS", `{"networkServeTLS":1}`, setNetworkServeTLS, -1},{"/api/system/setNetworkProxy", `{"scheme":"http","host":"host"}`, setNetworkProxy, -1},{"/api/system/setDownloadInstallPkg", `{"downloadInstallPkg":"true"}`, setDownloadInstallPkg, -1},+ {"/api/system/setSettingsWindow", `{"settingsWindow":"true"}`, setSettingsWindow, -1},{"/api/system/setUpdateChannel", `{"updateChannel":null}`, setUpdateChannel, -1},{"/api/setting/setEditorReadOnly", `{"readonly":1}`, setEditorReadOnly, -1},{"/api/setting/addVirtualBlockRefInclude", `{"keywords":[null]}`, addVirtualBlockRefInclude, -1},diff --git a/kernel/api/router.go b/kernel/api/router.goindex 03334294ee..363d371420 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -78,6 +78,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/system/importTLSCABundle", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, importTLSCABundle)ginServer.Handle("POST", "/api/system/setAutoLaunch", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setAutoLaunch)ginServer.Handle("POST", "/api/system/setDownloadInstallPkg", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setDownloadInstallPkg)+ ginServer.Handle("POST", "/api/system/setSettingsWindow", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSettingsWindow)ginServer.Handle("POST", "/api/system/setUpdateChannel", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setUpdateChannel)ginServer.Handle("POST", "/api/system/setNetworkProxy", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setNetworkProxy)ginServer.Handle("POST", "/api/system/setWorkspaceDir", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setWorkspaceDir)diff --git a/kernel/api/setting_patch.go b/kernel/api/setting_patch.goindex 8164f160f0..ad37af3527 100644--- a/kernel/api/setting_patch.go+++ b/kernel/api/setting_patch.go@@ -67,8 +67,8 @@ func additionalSettingNamespace(path string) string {case "/api/system/importConf":return "*"case "/api/system/setAutoLaunch", "/api/system/setFollowSystemLockScreen",- "/api/system/setDownloadInstallPkg", "/api/system/setUpdateChannel", "/api/system/setNetworkProxy",- "/api/system/setAPIToken", "/api/system/setAccessAuthCode", "/api/system/setOIDC":+ "/api/system/setDownloadInstallPkg", "/api/system/setSettingsWindow", "/api/system/setUpdateChannel",+ "/api/system/setNetworkProxy", "/api/system/setAPIToken", "/api/system/setAccessAuthCode", "/api/system/setOIDC":return "system"}if strings.HasPrefix(path, "/api/sync/set") {diff --git a/kernel/api/system.go b/kernel/api/system.goindex 4487adebae..d8d387f23c 100644--- a/kernel/api/system.go+++ b/kernel/api/system.go@@ -1338,6 +1338,12 @@ var setDownloadInstallPkg = contractHandler(apicontract.SetDownloadInstallPkg, freturn apicontract.Success(apicontract.Null{})})+var setSettingsWindow = contractHandler(apicontract.SetSettingsWindow, func(c *gin.Context, request apicontract.SettingsWindowRequest) apicontract.Response[apicontract.Null] {+ model.Conf.System.SettingsWindow = request.SettingsWindow+ model.Conf.Save()+ return apicontract.Success(apicontract.Null{})+})+var setUpdateChannel = contractHandler(apicontract.SetUpdateChannel, func(c *gin.Context, request apicontract.UpdateChannelRequest) apicontract.Response[apicontract.Null] {if err := model.SetUpdateChannel(request.UpdateChannel); err != nil {return apicontract.Failure[apicontract.Null](-1, err.Error())diff --git a/kernel/apicontract/basics.go b/kernel/apicontract/basics.goindex 4e7e9445f6..a72ee19e34 100644--- a/kernel/apicontract/basics.go+++ b/kernel/apicontract/basics.go@@ -40,6 +40,12 @@ type DownloadInstallPkgRequest struct {DownloadInstallPkg bool `json:"downloadInstallPkg"`}+// SettingsWindowRequest 更新工作空间的设置窗口偏好,接口要求管理员权限且禁止只读写入。+// settingsWindow 为必填布尔值;true 仅影响桌面 Electron 客户端,保存后通知 system 配置域。+type SettingsWindowRequest struct {+ SettingsWindow bool `json:"settingsWindow"`+}+type UpdateChannelRequest struct {UpdateChannel string `json:"updateChannel"`}diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex fd559b98bc..b05c990f46 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -271,6 +271,7 @@ var (SetFollowSystemLockScreen = define[LockScreenRequest, Null]("setFollowSystemLockScreen", "/api/system/setFollowSystemLockScreen", JSONBody, ResponseOptions{}, "POST")SetAutoLaunch = define[AutoLaunchRequest, Null]("setAutoLaunch", "/api/system/setAutoLaunch", JSONBody, ResponseOptions{}, "POST")SetDownloadInstallPkg = define[DownloadInstallPkgRequest, Null]("setDownloadInstallPkg", "/api/system/setDownloadInstallPkg", JSONBody, ResponseOptions{}, "POST")+ SetSettingsWindow = define[SettingsWindowRequest, Null]("setSettingsWindow", "/api/system/setSettingsWindow", JSONBody, ResponseOptions{}, "POST")SetNetworkServe = define[NetworkServeRequest, Null]("setNetworkServe", "/api/system/setNetworkServe", JSONBody, ResponseOptions{}, "POST")SetNetworkServeTLS = define[NetworkServeTLSRequest, Null]("setNetworkServeTLS", "/api/system/setNetworkServeTLS", JSONBody, ResponseOptions{}, "POST")SetUpdateChannel = define[UpdateChannelRequest, Null]("setUpdateChannel", "/api/system/setUpdateChannel", JSONBody, ResponseOptions{}, "POST")diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.jsonindex c9f00e2e7c..acf7bb1c8e 100644--- a/kernel/apicontract/schema.json+++ b/kernel/apicontract/schema.json@@ -48347,6 +48347,18 @@},"additionalProperties": false},+ "SettingsWindowRequestInput": {+ "type": "object",+ "properties": {+ "settingsWindow": {+ "type": "boolean"+ }+ },+ "required": [+ "settingsWindow"+ ],+ "additionalProperties": false+ },"Shorthand": {"type": "object","properties": {@@ -51557,6 +51569,9 @@"safeMode": {"type": "boolean"},+ "settingsWindow": {+ "type": "boolean"+ },"updateChannel": {"type": "string"},@@ -51586,6 +51601,7 @@"os","osPlatform","safeMode",+ "settingsWindow","workspaceDir"],"additionalProperties": false@@ -166811,6 +166827,81 @@]}},+ {+ "method": "POST",+ "path": "/api/system/setSettingsWindow",+ "handler": "setSettingsWindow",+ "body": "json",+ "request": {+ "$ref": "#/$defs/SettingsWindowRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/system/setUILayout",diff --git a/kernel/apicontract/system_conf.go b/kernel/apicontract/system_conf.goindex c7a5c6e5c4..d1fdb717d5 100644--- a/kernel/apicontract/system_conf.go+++ b/kernel/apicontract/system_conf.go@@ -135,6 +135,8 @@ type SystemSystem struct {DisabledFeatures []string `json:"disabledFeatures" api:"optional,nullable"`MicrosoftDefenderExcluded bool `json:"microsoftDefenderExcluded" api:"optional,nullable"`SafeMode bool `json:"safeMode" api:"optional,nullable"`+ // 独立设置窗口默认关闭,不读取旧的本地存储偏好;重置设置时恢复为 false。+ SettingsWindow bool `json:"settingsWindow" api:"optional,nullable"`}type SystemNetworkProxy struct {diff --git a/kernel/conf/system.go b/kernel/conf/system.goindex 51ae3802ee..0f00b4a2c7 100644--- a/kernel/conf/system.go+++ b/kernel/conf/system.go@@ -43,6 +43,7 @@ type System struct {UpdateChannel string `json:"updateChannel,omitempty"`AutoLaunch2 int `json:"autoLaunch2"` // 0:不自动启动,1:自动启动,2:自动启动+隐藏主窗口LockScreenMode int `json:"lockScreenMode"` // 0:手动,1:手动+跟随系统 https://github.com/siyuan-note/siyuan/issues/9087+ SettingsWindow bool `json:"settingsWindow"` // 是否在独立窗口中打开设置界面,仅桌面端生效EncryptedNotebookFollowSystemLock bool `json:"encryptedNotebookFollowSystemLock"` // 系统锁屏时锁定加密笔记本,默认关闭diff --git a/kernel/model/settings_reset.go b/kernel/model/settings_reset.goindex 9c3bf6dbac..f18350eb93 100644--- a/kernel/model/settings_reset.go+++ b/kernel/model/settings_reset.go@@ -17,7 +17,7 @@ import (// 仅清理内置偏好;保存的布局、插件数据、最近记录和未知键保持不变。var resetSettingsStorageKeys = []string{- "local-zoom", "local-settings-window-mode", "local-searchdata", "local-searchasset", "local-searchunref",+ "local-zoom", "local-searchdata", "local-searchasset", "local-searchunref","local-exportpdf", "local-exportword", "local-exportimg", "local-pdftheme", "local-flashcard","local-mobile-bars", "local-mobile-bottom-bar", "local-mobile-side-panel", "local-outline","local-fileposition", "local-dialogposition",@@ -64,6 +64,7 @@ func defaultWorkspaceSettings(current *AppConf) *AppConf {if current.System != nil {system := *current.Systemsystem.DownloadInstallPkg = conf.NewSystem().DownloadInstallPkg+ system.SettingsWindow = falsenext.System = &system}return &next@@ -119,6 +120,7 @@ func ResetSettings() error {Conf.UILayout, Conf.Keymap = next.UILayout, next.Keymapif Conf.System != nil {Conf.System.DownloadInstallPkg = next.System.DownloadInstallPkg+ Conf.System.SettingsWindow = next.System.SettingsWindow}return nil}diff --git a/kernel/model/settings_reset_test.go b/kernel/model/settings_reset_test.goindex 75eeb4463e..2b13f2cf8d 100644--- a/kernel/model/settings_reset_test.go+++ b/kernel/model/settings_reset_test.go@@ -69,6 +69,7 @@ func TestSettingsResetPreservesDataAndProtectedConfiguration(t *testing.T) {Conf.System.LockScreenMode = 1Conf.System.EncryptedNotebookFollowSystemLock = trueConf.System.DownloadInstallPkg = false+ Conf.System.SettingsWindow = trueutil.MarkdownSettings = util.NewMarkdown()util.MarkdownSettings.InlineMath = falseutil.UseSingleLineSave, util.LargeFileWarningSize = false, 64@@ -105,6 +106,9 @@ func TestSettingsResetPreservesDataAndProtectedConfiguration(t *testing.T) {Conf.System.NetworkProxy.Host != "proxy" || Conf.System.LockScreenMode != 1 || !Conf.System.EncryptedNotebookFollowSystemLock {t.Fatal("host, networking and authentication settings changed")}+ if Conf.System.SettingsWindow {+ t.Fatal("desktop settings window preference must be reset to its default")+ }if !reflect.DeepEqual((*Conf.Keymap)["plugin"], keymap["plugin"]) || (*Conf.Keymap)["general"] != nil {t.Fatal("only built-in shortcuts should be reset")}