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