t3mode 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/bundles/index.cjs +94 -0
- package/dist/bundles/main.cjs +30984 -0
- package/dist/bundles/main.cjs.map +1 -0
- package/dist/bundles/preload.cjs +116 -0
- package/dist/bundles/renderer.iife.js +2186 -0
- package/dist/bundles/update-helper.ps1 +111 -0
- package/dist/repair.cjs +32649 -0
- package/dist/t3mode.cjs +46956 -0
- package/package.json +35 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
let electron = require("electron");
|
|
2
|
+
// ../shared/src/Ipc.ts
|
|
3
|
+
const Channel = {
|
|
4
|
+
/** Page → main: a SocketAction on a local socket the plugin's manifest declares. */
|
|
5
|
+
socket: "t3mode:socket",
|
|
6
|
+
/** Main → page: a SocketEvent for a socket this page opened. */
|
|
7
|
+
socketEvent: "t3mode:socket-event",
|
|
8
|
+
/** Preload → main: each loadable plugin's wrapped plugin.js, then renderer.js, re-read on every call. */
|
|
9
|
+
pageScripts: "t3mode:page-scripts",
|
|
10
|
+
/** Preload → main: one plugin's wrapped plugin.js, after an install or update. */
|
|
11
|
+
pluginScript: "t3mode:plugin-script",
|
|
12
|
+
/** Page → main: a PluginAction. Main accepts only GitHub sources from the page. */
|
|
13
|
+
plugins: "t3mode:plugins",
|
|
14
|
+
/** Page → main: one log line for the t3mode log file. */
|
|
15
|
+
log: "t3mode:log",
|
|
16
|
+
/** Page → main: the runtime started, so this boot counts as healthy. */
|
|
17
|
+
ready: "t3mode:ready",
|
|
18
|
+
/** Page → main: versions and paths, for the settings page and `status`. */
|
|
19
|
+
info: "t3mode:info",
|
|
20
|
+
/** Page → main: settings.json, or defaults when missing or invalid. */
|
|
21
|
+
readSettings: "t3mode:read-settings",
|
|
22
|
+
/** Page → main: every plugin's `plugin-data/<id>.json`, read once at startup. */
|
|
23
|
+
readPluginData: "t3mode:read-plugin-data",
|
|
24
|
+
/** Page → main: replace one plugin's `plugin-data/<id>.json`. */
|
|
25
|
+
writePluginData: "t3mode:write-plugin-data",
|
|
26
|
+
/** Page → main: replace settings.json. */
|
|
27
|
+
writeSettings: "t3mode:write-settings",
|
|
28
|
+
/** Page → main: show the logs folder in Explorer. */
|
|
29
|
+
openLogs: "t3mode:open-logs",
|
|
30
|
+
/** Page → main: T3 Mode's shortcut in T3 Code's keybindings.json (see Shortcut.ts). */
|
|
31
|
+
shortcut: "t3mode:shortcut",
|
|
32
|
+
/** Page → main: update status, a check now, or restart to install (see Updates.ts). */
|
|
33
|
+
update: "t3mode:update",
|
|
34
|
+
/** Main → page: the update status changed. Sent to pages that asked for the status. */
|
|
35
|
+
updateChanged: "t3mode:update-changed"
|
|
36
|
+
};
|
|
37
|
+
/** T3 Code's main window. Dev builds use schemes like `t3code-dev`. */
|
|
38
|
+
const MAIN_WINDOW_URL = /^t3code(?:-[a-z]+)?:\/\/app\//;
|
|
39
|
+
const isMainWindowUrl = (url) => MAIN_WINDOW_URL.test(url);
|
|
40
|
+
// src/preload.ts
|
|
41
|
+
const GUARD = "__t3modePreloaded";
|
|
42
|
+
const describe = (error) => error instanceof Error ? error.stack ?? error.message : String(error);
|
|
43
|
+
const runScript = async (script) => {
|
|
44
|
+
await electron.webFrame.executeJavaScript(`${script.code}\n//# sourceURL=${script.name}`);
|
|
45
|
+
};
|
|
46
|
+
const plugins = (action) => electron.ipcRenderer.invoke(Channel.plugins, action);
|
|
47
|
+
const start = () => {
|
|
48
|
+
const scope = globalThis;
|
|
49
|
+
if (scope[GUARD] === true || window.top !== window || !isMainWindowUrl(location.href)) return;
|
|
50
|
+
scope[GUARD] = true;
|
|
51
|
+
const bridge = {
|
|
52
|
+
socket: {
|
|
53
|
+
connect: (plugin, name) => electron.ipcRenderer.invoke(Channel.socket, {
|
|
54
|
+
_tag: "connect",
|
|
55
|
+
plugin,
|
|
56
|
+
name
|
|
57
|
+
}),
|
|
58
|
+
write: (id, data) => electron.ipcRenderer.invoke(Channel.socket, {
|
|
59
|
+
_tag: "write",
|
|
60
|
+
id,
|
|
61
|
+
data
|
|
62
|
+
}),
|
|
63
|
+
close: (id) => electron.ipcRenderer.invoke(Channel.socket, {
|
|
64
|
+
_tag: "close",
|
|
65
|
+
id
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
onSocketEvent: (listener) => {
|
|
69
|
+
electron.ipcRenderer.on(Channel.socketEvent, (_event, event) => listener(event));
|
|
70
|
+
},
|
|
71
|
+
log: (level, message) => electron.ipcRenderer.invoke(Channel.log, level, message),
|
|
72
|
+
ready: () => electron.ipcRenderer.invoke(Channel.ready),
|
|
73
|
+
info: () => electron.ipcRenderer.invoke(Channel.info),
|
|
74
|
+
readSettings: () => electron.ipcRenderer.invoke(Channel.readSettings),
|
|
75
|
+
writeSettings: (settings) => electron.ipcRenderer.invoke(Channel.writeSettings, settings),
|
|
76
|
+
readPluginData: () => electron.ipcRenderer.invoke(Channel.readPluginData),
|
|
77
|
+
writePluginData: (id, data) => electron.ipcRenderer.invoke(Channel.writePluginData, id, data),
|
|
78
|
+
openLogs: () => electron.ipcRenderer.invoke(Channel.openLogs),
|
|
79
|
+
shortcut: (action) => electron.ipcRenderer.invoke(Channel.shortcut, action),
|
|
80
|
+
update: (action) => electron.ipcRenderer.invoke(Channel.update, action),
|
|
81
|
+
onUpdate: (listener) => {
|
|
82
|
+
electron.ipcRenderer.on(Channel.updateChanged, (_event, status) => listener(status));
|
|
83
|
+
},
|
|
84
|
+
plugins: {
|
|
85
|
+
list: () => plugins({ _tag: "list" }),
|
|
86
|
+
preview: (input) => plugins({
|
|
87
|
+
_tag: "preview",
|
|
88
|
+
input
|
|
89
|
+
}),
|
|
90
|
+
install: (source, id) => plugins({
|
|
91
|
+
_tag: "install",
|
|
92
|
+
source,
|
|
93
|
+
id
|
|
94
|
+
}),
|
|
95
|
+
update: (id) => plugins({
|
|
96
|
+
_tag: "update",
|
|
97
|
+
id
|
|
98
|
+
}),
|
|
99
|
+
remove: (id) => plugins({
|
|
100
|
+
_tag: "remove",
|
|
101
|
+
id
|
|
102
|
+
}),
|
|
103
|
+
checkUpdates: () => plugins({ _tag: "check" })
|
|
104
|
+
},
|
|
105
|
+
loadPlugin: async (id) => {
|
|
106
|
+
const script = await electron.ipcRenderer.invoke(Channel.pluginScript, id);
|
|
107
|
+
if (!script) throw new Error(`Plugin ${id} has no code that can be loaded.`);
|
|
108
|
+
await runScript(script);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
electron.contextBridge.exposeInMainWorld("t3modeNative", bridge);
|
|
112
|
+
const logError = (message) => bridge.log("error", message).catch(() => void 0);
|
|
113
|
+
const runEachInOrder = (scripts) => scripts.reduce((previous, script) => previous.then(() => runScript(script).catch((error) => logError(`${script.name} failed: ${describe(error)}`))), Promise.resolve());
|
|
114
|
+
electron.ipcRenderer.invoke(Channel.pageScripts).then(runEachInOrder, (error) => logError(`Could not read the page scripts: ${describe(error)}`));
|
|
115
|
+
};
|
|
116
|
+
start();
|