笔记备份:2025-05-24 11:07:02
This commit is contained in:
8
.obsidian/plugins/keep-the-rhythm/data.json
vendored
8
.obsidian/plugins/keep-the-rhythm/data.json
vendored
@@ -51,7 +51,7 @@
|
||||
}
|
||||
},
|
||||
"2025-05-24": {
|
||||
"totalDelta": 1555,
|
||||
"totalDelta": 3920,
|
||||
"files": {
|
||||
"README.md": {
|
||||
"initial": 206,
|
||||
@@ -67,7 +67,11 @@
|
||||
},
|
||||
"A1-Work/接单/电梯维保系统.md": {
|
||||
"initial": 0,
|
||||
"current": 1511
|
||||
"current": 3876
|
||||
},
|
||||
"electron.nodejs.cn/api/child_process.html.md": {
|
||||
"initial": 0,
|
||||
"current": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
.obsidian/plugins/novel-word-count/data.json
vendored
16
.obsidian/plugins/novel-word-count/data.json
vendored
@@ -281,20 +281,20 @@
|
||||
"isCountable": true,
|
||||
"targetNodeType": "file",
|
||||
"noteCount": 1,
|
||||
"wordCount": 84,
|
||||
"wordCount": 679,
|
||||
"wordCountTowardGoal": 0,
|
||||
"wordGoal": null,
|
||||
"pageCount": 0.28,
|
||||
"characterCount": 717,
|
||||
"nonWhitespaceCharacterCount": 657,
|
||||
"newlineCount": 24,
|
||||
"readingTimeInMinutes": 0.23539622641509433,
|
||||
"pageCount": 2.263333333333333,
|
||||
"characterCount": 4275,
|
||||
"nonWhitespaceCharacterCount": 3465,
|
||||
"newlineCount": 177,
|
||||
"readingTimeInMinutes": 1.7889811320754716,
|
||||
"linkCount": 0,
|
||||
"embedCount": 0,
|
||||
"aliases": null,
|
||||
"createdDate": 1748051833199,
|
||||
"modifiedDate": 1748055046493,
|
||||
"sizeInBytes": 823,
|
||||
"modifiedDate": 1748055962289,
|
||||
"sizeInBytes": 5252,
|
||||
"sessionStart": {
|
||||
"noteCount": 0,
|
||||
"pageCount": 0,
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
"basename": "电梯维保系统",
|
||||
"path": "A1-Work/接单/电梯维保系统.md"
|
||||
},
|
||||
{
|
||||
"basename": "C语言小记",
|
||||
"path": "A0-Diary/C语言小记.md"
|
||||
},
|
||||
{
|
||||
"basename": "README",
|
||||
"path": "README.md"
|
||||
},
|
||||
{
|
||||
"basename": "C语言小记",
|
||||
"path": "A0-Diary/C语言小记.md"
|
||||
},
|
||||
{
|
||||
"basename": "知识库相关配置",
|
||||
"path": "A3-Tools/Dify/知识库相关配置.md"
|
||||
|
||||
15
.obsidian/workspace.json
vendored
15
.obsidian/workspace.json
vendored
@@ -4,17 +4,17 @@
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "99c6314fadbb0662",
|
||||
"id": "621b445102c90e6c",
|
||||
"type": "tabs",
|
||||
"children": [
|
||||
{
|
||||
"id": "da5b7d15e631b32d",
|
||||
"id": "90c963aaa9bee9fe",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "markdown",
|
||||
"state": {
|
||||
"file": "A1-Work/接单/电梯维保系统.md",
|
||||
"mode": "source",
|
||||
"mode": "preview",
|
||||
"source": true,
|
||||
"backlinks": false
|
||||
},
|
||||
@@ -246,12 +246,15 @@
|
||||
"obsidian-task-progress-bar:打开 Task Genius 视图": false
|
||||
}
|
||||
},
|
||||
"active": "da5b7d15e631b32d",
|
||||
"active": "90c963aaa9bee9fe",
|
||||
"lastOpenFiles": [
|
||||
"A1-Work/接单/电梯维保系统.md",
|
||||
"electron.nodejs.cn/api/child_process.html.md",
|
||||
"electron.nodejs.cn/api",
|
||||
"electron.nodejs.cn",
|
||||
"README.md",
|
||||
"A0-Diary/C语言小记.md",
|
||||
"A1-Work/接单",
|
||||
"README.md",
|
||||
"conflict-files-obsidian-git.md",
|
||||
"A5-Attachments/FqnUCGisfZt9Dsq8Oo7bOP0zxbBvy2e1oMkZ3zk2zJThFruk9HJtXZFYOv1b9ShB50u2pc8t4VPtdZtCEq5qXg.png",
|
||||
"A5-Attachments/f1f1202597066ccb49950154fe5af72c56a6a77b3445a460d7dd397cdbb7696f89e5924c2da72e9ca92ef9c9056d679af6bda6c2bd826fc548efce58d204a955.png",
|
||||
@@ -274,8 +277,6 @@
|
||||
"A3-Tools/Obsidian",
|
||||
"Home.md",
|
||||
"A6-Excalidraw",
|
||||
"A5-Attachments/Banner",
|
||||
"A5-Attachments",
|
||||
"A5-Attachments/Banner/logo.png",
|
||||
"A6-Excalidraw/Drawing 2025-05-20 23.48.44.excalidraw.md",
|
||||
"A5-Attachments/Pasted image 20250520234541.png",
|
||||
|
||||
0
.trash/electron.nodejs.cn/api/child_process.html.md
Normal file
0
.trash/electron.nodejs.cn/api/child_process.html.md
Normal file
@@ -1,6 +1,6 @@
|
||||
## 技术栈
|
||||
### electron-vite
|
||||
#### 搭建项目
|
||||
#### 快速开始
|
||||
```sh
|
||||
pnpm create @quick-start/electron
|
||||
```
|
||||
@@ -33,7 +33,7 @@ export default defineConfig({
|
||||
|
||||
```
|
||||
|
||||
#### 多窗口程序
|
||||
##### 多窗口程序
|
||||
```JavaScript
|
||||
// electron.vite.config.js
|
||||
export default {
|
||||
@@ -42,25 +42,128 @@ export default {
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
browser: resolve(__dirname, 'src/preload/browser.js'),
|
||||
webview: resolve(__dirname, 'src/preload/webview.js')
|
||||
}
|
||||
}
|
||||
}
|
||||
browser: resolve(__dirname, "src/preload/browser.js"),
|
||||
webview: resolve(__dirname, "src/preload/webview.js"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
renderer: {
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
browser: resolve(__dirname, 'src/renderer/browser.html'),
|
||||
webview: resolve(__dirname, 'src/renderer/webview.html')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
browser: resolve(__dirname, "src/renderer/browser.html"),
|
||||
webview: resolve(__dirname, "src/renderer/webview.html"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
##### Worker Threads
|
||||
你可以在导入请求上添加 `?modulePath` 或 `?nodeWorker` 查询参数来直接导入一个 node worker
|
||||
- 带 `?modulePath` 后缀默认导出会是一个 worker 的模块路径,这种语法更接近于标准,是创建 worker 的**推荐**方式
|
||||
|
||||
```JavaScript
|
||||
import { resolve } from "node:path";
|
||||
import { Worker } from "node:worker_threads";
|
||||
import workerPath from "./worker?modulePath";
|
||||
|
||||
new Worker(workerPath, {});
|
||||
|
||||
```
|
||||
|
||||
- 带 `?nodeWorker` 后缀默认导出会是一个自定义 worker 的构造函数
|
||||
|
||||
```JavaScript
|
||||
import createWorker from "./worker?nodeWorker";
|
||||
|
||||
createWorker({ workerData: "worker" })
|
||||
.on("message", (message) => {
|
||||
console.log(`Message from worker: ${message}`);
|
||||
})
|
||||
.postMessage("");
|
||||
|
||||
```
|
||||
|
||||
##### Utility Process and Child Process
|
||||
electron-vite 支持使用 Electron [UtilityProcess](https://electron.nodejs.cn/docs/latest/api/utility-process) API 或 Node.js [child_process](https://nodejs.cn/api/child_process.html) 来 fork 子进程。子进程可以使用 `?modulePath` 后缀导入。
|
||||
|
||||
```JavaScript
|
||||
// main.ts
|
||||
import { utilityProcess, MessageChannelMain } from "electron";
|
||||
import forkPath from "./fork?modulePath";
|
||||
|
||||
const { port1, port2 } = new MessageChannelMain();
|
||||
const child = utilityProcess.fork(forkPath);
|
||||
child.postMessage({ message: "hello" }, [port1]);
|
||||
|
||||
port2.on("message", (e) => {
|
||||
console.log(`Message from child: ${e.data}`);
|
||||
});
|
||||
port2.start();
|
||||
port2.postMessage("hello");
|
||||
|
||||
// fork.ts
|
||||
process.parentPort.on("message", (e) => {
|
||||
const [port] = e.ports;
|
||||
port.on("message", (e) => {
|
||||
console.log(`Message from parent: ${e.data}`);
|
||||
});
|
||||
port.start();
|
||||
port.postMessage("hello");
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
##### Electron ESM 的局限性
|
||||
我们首先应该了解 Electron ESM 的局限性:
|
||||
|
||||
1. Electron 的主进程和预加载脚本都支持 ESM 并且都使用 Node.js 的 ESM 加载器。
|
||||
2. Electron 的预加载脚本必须 `非沙盒化` 并且文件以 `.mjs` 扩展名结尾。
|
||||
|
||||
了解更多有关 [Electron ESM](https://electron.nodejs.cn/docs/latest/tutorial/esm/)。
|
||||
|
||||
##### 启用 ESM
|
||||
electron-vite 启用 ESM 有两种方法:
|
||||
|
||||
1. 将 `"type": "module"` 添加到最近的 `package.json` 中。
|
||||
|
||||
使用这种方式时,主进程和预加载脚本将被打包成 ES 模块文件。请注意,预加载脚本文件以 `.mjs` 扩展名结尾。你需要修复代码中引用这些脚本的文件名。
|
||||
|
||||
2. 在配置文件中将 `build.rollupOptions.output.format` 设置为 `es`。
|
||||
|
||||
```JavaScript
|
||||
export default defineConfig({
|
||||
main: {
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
format: "es",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
preload: {
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
format: "es",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// ...
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
使用这种方式时,主进程和预加载脚本将被打包成 ES 模块文件,并以 `.mjs` 扩展名结尾。你需要修复 `package.json` 中的 `main` 字段(Electron 入口点)以及代码中引用这些预加载脚本的文件名。
|
||||
|
||||
另外,从 electron-vite 2.0 开始,即使 Electron 版本低于 28,也可以在 `package.json` 中使用 `"type": "module"`。这种情况下,主进程和预加载脚本将被打包成 CommonJS 文件并以 `.cjs` 扩展名结尾。
|
||||
|
||||
## 参考
|
||||
|
||||
```cardlink
|
||||
|
||||
Reference in New Issue
Block a user