Skip to content

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

:recycle: https://github.com/siyuan-note/siyuan/pull/14828

Vanessaefe9a3f90886
diff --git a/app/electron/main.js b/app/electron/main.js
index 6b860bad5a..efb0729ad8 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -761,12 +761,6 @@ app.whenReady().then(() => {
const menu = Menu.buildFromTemplate(template);
menu.popup({window: BrowserWindow.fromWebContents(event.sender)});
});
- ipcMain.on("siyuan-open-folder", (event, filePath) => {
- shell.showItemInFolder(filePath);
- });
- ipcMain.on("siyuan-open-path", (event, filePath) => {
- shell.openPath(filePath);
- });
ipcMain.on("siyuan-first-quit", () => {
app.exit();
});
@@ -874,6 +868,12 @@ app.whenReady().then(() => {
}
const currentWindow = getWindowByContentId(webContentsId);
switch (cmd) {
+ case "showItemInFolder":
+ shell.showItemInFolder(data.filePath);
+ break;
+ case "openPath":
+ shell.openPath(data.filePath);
+ break;
case "openDevTools":
event.sender.openDevTools({mode: "bottom"});
break;
diff --git a/app/src/boot/globalEvent/searchKeydown.ts b/app/src/boot/globalEvent/searchKeydown.ts
index be4a792a9d..1c05df0c6b 100644
--- a/app/src/boot/globalEvent/searchKeydown.ts
+++ b/app/src/boot/globalEvent/searchKeydown.ts
@@ -11,7 +11,7 @@ import {Dialog} from "../../dialog";
import {getAllModels} from "../../layout/getAll";
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
import {getArticle, inputEvent, replace} from "../../search/util";
-import {showFileInFolder} from "../../util/pathName";
+import {useShell} from "../../util/pathName";
import {assetInputEvent, renderPreview} from "../../search/assets";
import {initSearchMenu} from "../../menus/search";
import {writeText} from "../../protyle/util/compatibility";
@@ -235,7 +235,7 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {
}
} else {
/// #if !BROWSER
- showFileInFolder(path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label")));
+ useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, currentList.lastElementChild.getAttribute("aria-label")));
/// #endif
}
return true;
diff --git a/app/src/config/about.ts b/app/src/config/about.ts
index cca47ffdfe..d3f56b6904 100644
--- a/app/src/config/about.ts
+++ b/app/src/config/about.ts
@@ -12,7 +12,7 @@ import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
import {confirmDialog} from "../dialog/confirmDialog";
import {setKey} from "../sync/syncGuide";
-import {openPath} from "../util/pathName";
+import {useShell} from "../util/pathName";
export const about = {
element: undefined as Element,
@@ -209,7 +209,7 @@ ${checkUpdateHTML}
<span style="color:var(--b3-theme-background);font-family: cursive;">会泽百家&nbsp;至公天下</span>
</div>
<div class='fn__hr'></div>
- ${window.siyuan.languages.about1} ${"harmony" === window.siyuan.config.system.container? " • " + window.siyuan.languages.feedback + " [email protected]" : ""}
+ ${window.siyuan.languages.about1} ${"harmony" === window.siyuan.config.system.container ? " • " + window.siyuan.languages.feedback + " [email protected]" : ""}
</div>`;
},
bindEvent: () => {
@@ -260,7 +260,7 @@ ${checkUpdateHTML}
if (url.startsWith("http")) {
shell.openExternal(url);
} else {
- openPath(url);
+ useShell("openPath", url);
}
/// #else
window.open(url);
diff --git a/app/src/config/appearance.ts b/app/src/config/appearance.ts
index 3b9c9c299a..1ec310d509 100644
--- a/app/src/config/appearance.ts
+++ b/app/src/config/appearance.ts
@@ -11,7 +11,7 @@ import {openSnippets} from "./util/snippets";
import {loadAssets} from "../util/assets";
import {resetFloatDockSize} from "../layout/dock/util";
import {confirmDialog} from "../dialog/confirmDialog";
-import {openPath} from "../util/pathName";
+import {useShell} from "../util/pathName";
export const appearance = {
element: undefined as Element,
@@ -234,13 +234,13 @@ export const appearance = {
});
/// #if !BROWSER
appearance.element.querySelector("#appearanceOpenIcon").addEventListener("click", () => {
- openPath(path.join(window.siyuan.config.system.confDir, "appearance", "icons"));
+ useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "icons"));
});
appearance.element.querySelector("#appearanceOpenTheme").addEventListener("click", () => {
- openPath(path.join(window.siyuan.config.system.confDir, "appearance", "themes"));
+ useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", "themes"));
});
appearance.element.querySelector("#appearanceOpenEmoji").addEventListener("click", () => {
- openPath(path.join(window.siyuan.config.system.dataDir, "emojis"));
+ useShell("openPath", path.join(window.siyuan.config.system.dataDir, "emojis"));
});
/// #endif
appearance.element.querySelectorAll("select").forEach(item => {
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index 2fc5389d39..2edc35ba71 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -6,7 +6,6 @@ import {highlightRender} from "../protyle/render/highlightRender";
import {exportLayout, saveLayout} from "../layout/util";
import {Constants} from "../constants";
/// #if !BROWSER
-import {shell} from "electron";
import * as path from "path";
/// #endif
import {getFrontend, isBrowser} from "../util/functions";
@@ -19,7 +18,7 @@ import {uninstall} from "../plugin/uninstall";
import {afterLoadPlugin, loadPlugin, loadPlugins, reloadPlugin} from "../plugin/loader";
import {loadAssets} from "../util/assets";
import {addScript} from "../protyle/util/addScript";
-import {openPath} from "../util/pathName";
+import {useShell} from "../util/pathName";
export const bazaar = {
element: undefined as Element,
@@ -626,9 +625,9 @@ export const bazaar = {
/// #if !BROWSER
const dirName = dataObj.bazaarType;
if (dirName === "icons" || dirName === "themes") {
- openPath(path.join(window.siyuan.config.system.confDir, "appearance", dirName, dataObj.name));
+ useShell("openPath", path.join(window.siyuan.config.system.confDir, "appearance", dirName, dataObj.name));
} else {
- openPath(path.join(window.siyuan.config.system.dataDir, dirName, dataObj.name));
+ useShell("openPath", path.join(window.siyuan.config.system.dataDir, dirName, dataObj.name));
}
/// #endif
event.preventDefault();
diff --git a/app/src/config/exportConfig.ts b/app/src/config/exportConfig.ts
index 85b78e292b..bb4e3f8fbf 100644
--- a/app/src/config/exportConfig.ts
+++ b/app/src/config/exportConfig.ts
@@ -6,7 +6,7 @@ import * as path from "path";
/// #endif
import {isBrowser} from "../util/functions";
import {showMessage} from "../dialog/message";
-import {showFileInFolder} from "../util/pathName";
+import {useShell} from "../util/pathName";
import {Constants} from "../constants";
import {openByMobile} from "../protyle/util/compatibility";
import {exportLayout} from "../layout/util";
@@ -293,7 +293,7 @@ export const exportConfig = {
/// #if !BROWSER
pandocBinPathElement.addEventListener("click", () => {
if (window.siyuan.config.export.pandocBin) {
- showFileInFolder(window.siyuan.config.export.pandocBin);
+ useShell("showItemInFolder", window.siyuan.config.export.pandocBin);
}
});
const pandocBinElement = exportConfig.element.querySelector("#pandocBin") as HTMLInputElement;
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 30ad6ad65e..b028cb476c 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -49,8 +49,6 @@ export abstract class Constants {
public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
public static readonly SIYUAN_OPEN_URL: string = "siyuan-open-url";
public static readonly SIYUAN_OPEN_WINDOW: string = "siyuan-open-window";
- public static readonly SIYUAN_OPEN_FOLDER: string = "siyuan-open-folder";
- public static readonly SIYUAN_OPEN_PATH: string = "siyuan-open-path";
public static readonly SIYUAN_OPEN_FILE: string = "siyuan-open-file";
public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf";
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index 42f754b79d..b73476612c 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -5,7 +5,7 @@ import {getInstanceById, getWndByLayout, pdfIsLoading, setPanelFocus} from "../l
import {getDockByType} from "../layout/tabUtil";
import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById";
-import {getDisplayName, openPath, pathPosix, showFileInFolder} from "../util/pathName";
+import {getDisplayName, useShell, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
import {setEditMode} from "../protyle/util/setEditMode";
import {Files} from "../layout/dock/Files";
@@ -13,7 +13,7 @@ import {fetchPost, fetchSyncPost} from "../util/fetch";
import {focusBlock, focusByRange} from "../protyle/util/selection";
import {onGet} from "../protyle/util/onGet";
/// #if !BROWSER
-import {ipcRenderer, shell} from "electron";
+import {ipcRenderer} from "electron";
/// #endif
import {pushBack} from "../util/backForward";
import {Asset} from "../asset";
@@ -695,9 +695,9 @@ export const openBy = (url: string, type: "folder" | "app") => {
if (url.startsWith("assets/")) {
fetchPost("/api/asset/resolveAssetPath", {path: url.replace(/\.pdf\?page=\d{1,}$/, ".pdf")}, (response) => {
if (type === "app") {
- openPath(response.data);
+ useShell("openPath", response.data);
} else if (type === "folder") {
- showFileInFolder(response.data);
+ useShell("showItemInFolder", response.data);
}
});
return;
@@ -713,7 +713,7 @@ export const openBy = (url: string, type: "folder" | "app") => {
// 拖入文件名包含 `)` 、`(` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786
address = address.replace(/\\\)/g, ")").replace(/\\\(/g, "(");
if (type === "app") {
- openPath(address);
+ useShell("openPath", address);
} else if (type === "folder") {
if ("windows" === window.siyuan.config.system.os) {
if (!address.startsWith("\\\\")) { // \\ 开头的路径是 Windows 网络共享路径 https://github.com/siyuan-note/siyuan/issues/5980
@@ -721,7 +721,7 @@ export const openBy = (url: string, type: "folder" | "app") => {
address = address.replace(/\\\\/g, "\\");
}
}
- showFileInFolder(address);
+ useShell("showItemInFolder", address);
}
/// #endif
};
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index 4c10ba2d8f..a0fc0d8e5e 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -4,7 +4,7 @@ import {FileFilter, ipcRenderer} from "electron";
import * as path from "path";
/// #endif
import {MenuItem} from "./Menu";
-import {getDisplayName, getNotebookName, getTopPaths, openPath, pathPosix} from "../util/pathName";
+import {getDisplayName, getNotebookName, getTopPaths, useShell, pathPosix} from "../util/pathName";
import {hideMessage, showMessage} from "../dialog/message";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {onGetnotebookconf} from "./onGetnotebookconf";
@@ -362,7 +362,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click: () => {
- openPath(path.join(window.siyuan.config.system.dataDir, notebookId));
+ useShell("openPath", path.join(window.siyuan.config.system.dataDir, notebookId));
}
}).element);
/// #endif
diff --git a/app/src/menus/util.ts b/app/src/menus/util.ts
index bd212cf8ef..229f64bed1 100644
--- a/app/src/menus/util.ts
+++ b/app/src/menus/util.ts
@@ -3,7 +3,7 @@ import {ipcRenderer} from "electron";
import * as path from "path";
/// #endif
import {fetchPost} from "../util/fetch";
-import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
+import {getAssetName, pathPosix, useShell} from "../util/pathName";
import {openFileById} from "../editor/util";
import {Constants} from "../constants";
import {openNewWindowById} from "../window/openNewWindow";
@@ -149,11 +149,11 @@ export const openEditorTab = (app: App, ids: string[], notebookId?: string, path
label: window.siyuan.languages.showInFolder,
click: () => {
if (notebookId) {
- showFileInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
+ useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
} else {
ids.forEach((id) => {
fetchPost("/api/block/getBlockInfo", {id}, (response) => {
- showFileInFolder(path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path));
+ useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, response.data.box, response.data.path));
});
});
}
diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts
index 2528867803..fb6930b017 100644
--- a/app/src/menus/workspace.ts
+++ b/app/src/menus/workspace.ts
@@ -3,7 +3,7 @@ import {MenuItem} from "./Menu";
import {ipcRenderer} from "electron";
/// #endif
import {openHistory} from "../history/history";
-import {getOpenNotebookCount, originalPath, pathPosix, showFileInFolder} from "../util/pathName";
+import {getOpenNotebookCount, originalPath, pathPosix, useShell} from "../util/pathName";
import {fetchNewDailyNote, mountHelp, newDailyNote} from "../util/mount";
import {fetchPost} from "../util/fetch";
import {Constants} from "../constants";
@@ -354,7 +354,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
const genListHTML = () => {
let html = "";
window.siyuan.storage[Constants.LOCAL_LAYOUTS].sort((a: ISaveLayout, b: ISaveLayout) => {
- return a.name.localeCompare(b.name, undefined, {numeric:true});
+ return a.name.localeCompare(b.name, undefined, {numeric: true});
}).forEach((item: ISaveLayout) => {
if (inputElement.value === "" || item.name.toLowerCase().indexOf(inputElement.value.toLowerCase()) > -1) {
html += `<div data-name="${item.name}" class="b3-list-item b3-list-item--narrow b3-list-item--hide-action ${html ? "" : "b3-list-item--focus"}">
@@ -607,7 +607,7 @@ const workspaceItem = (item: IWorkspace) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click() {
- showFileInFolder(item.path);
+ useShell("showItemInFolder", item.path);
}
}, {
id: "copyPath",
diff --git a/app/src/protyle/export/util.ts b/app/src/protyle/export/util.ts
index 57c103a22b..70e00f4968 100644
--- a/app/src/protyle/export/util.ts
+++ b/app/src/protyle/export/util.ts
@@ -11,7 +11,7 @@ import {Constants} from "../../constants";
import {highlightRender} from "../render/highlightRender";
import {processRender} from "../util/processCode";
import {isIPhone, isSafari, openByMobile, setStorageVal} from "../util/compatibility";
-import {showFileInFolder} from "../../util/pathName";
+import {useShell} from "../../util/pathName";
import {isPaidUser} from "../../util/needSubscribe";
import {getCloudURL} from "../../config/util/about";
@@ -21,7 +21,7 @@ export const afterExport = (exportPath: string, msgId: string) => {
<div class="fn__space"></div>
<button class="b3-button b3-button--white">${window.siyuan.languages.showInFolder}</button>`, 6000, "info", msgId);
document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => {
- showFileInFolder(path.join(exportPath));
+ useShell("showItemInFolder", path.join(exportPath));
hideMessage(msgId);
});
/// #endif
diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts
index 1f3b206b9b..ad1c9a5d5c 100644
--- a/app/src/protyle/header/openTitleMenu.ts
+++ b/app/src/protyle/header/openTitleMenu.ts
@@ -10,7 +10,7 @@ import * as path from "path";
import {Constants} from "../../constants";
import {openCardByData} from "../../card/openCard";
import {viewCards} from "../../card/viewCards";
-import {getDisplayName, getNotebookName, pathPosix, showFileInFolder} from "../../util/pathName";
+import {getDisplayName, getNotebookName, pathPosix, useShell} from "../../util/pathName";
import {makeCard, quickMakeCard} from "../../card/makeCard";
import {emitOpenMenu} from "../../plugin/EventBus";
import * as dayjs from "dayjs";
@@ -244,7 +244,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
click: () => {
- showFileInFolder(path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path));
+ useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, protyle.notebookId, protyle.path));
}
}).element);
/// #endif
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 5439d8f909..03c5deb8da 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -15,7 +15,7 @@ import {
getNotebookName,
movePathTo,
pathPosix,
- showFileInFolder
+ useShell
} from "../util/pathName";
import {Protyle} from "../protyle";
import {onGet} from "../protyle/util/onGet";
@@ -852,7 +852,7 @@ export const genSearch = (app: App, config: Config.IUILayoutTabSearchConfig, ele
clearTimeout(clickTimeout);
if (searchType === "asset") {
/// #if !BROWSER
- showFileInFolder(path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label")));
+ useShell("showItemInFolder", path.join(window.siyuan.config.system.dataDir, target.lastElementChild.getAttribute("aria-label")));
/// #endif
} else {
const id = target.getAttribute("data-node-id");
diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts
index c5fb866130..9bf499277b 100644
--- a/app/src/util/pathName.ts
+++ b/app/src/util/pathName.ts
@@ -15,15 +15,12 @@ import {matchHotKey} from "../protyle/util/hotKey";
import {Menu} from "../plugin/Menu";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
-export const showFileInFolder = (filePath: string) => {
+export const useShell = (cmd: "showItemInFolder" | "openPath", filePath: string) => {
/// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_OPEN_FOLDER, filePath);
- /// #endif
-};
-
-export const openPath = (filePath: string) => {
- /// #if !BROWSER
- ipcRenderer.send(Constants.SIYUAN_OPEN_PATH, filePath);
+ ipcRenderer.send(Constants.SIYUAN_CMD, {
+ cmd,
+ filePath: filePath
+ });
/// #endif
};