Skip to content

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

:recycle: Read macOS clipboard file paths in the main process via IPC (#17186)

Jeffrey Chen1bd591a889be
diff --git a/app/electron/main.js b/app/electron/main.js
index dc8b8363b5..8f91464ce5 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -24,6 +24,7 @@ const {
MenuItem,
screen,
ipcMain,
+ clipboard,
globalShortcut,
Tray,
dialog,
@@ -843,6 +844,9 @@ app.whenReady().then(() => {
app.exit();
});
ipcMain.handle("siyuan-get", (event, data) => {
+ if (data.cmd === "clipboardRead") {
+ return clipboard.read(data.format);
+ }
if (data.cmd === "showOpenDialog") {
return dialog.showOpenDialog(data);
}
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index c911039dc9..60a5ac7a9b 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -2,7 +2,7 @@ import {focusByRange} from "./selection";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {Constants} from "../../constants";
/// #if !BROWSER
-import {clipboard, ipcRenderer} from "electron";
+import {ipcRenderer} from "electron";
/// #endif
/// #if MOBILE
import {processSYLink} from "../../editor/openLink";
@@ -133,12 +133,17 @@ export const getLocalFiles = async () => {
// 不再支持 PC 浏览器 https://github.com/siyuan-note/siyuan/issues/7206
let localFiles: ILocalFiles[] = [];
if ("darwin" === window.siyuan.config.system.os) {
- const xmlString = clipboard.read("NSFilenamesPboardType");
- const domParser = new DOMParser();
- const xmlDom = domParser.parseFromString(xmlString, "application/xml");
- Array.from(xmlDom.getElementsByTagName("string")).forEach(item => {
- localFiles.push({path: item.childNodes[0].nodeValue, size: null});
+ const xmlString = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
+ cmd: "clipboardRead",
+ format: "NSFilenamesPboardType",
});
+ if (xmlString) {
+ const domParser = new DOMParser();
+ const xmlDom = domParser.parseFromString(xmlString, "application/xml");
+ Array.from(xmlDom.getElementsByTagName("string")).forEach(item => {
+ localFiles.push({path: item.childNodes[0].nodeValue, size: null});
+ });
+ }
} else {
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
if (xmlString.data.length > 0) {