t3mode 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/backend-host.cjs +74 -0
- package/dist/bundles/index.cjs +2 -0
- package/dist/bundles/main.cjs +2832 -2256
- package/dist/bundles/main.cjs.map +1 -1
- package/dist/bundles/preload.cjs +41 -28
- package/dist/bundles/renderer.iife.js +111 -99
- package/dist/bundles/update-helper.ps1 +34 -2
- package/dist/repair.cjs +3 -1
- package/dist/t3mode.cjs +773 -129
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Runs one plugin's backend in its own Electron utility process (see "Backends" in
|
|
2
|
+
// docs/architecture.md). Main forks this file with the plugin's id, script and data folder in the
|
|
3
|
+
// environment. It loads the script, which default-exports defineBackend({ start }), and carries
|
|
4
|
+
// messages between the plugin's `api` and main over process.parentPort. Any error the plugin
|
|
5
|
+
// leaves uncaught ends the process, and main restarts it with backoff.
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const port = process.parentPort;
|
|
9
|
+
const id = process.env.T3MODE_PLUGIN_ID ?? "";
|
|
10
|
+
const script = process.env.T3MODE_PLUGIN_BACKEND ?? "";
|
|
11
|
+
const dataDir = process.env.T3MODE_PLUGIN_DATA ?? "";
|
|
12
|
+
|
|
13
|
+
const describe = (error) =>
|
|
14
|
+
error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
15
|
+
const fatal = (error) => {
|
|
16
|
+
process.stderr.write(`[fatal] ${describe(error)}\n`, () => process.exit(1));
|
|
17
|
+
};
|
|
18
|
+
process.on("uncaughtException", fatal);
|
|
19
|
+
process.on("unhandledRejection", fatal);
|
|
20
|
+
|
|
21
|
+
// Messages can arrive before the plugin calls onMessage. They wait, up to a limit.
|
|
22
|
+
const MAX_QUEUED = 1000;
|
|
23
|
+
const listeners = [];
|
|
24
|
+
let queued = [];
|
|
25
|
+
const deliver = (data) => {
|
|
26
|
+
for (const listener of listeners) {
|
|
27
|
+
try {
|
|
28
|
+
listener(data);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
fatal(error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
port.on("message", (event) => {
|
|
35
|
+
const message = event.data;
|
|
36
|
+
if (!message || message._tag !== "message") return;
|
|
37
|
+
if (queued === undefined) deliver(message.data);
|
|
38
|
+
else if (queued.length < MAX_QUEUED) queued.push(message.data);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const write = (stream, level, message) => stream.write(`[${level}] ${message}\n`);
|
|
42
|
+
const api = Object.freeze({
|
|
43
|
+
id,
|
|
44
|
+
dataDir,
|
|
45
|
+
send: (data) => port.postMessage({ _tag: "message", data }),
|
|
46
|
+
onMessage: (listener) => {
|
|
47
|
+
if (typeof listener !== "function") throw new TypeError("onMessage takes a function.");
|
|
48
|
+
listeners.push(listener);
|
|
49
|
+
if (queued === undefined) return;
|
|
50
|
+
const waiting = queued;
|
|
51
|
+
queued = undefined;
|
|
52
|
+
queueMicrotask(() => {
|
|
53
|
+
for (const data of waiting) deliver(data);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
log: (level, message) =>
|
|
57
|
+
write(level === "error" || level === "warn" ? process.stderr : process.stdout, level, message),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
let definition;
|
|
61
|
+
try {
|
|
62
|
+
const loaded = require(script);
|
|
63
|
+
definition =
|
|
64
|
+
loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
fatal(error);
|
|
67
|
+
}
|
|
68
|
+
if (definition !== undefined && (!definition || typeof definition.start !== "function")) {
|
|
69
|
+
fatal(new Error(`${script} must default-export defineBackend({ start }).`));
|
|
70
|
+
} else if (definition) {
|
|
71
|
+
Promise.resolve()
|
|
72
|
+
.then(() => definition.start(api))
|
|
73
|
+
.then(() => port.postMessage({ _tag: "ready" }), fatal);
|
|
74
|
+
}
|
package/dist/bundles/index.cjs
CHANGED
|
@@ -55,6 +55,8 @@ const homeLayout = (root) => {
|
|
|
55
55
|
repairJs: node_path.join(dist, "repair.cjs"),
|
|
56
56
|
shimJs: node_path.join(dist, "shim.cjs"),
|
|
57
57
|
updateHelper: node_path.join(dist, "update-helper.ps1"),
|
|
58
|
+
backendHost: node_path.join(dist, "backend-host.cjs"),
|
|
59
|
+
pluginLogs: node_path.join(logs, "plugins"),
|
|
58
60
|
updates: node_path.join(root, "updates"),
|
|
59
61
|
updateReady: node_path.join(root, "updates", "ready.json"),
|
|
60
62
|
updateLog: node_path.join(logs, "update.log"),
|