Skip to content

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

:recycle: Upgrade to Electron v44.2.0

Daniel9bf5b31b46a4
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 0899d0c97f..bbea4b1c39 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -8,6 +8,8 @@
## NPM dependencies
+Electron 44 requires macOS 13 or later and supports only 64-bit Windows and Linux builds.
+
Install pnpm: `npm install -g [email protected]`
<details>
@@ -15,10 +17,10 @@ Install pnpm: `npm install -g [email protected]`
Set the Electron mirror environment variable and install Electron:
-* macOS/Linux: `ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ pnpm install [email protected] -D`
+* macOS/Linux: `ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ pnpm install [email protected] -D`
* Windows:
* `SET ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/`
- * `pnpm install [email protected] -D`
+ * `pnpm install [email protected] -D`
NPM mirror:
@@ -28,7 +30,7 @@ NPM mirror:
Enter the app folder and execute:
-* `pnpm install [email protected] -D`
+* `pnpm install [email protected] -D`
* `pnpm run install:electron`
* `pnpm run dev`
* `pnpm run start`
diff --git a/.github/CONTRIBUTING.zh-CN.md b/.github/CONTRIBUTING.zh-CN.md
index 9f635f91fb..8ad528e3e1 100644
--- a/.github/CONTRIBUTING.zh-CN.md
+++ b/.github/CONTRIBUTING.zh-CN.md
@@ -8,6 +8,8 @@
## NPM 依赖
+Electron 44 要求 macOS 13 或更高版本,Windows 和 Linux 仅支持 64 位构建。
+
安装 pnpm:`npm install -g [email protected]`
<details>
@@ -15,10 +17,10 @@
设置 Electron 镜像环境变量并安装 Electron:
-* macOS/Linux:`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ pnpm install [email protected] -D`
+* macOS/Linux:`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ pnpm install [email protected] -D`
* Windows:
* `SET ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/`
- * `pnpm install [email protected] -D`
+ * `pnpm install [email protected] -D`
NPM 镜像:
@@ -28,7 +30,7 @@ NPM 镜像:
进入 app 文件夹执行:
-* `pnpm install [email protected] -D`
+* `pnpm install [email protected] -D`
* `pnpm run install:electron`
* `pnpm run dev`
* `pnpm run start`
diff --git a/app/electron/clipboard.js b/app/electron/clipboard.js
new file mode 100644
index 0000000000..7a5fadd9e7
--- /dev/null
+++ b/app/electron/clipboard.js
@@ -0,0 +1,38 @@
+const rawFormatType = (format) => `electron application/osclipboard;format="${format.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
+
+const {fileURLToPath} = require("url");
+
+const readClipboardBuffer = async (items, type) => {
+ for (const item of items) {
+ if (item.types.includes(type)) {
+ const blob = await item.getType(type);
+ return Buffer.from(await blob.arrayBuffer());
+ }
+ }
+ return Buffer.alloc(0);
+};
+
+const readClipboardText = async (items, type) => {
+ return (await readClipboardBuffer(items, type)).toString("utf8");
+};
+
+const getClipboardFormats = (items) => {
+ return [...new Set(items.flatMap(item => item.types).map(type => {
+ const match = /^electron application\/osclipboard;format="((?:\\.|[^"\\])*)"$/.exec(type);
+ return match ? match[1].replace(/\\(.)/g, "$1") : type;
+ }))];
+};
+
+const parseClipboardFilePaths = (text) => text.split(/\r?\n/).flatMap(line => {
+ const uri = line.trim();
+ if (!uri || uri.startsWith("#")) {
+ return [];
+ }
+ try {
+ return [fileURLToPath(uri)];
+ } catch {
+ return [];
+ }
+});
+
+module.exports = {rawFormatType, readClipboardBuffer, readClipboardText, getClipboardFormats, parseClipboardFilePaths};
diff --git a/app/electron/clipboard.test.js b/app/electron/clipboard.test.js
new file mode 100644
index 0000000000..b52764420b
--- /dev/null
+++ b/app/electron/clipboard.test.js
@@ -0,0 +1,41 @@
+const assert = require("node:assert/strict");
+const {test} = require("node:test");
+const {pathToFileURL} = require("node:url");
+const path = require("node:path");
+const {rawFormatType, readClipboardBuffer, readClipboardText, getClipboardFormats, parseClipboardFilePaths} = require("./clipboard");
+
+const createItem = (data) => ({
+ types: Object.keys(data),
+ getType: async (type) => new Blob([data[type]])
+});
+
+test("clipboard preserves native Office and WPS bytes alongside text", async () => {
+ const office = Buffer.from([0xD0, 0xCF, 0x11, 0xE0, 0, 255]);
+ const math = Buffer.from("<math>x</math>\0", "utf16le");
+ const items = [createItem({"text/plain": "x", "text/html": "<b>x</b>"}), createItem({
+ [rawFormatType("Embed Source")]: office,
+ [rawFormatType("MathML")]: math,
+ [rawFormatType("Kingsoft WPS 9.0 Format")]: Buffer.from([0x50, 0x4B, 0, 255])
+ })];
+ assert.equal(await readClipboardText(items, "text/plain"), "x");
+ assert.equal(await readClipboardText(items, "text/html"), "<b>x</b>");
+ assert.deepEqual(await readClipboardBuffer(items, rawFormatType("Embed Source")), office);
+ assert.deepEqual(await readClipboardBuffer(items, rawFormatType("MathML")), math);
+ assert.ok(getClipboardFormats(items).includes("Kingsoft WPS 9.0 Format"));
+ assert.equal((await readClipboardBuffer(items, "missing")).length, 0);
+});
+
+test("clipboard raw format names round trip quoted characters", () => {
+ const format = 'custom "quoted" \\ format';
+ assert.deepEqual(getClipboardFormats([createItem({[rawFormatType(format)]: "x"})]), [format]);
+});
+
+test("clipboard file references decode escaped paths and reject non-file entries", () => {
+ const file = path.resolve("clipboard test #1.txt");
+ assert.deepEqual(parseClipboardFilePaths(`# comment\r\n${pathToFileURL(file).href}\r\nhttps://example.com/a\ninvalid\n`), [file]);
+});
+
+test("clipboard read failures propagate without returning partial data", async () => {
+ const items = [{types: ["text/html"], getType: async () => { throw new Error("clipboard changed"); }}];
+ await assert.rejects(readClipboardText(items, "text/html"), /clipboard changed/);
+});
diff --git a/app/electron/main.js b/app/electron/main.js
index ee454d5226..6b9b3dcf6f 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -29,6 +29,7 @@ const {
screen,
ipcMain,
clipboard,
+ ClipboardItem,
globalShortcut,
Tray,
dialog,
@@ -41,6 +42,9 @@ const {pathToFileURL} = require("url");
const gNet = require("net");
const childProcess = require("child_process");
const remote = require("@electron/remote/main");
+const {
+ rawFormatType, readClipboardBuffer, readClipboardText, getClipboardFormats, parseClipboardFilePaths
+} = require("./clipboard");
const {
getAppleSiliconDownloadURL,
shouldDownloadAppleSilicon,
@@ -2826,9 +2830,9 @@ app.whenReady().then(() => {
ipcMain.on("siyuan-first-quit", () => {
app.exit();
});
- ipcMain.handle("siyuan-get", (event, data) => {
+ ipcMain.handle("siyuan-get", async (event, data) => {
const remoteSender = getWindowKernelTarget(event.sender.id)?.mode === "remote";
- if (remoteSender && ["beginRichClipboard", "completeRichClipboard", "cancelRichClipboard", "clipboardRead"]
+ if (remoteSender && ["beginRichClipboard", "completeRichClipboard", "cancelRichClipboard", "clipboardRead", "clipboardReadFiles"]
.includes(data.cmd)) {
writeLog("ignored local file clipboard processing in remote kernel mode");
return false;
@@ -2850,19 +2854,23 @@ app.whenReady().then(() => {
return false;
}
if (data.cmd === "clipboardRead") {
- return clipboard.read(data.format);
+ return readClipboardText(await clipboard.read(), rawFormatType(data.format));
+ }
+ if (data.cmd === "clipboardReadFiles") {
+ return parseClipboardFilePaths(await readClipboardText(await clipboard.read(), "text/uri-list"));
}
if (data.cmd === "clipboardReadMathML") {
+ const items = await clipboard.read();
if (typeof data.text !== "string" ||
- normalizeClipboardText(clipboard.readText()) !== normalizeClipboardText(data.text)) {
+ normalizeClipboardText(await readClipboardText(items, "text/plain")) !== normalizeClipboardText(data.text)) {
return "";
}
- const formats = clipboard.availableFormats().filter((format) =>
+ const formats = getClipboardFormats(items).filter((format) =>
/^mathml(?: presentation)?$/i.test(format));
formats.push("MathML", "MathML Presentation");
- // availableFormats 可能不包含 Office 原生 MathML 格式,需要直接尝试标准格式名
+ // 按原生格式读取 UTF-16 编码的 Office 公式。
for (const format of new Set(formats)) {
- const buffer = clipboard.readBuffer(format);
+ const buffer = await readClipboardBuffer(items, rawFormatType(format));
if (buffer.length === 0 || buffer.length > 1024 * 1024 || buffer.length % 2 !== 0) {
continue;
}
@@ -2877,11 +2885,12 @@ app.whenReady().then(() => {
return "";
}
if (data.cmd === "clipboardReadOffice") {
+ const items = await clipboard.read();
if (typeof data.text !== "string" ||
- normalizeClipboardText(clipboard.readText()) !== normalizeClipboardText(data.text)) {
+ normalizeClipboardText(await readClipboardText(items, "text/plain")) !== normalizeClipboardText(data.text)) {
return "";
}
- const buffer = clipboard.readBuffer("Embed Source");
+ const buffer = await readClipboardBuffer(items, rawFormatType("Embed Source"));
const compoundFileSignature = Buffer.from([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1]);
if (buffer.length === 0 || buffer.length > 8 * 1024 * 1024 ||
!buffer.subarray(0, compoundFileSignature.length).equals(compoundFileSignature)) {
@@ -2890,19 +2899,20 @@ app.whenReady().then(() => {
return buffer.toString("base64");
}
if (data.cmd === "clipboardReadWPS") {
+ const items = await clipboard.read();
if (typeof data.text !== "string" ||
- normalizeClipboardText(clipboard.readText()) !== normalizeClipboardText(data.text)) {
+ normalizeClipboardText(await readClipboardText(items, "text/plain")) !== normalizeClipboardText(data.text)) {
return "";
}
- const formats = clipboard.availableFormats().filter((format) =>
+ const formats = getClipboardFormats(items).filter((format) =>
/kingsoft.*wps.*format/i.test(format));
formats.push("Kingsoft WPS Format");
for (let version = 6; version <= 20; version++) {
formats.push(`Kingsoft WPS ${version}.0 Format`);
}
- // availableFormats 可能不包含 WPS 原生格式,需要尝试常见格式名
+ // 按原生格式读取 WPS 的压缩包数据。
for (const format of new Set(formats)) {
- const buffer = clipboard.readBuffer(format);
+ const buffer = await readClipboardBuffer(items, rawFormatType(format));
if (buffer.length <= 8 * 1024 * 1024 && buffer[0] === 0x50 && buffer[1] === 0x4b) {
return buffer.toString("base64");
}
@@ -2911,15 +2921,19 @@ app.whenReady().then(() => {
}
if (data.cmd === "beginRichClipboard") {
richClipboardOperation = undefined;
- const text = clipboard.readText();
- const html = clipboard.readHTML();
+ const sequence = ++richClipboardSequence;
+ const items = await clipboard.read();
+ const text = await readClipboardText(items, "text/plain");
+ const html = await readClipboardText(items, "text/html");
+ if (sequence !== richClipboardSequence) {
+ return;
+ }
if (typeof data.text !== "string" || typeof data.marker !== "string" ||
normalizeClipboardText(text) !== normalizeClipboardText(data.text) ||
!data.marker || !html.includes(data.marker)) {
return;
}
- richClipboardSequence++;
const token = `${Date.now()}-${richClipboardSequence}`;
richClipboardOperation = {
token,
@@ -2935,8 +2949,14 @@ app.whenReady().then(() => {
if (!operation || operation.token !== data.token || operation.senderId !== event.sender.id) {
return false;
}
- if (operation.requestedText !== data.text || clipboard.readText() !== operation.text ||
- clipboard.readHTML() !== operation.html || typeof data.html !== "string" ||
+ const items = await clipboard.read();
+ const text = await readClipboardText(items, "text/plain");
+ const clipboardHTML = await readClipboardText(items, "text/html");
+ if (richClipboardOperation !== operation) {
+ return false;
+ }
+ if (operation.requestedText !== data.text || text !== operation.text ||
+ clipboardHTML !== operation.html || typeof data.html !== "string" ||
!Array.isArray(data.replacements) || 1024 < data.replacements.length) {
richClipboardOperation = undefined;
return false;
@@ -2962,10 +2982,7 @@ app.whenReady().then(() => {
}
richClipboardOperation = undefined;
- clipboard.write({
- text: data.text,
- html
- });
+ await clipboard.write([new ClipboardItem({"text/plain": data.text, "text/html": html})]);
return true;
}
if (data.cmd === "cancelRichClipboard") {
diff --git a/app/package.json b/app/package.json
index 15043b6d52..b65b342d0b 100644
--- a/app/package.json
+++ b/app/package.json
@@ -66,7 +66,7 @@
"cross-env": "^10.1.0",
"css-loader": "^7.1.2",
"dayjs": "^1.11.5",
- "electron": "43.5.1",
+ "electron": "44.2.0",
"electron-builder": "26.15.7",
"encoding": "^0.1.13",
"esbuild-loader": "^3.0.1",
diff --git a/app/pnpm-lock.yaml b/app/pnpm-lock.yaml
index 67f2c60fa2..7c06582444 100644
--- a/app/pnpm-lock.yaml
+++ b/app/pnpm-lock.yaml
@@ -13,7 +13,7 @@ importers:
dependencies:
'@electron/remote':
specifier: ^2.1.3
zxcvbn:
specifier: 4.4.2
version: 4.4.2
@@ -55,8 +55,8 @@ importers:
specifier: ^1.11.5
version: 1.11.20
electron:
- specifier: 43.5.1
- version: 43.5.1([email protected])
+ specifier: 44.2.0
+ version: 44.2.0([email protected])
electron-builder:
specifier: 26.15.7
@@ -1494,8 +1494,8 @@ packages:
resolution: {integrity: sha512-bO3y10YikuUwUuDUQRM4KfwNkKhnpVO7IPdbsrejwN9/AABJzzTQ4GeHwyzNSrVO+tEH3/Np255a3sVZpZDjvg==}
engines: {node: '>=8.0.0'}
- resolution: {integrity: sha512-lRHSwzZimdWWeqcTHFRCpicWwxBE6kotKIyGTusums/jvmVVC27rLPFikUz8LsLwV7gVWlYaiEYQAWzitbN6nA==}
+ resolution: {integrity: sha512-oK1icjhapp3xsUZycO9WZaLmd3hJnA7ieobC4mpdtO1pEN+PPGWpA3m1Mgzzuc1wzSD2Wai4zcH4yfpGJqxFMA==}
engines: {node: '>= 22.12.0'}
hasBin: true
@@ -3071,9 +3071,9 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
- electron: 43.5.1([email protected])
+ electron: 44.2.0([email protected])
dependencies:
@@ -4325,7 +4325,7 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@electron-internal/extract-zip': 1.0.3
'@electron/get': 4.0.3([email protected])
diff --git a/app/pnpm-workspace.yaml b/app/pnpm-workspace.yaml
index 3fdf9ac29a..9e23bbc98e 100644
--- a/app/pnpm-workspace.yaml
+++ b/app/pnpm-workspace.yaml
@@ -5,7 +5,7 @@ allowBuilds:
esbuild: true
blockExoticSubdeps: false
minimumReleaseAgeExclude:
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 1823fd2806..d541f8db4d 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -221,16 +221,11 @@ export const getLocalFiles = async () => {
return localFiles;
}
if ("darwin" === window.siyuan.config.system.os) {
- const xmlString = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
- cmd: "clipboardRead",
- format: "NSFilenamesPboardType",
+ const filePaths: string[] = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
+ cmd: "clipboardReadFiles",
});
- 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});
- });
+ if (Array.isArray(filePaths)) {
+ localFiles = filePaths.map(path => ({path, size: null}));
}
} else {
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});