Skip to content

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

:recycle: Align window layout IPC commands with SiYuan naming https://github.com/siyuan-note/siyuan/issues/10809

Vanessa7d657573bd68
diff --git a/app/electron/main.js b/app/electron/main.js
index 9eb4ae7c82..0f7e330615 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -3342,19 +3342,20 @@ app.whenReady().then(() => {
if (data.cmd === "getContentsId") {
return event.sender.id;
}
- if (["setWindowWorkspace", "focusWindowWorkspace", "getOpenWindowWorkspaces", "flushWindowWorkspaces"].includes(data.cmd)) {
+ if (["siyuan-window-workspace-set", "siyuan-window-workspace-focus", "siyuan-window-workspace-get-open",
+ "siyuan-window-workspace-flush-all"].includes(data.cmd)) {
const kernelTarget = getWindowKernelTarget(event.sender.id);
if (!kernelTarget) {
return false;
}
- if (data.cmd === "getOpenWindowWorkspaces") {
+ if (data.cmd === "siyuan-window-workspace-get-open") {
return windowWorkspaces.list(kernelTarget.origin);
}
- if (data.cmd === "flushWindowWorkspaces") {
+ if (data.cmd === "siyuan-window-workspace-flush-all") {
return flushWindowWorkspaces(windowWorkspaces.list(kernelTarget.origin)
.map(id => windowWorkspaces.get(kernelTarget.origin, id)).filter(Boolean), ipcMain);
}
- if (data.cmd === "focusWindowWorkspace") {
+ if (data.cmd === "siyuan-window-workspace-focus") {
const window = windowWorkspaces.get(kernelTarget.origin, data.id);
if (window) {
showWindow(window);
diff --git a/app/electron/windowWorkspaces.js b/app/electron/windowWorkspaces.js
index 89dda97004..10d5a928dd 100644
--- a/app/electron/windowWorkspaces.js
+++ b/app/electron/windowWorkspaces.js
@@ -79,7 +79,7 @@ const flushWindowWorkspaces = (windows, ipcMain, timeoutMs = 11000) => {
ipcMain.on("siyuan-window-workspace-saved", onSaved);
contents.forEach(content => {
try {
- content.send("siyuan-send-windows", {cmd: "flushWindowWorkspace", data: id});
+ content.send("siyuan-send-windows", {cmd: "siyuan-window-workspace-flush", data: id});
} catch {
finish(false);
}
diff --git a/app/electron/windowWorkspaces.test.js b/app/electron/windowWorkspaces.test.js
index 8c53ea7430..d9620566a6 100644
--- a/app/electron/windowWorkspaces.test.js
+++ b/app/electron/windowWorkspaces.test.js
@@ -77,7 +77,7 @@ test("退出前等待所有窗口保存,忽略其他窗口和子帧的确认",
respond(1, true);
assert.equal(await task, true);
assert.equal(ipc.listenerCount("siyuan-window-workspace-saved"), 0);
- assert.equal(messages[0].cmd, "flushWindowWorkspace");
+ assert.equal(messages[0].cmd, "siyuan-window-workspace-flush");
});
test("保存失败或窗口无响应时取消退出并清理监听器", async () => {
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 2cae015a0d..66e835add6 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -39,12 +39,10 @@ export abstract class Constants {
public static readonly SIYUAN_EVENT: string = "siyuan-event";
public static readonly SIYUAN_WINDOW_WORKSPACE_SAVED = "siyuan-window-workspace-saved";
- // 新窗口布局操作
- public static readonly WINDOW_WORKSPACE_SET = "setWindowWorkspace";
- public static readonly WINDOW_WORKSPACE_FOCUS = "focusWindowWorkspace";
- public static readonly WINDOW_WORKSPACE_GET_OPEN = "getOpenWindowWorkspaces";
- public static readonly WINDOW_WORKSPACE_FLUSH_ALL = "flushWindowWorkspaces";
- public static readonly WINDOW_WORKSPACE_FLUSH = "flushWindowWorkspace";
+ public static readonly SIYUAN_WINDOW_WORKSPACE_SET = "siyuan-window-workspace-set";
+ public static readonly SIYUAN_WINDOW_WORKSPACE_FOCUS = "siyuan-window-workspace-focus";
+ public static readonly SIYUAN_WINDOW_WORKSPACE_GET_OPEN = "siyuan-window-workspace-get-open";
+ public static readonly SIYUAN_WINDOW_WORKSPACE_FLUSH_ALL = "siyuan-window-workspace-flush-all";
public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
public static readonly SIYUAN_QUIT: string = "siyuan-quit";
@@ -72,6 +70,7 @@ export abstract class Constants {
public static readonly SIYUAN_SHOW_WINDOW: string = "siyuan-show-window";
// 主进程调渲染进程
+ public static readonly SIYUAN_WINDOW_WORKSPACE_FLUSH = "siyuan-window-workspace-flush";
public static readonly SIYUAN_OPEN_URL: string = "siyuan-open-url";
public static readonly SIYUAN_OPEN_FILE: string = "siyuan-open-file";
public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close";
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts
index 0edfc32044..4704608624 100644
--- a/app/src/dialog/processSystem.ts
+++ b/app/src/dialog/processSystem.ts
@@ -211,7 +211,7 @@ export const exitSiYuan = async (setCurrentWorkspace = true) => {
hideAllElements(["util"]);
/// #if !BROWSER
try {
- if (!await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.WINDOW_WORKSPACE_FLUSH_ALL})) {
+ if (!await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.SIYUAN_WINDOW_WORKSPACE_FLUSH_ALL})) {
showMessage(window.siyuan.languages.windowWorkspaceSaveError, 6000, "error");
return;
}
diff --git a/app/src/menus/layouts.test.ts b/app/src/menus/layouts.test.ts
index 946a8ef5b2..6c9f09075d 100644
--- a/app/src/menus/layouts.test.ts
+++ b/app/src/menus/layouts.test.ts
@@ -14,7 +14,7 @@ const fixture = () => {
let dialog: any;
const dependencies = {
Constants: {LOCAL_LAYOUTS: "layouts", LOCAL_FILESPATHS: "paths",
- WINDOW_WORKSPACE_GET_OPEN: "getOpenWindowWorkspaces"},
+ SIYUAN_WINDOW_WORKSPACE_GET_OPEN: "siyuan-window-workspace-get-open"},
setStorageVal: (key: string, value: unknown, callback?: () => void) => {
calls.push({action: key, value: JSON.parse(JSON.stringify(value))});
callback?.();
diff --git a/app/src/menus/layouts.ts b/app/src/menus/layouts.ts
index 69ca65ac1f..0584d3e4f5 100644
--- a/app/src/menus/layouts.ts
+++ b/app/src/menus/layouts.ts
@@ -279,7 +279,7 @@ export const getLayoutSubMenu = (): IMenu[] => {
});
render();
/// #if !BROWSER
- void ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.WINDOW_WORKSPACE_GET_OPEN}).then((ids: string[]) => {
+ void ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.SIYUAN_WINDOW_WORKSPACE_GET_OPEN}).then((ids: string[]) => {
openIDs = Array.isArray(ids) ? ids : [];
if (menuElement.isConnected) {
render();
diff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.ts
index b7f1d3d370..6677000e8f 100644
--- a/app/src/window/onWindowsMsg.ts
+++ b/app/src/window/onWindowsMsg.ts
@@ -15,7 +15,7 @@ const closeTab = (ipcData: IWebSocketData) => {
};
export const onWindowsMsg = (ipcData: IWebSocketData) => {
switch (ipcData.cmd) {
- case Constants.WINDOW_WORKSPACE_FLUSH:
+ case Constants.SIYUAN_WINDOW_WORKSPACE_FLUSH:
void flushWindowWorkspace().then(saved => {
ipcRenderer.send(Constants.SIYUAN_WINDOW_WORKSPACE_SAVED, {id: ipcData.data, saved});
}).catch(() => {
diff --git a/app/src/window/workspace.test.ts b/app/src/window/workspace.test.ts
index b9e95a4e09..d453612a19 100644
--- a/app/src/window/workspace.test.ts
+++ b/app/src/window/workspace.test.ts
@@ -38,8 +38,8 @@ const fixture = (initialStorage: Record<string, unknown> = {}, workspaceID = "")
const dependencies = {
...core,
Constants: {LOCAL_WINDOW_WORKSPACE: prefix, SIYUAN_APPID: "test", SIYUAN_GET: "get",
- WINDOW_WORKSPACE_SET: "setWindowWorkspace",
- WINDOW_WORKSPACE_FOCUS: "focusWindowWorkspace"},
+ SIYUAN_WINDOW_WORKSPACE_SET: "siyuan-window-workspace-set",
+ SIYUAN_WINDOW_WORKSPACE_FOCUS: "siyuan-window-workspace-focus"},
getSearch: (key: string) => url.searchParams.get(key),
isBrowser: () => false,
isWindow: () => true,
@@ -71,7 +71,7 @@ const fixture = (initialStorage: Record<string, unknown> = {}, workspaceID = "")
escapeHtml: (text: string) => text,
openNewWindowByWorkspace: (workspace: string) => opened.push(workspace),
ipcRenderer: {invoke: async (_channel: string, data: {cmd: string, id: string}) => {
- if (data.cmd === "setWindowWorkspace") {
+ if (data.cmd === "siyuan-window-workspace-set") {
associated.push(data.id);
return true;
}
diff --git a/app/src/window/workspace.ts b/app/src/window/workspace.ts
index ec8e18e383..e7dfe293fd 100644
--- a/app/src/window/workspace.ts
+++ b/app/src/window/workspace.ts
@@ -140,7 +140,7 @@ const scheduleSave = () => {
const associate = async (id?: string) => {
/// #if !BROWSER
- if (!await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.WINDOW_WORKSPACE_SET, id: id || ""})) {
+ if (!await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.SIYUAN_WINDOW_WORKSPACE_SET, id: id || ""})) {
return false;
}
/// #endif
@@ -182,7 +182,7 @@ export const openWindowWorkspace = async (id: string) => {
return;
}
/// #if !BROWSER
- if (await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.WINDOW_WORKSPACE_FOCUS, id})) {
+ if (await ipcRenderer.invoke(Constants.SIYUAN_GET, {cmd: Constants.SIYUAN_WINDOW_WORKSPACE_FOCUS, id})) {
return;
}
/// #endif