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
package/dist/bundles/preload.cjs
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
let electron = require("electron");
|
|
2
2
|
// ../shared/src/Ipc.ts
|
|
3
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
4
|
/** Preload → main: each loadable plugin's wrapped plugin.js, then renderer.js, re-read on every call. */
|
|
9
5
|
pageScripts: "t3mode:page-scripts",
|
|
10
6
|
/** Preload → main: one plugin's wrapped plugin.js, after an install or update. */
|
|
@@ -32,11 +28,19 @@ const Channel = {
|
|
|
32
28
|
/** Page → main: update status, a check now, or restart to install (see Updates.ts). */
|
|
33
29
|
update: "t3mode:update",
|
|
34
30
|
/** Main → page: the update status changed. Sent to pages that asked for the status. */
|
|
35
|
-
updateChanged: "t3mode:update-changed"
|
|
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"
|
|
36
38
|
};
|
|
37
39
|
/** T3 Code's main window. Dev builds use schemes like `t3code-dev`. */
|
|
38
40
|
const MAIN_WINDOW_URL = /^t3code(?:-[a-z]+)?:\/\/app\//;
|
|
39
41
|
const isMainWindowUrl = (url) => MAIN_WINDOW_URL.test(url);
|
|
42
|
+
// ../shared/src/Version.ts
|
|
43
|
+
const T3MODE_VERSION = "0.2.0";
|
|
40
44
|
// src/preload.ts
|
|
41
45
|
const GUARD = "__t3modePreloaded";
|
|
42
46
|
const describe = (error) => error instanceof Error ? error.stack ?? error.message : String(error);
|
|
@@ -44,30 +48,30 @@ const runScript = async (script) => {
|
|
|
44
48
|
await electron.webFrame.executeJavaScript(`${script.code}\n//# sourceURL=${script.name}`);
|
|
45
49
|
};
|
|
46
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
|
+
};
|
|
47
70
|
const start = () => {
|
|
48
71
|
const scope = globalThis;
|
|
49
72
|
if (scope[GUARD] === true || window.top !== window || !isMainWindowUrl(location.href)) return;
|
|
50
73
|
scope[GUARD] = true;
|
|
51
74
|
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
75
|
log: (level, message) => electron.ipcRenderer.invoke(Channel.log, level, message),
|
|
72
76
|
ready: () => electron.ipcRenderer.invoke(Channel.ready),
|
|
73
77
|
info: () => electron.ipcRenderer.invoke(Channel.info),
|
|
@@ -87,14 +91,16 @@ const start = () => {
|
|
|
87
91
|
_tag: "preview",
|
|
88
92
|
input
|
|
89
93
|
}),
|
|
90
|
-
install: (source, id) => plugins({
|
|
94
|
+
install: (source, id, approved) => plugins({
|
|
91
95
|
_tag: "install",
|
|
92
96
|
source,
|
|
93
|
-
id
|
|
97
|
+
id,
|
|
98
|
+
approved
|
|
94
99
|
}),
|
|
95
|
-
update: (id) => plugins({
|
|
100
|
+
update: (id, approved) => plugins({
|
|
96
101
|
_tag: "update",
|
|
97
|
-
id
|
|
102
|
+
id,
|
|
103
|
+
...approved === void 0 ? {} : { approved }
|
|
98
104
|
}),
|
|
99
105
|
remove: (id) => plugins({
|
|
100
106
|
_tag: "remove",
|
|
@@ -106,10 +112,17 @@ const start = () => {
|
|
|
106
112
|
const script = await electron.ipcRenderer.invoke(Channel.pluginScript, id);
|
|
107
113
|
if (!script) throw new Error(`Plugin ${id} has no code that can be loaded.`);
|
|
108
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));
|
|
109
120
|
}
|
|
110
121
|
};
|
|
111
122
|
electron.contextBridge.exposeInMainWorld("t3modeNative", bridge);
|
|
112
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();
|
|
113
126
|
const runEachInOrder = (scripts) => scripts.reduce((previous, script) => previous.then(() => runScript(script).catch((error) => logError(`${script.name} failed: ${describe(error)}`))), Promise.resolve());
|
|
114
127
|
electron.ipcRenderer.invoke(Channel.pageScripts).then(runEachInOrder, (error) => logError(`Could not read the page scripts: ${describe(error)}`));
|
|
115
128
|
};
|
|
@@ -1,90 +1,4 @@
|
|
|
1
1
|
(function() {
|
|
2
|
-
// src/LocalSockets.ts
|
|
3
|
-
const localSockets = (native) => {
|
|
4
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
5
|
-
const early = /* @__PURE__ */ new Map();
|
|
6
|
-
let pending = 0;
|
|
7
|
-
let subscribed = false;
|
|
8
|
-
return async (plugin, name, alive, guard, add) => {
|
|
9
|
-
if (!alive()) throw new Error("The plugin has stopped.");
|
|
10
|
-
if (!subscribed) {
|
|
11
|
-
native.onSocketEvent((event) => {
|
|
12
|
-
const listener = listeners.get(event.id);
|
|
13
|
-
if (listener) listener(event);
|
|
14
|
-
else if (pending > 0) {
|
|
15
|
-
const queue = early.get(event.id) ?? [];
|
|
16
|
-
queue.push(event);
|
|
17
|
-
early.set(event.id, queue);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
subscribed = true;
|
|
21
|
-
}
|
|
22
|
-
pending++;
|
|
23
|
-
try {
|
|
24
|
-
const result = await native.socket.connect(plugin, name);
|
|
25
|
-
if (!result.ok) throw new Error(result.error);
|
|
26
|
-
const id = result.value;
|
|
27
|
-
const dataListeners = [];
|
|
28
|
-
const closeListeners = [];
|
|
29
|
-
let unread = [];
|
|
30
|
-
let state = { kind: "open" };
|
|
31
|
-
const closed = (error) => {
|
|
32
|
-
if (state.kind === "closed") return;
|
|
33
|
-
state = {
|
|
34
|
-
kind: "closed",
|
|
35
|
-
...error === void 0 ? {} : { error }
|
|
36
|
-
};
|
|
37
|
-
listeners.delete(id);
|
|
38
|
-
for (const callback of closeListeners) callback(error);
|
|
39
|
-
};
|
|
40
|
-
const close = () => {
|
|
41
|
-
if (state.kind === "closed") return;
|
|
42
|
-
native.socket.close(id).catch(() => void 0);
|
|
43
|
-
closed();
|
|
44
|
-
};
|
|
45
|
-
if (!alive()) {
|
|
46
|
-
close();
|
|
47
|
-
throw new Error("The plugin stopped while connecting.");
|
|
48
|
-
}
|
|
49
|
-
const listener = (event) => {
|
|
50
|
-
if (event._tag === "closed") closed(event.error);
|
|
51
|
-
else if (unread) unread.push(event.data);
|
|
52
|
-
else for (const callback of dataListeners) callback(event.data);
|
|
53
|
-
};
|
|
54
|
-
listeners.set(id, listener);
|
|
55
|
-
add(close);
|
|
56
|
-
for (const event of early.get(id) ?? []) listener(event);
|
|
57
|
-
early.delete(id);
|
|
58
|
-
return {
|
|
59
|
-
name,
|
|
60
|
-
write: (data) => {
|
|
61
|
-
if (!alive() || state.kind === "closed") return;
|
|
62
|
-
native.socket.write(id, data).catch((error) => {
|
|
63
|
-
close();
|
|
64
|
-
guard(() => {
|
|
65
|
-
throw error;
|
|
66
|
-
})();
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
close,
|
|
70
|
-
onData: (callback) => {
|
|
71
|
-
const guarded = guard(callback);
|
|
72
|
-
dataListeners.push(guarded);
|
|
73
|
-
const pendingData = unread;
|
|
74
|
-
unread = void 0;
|
|
75
|
-
for (const data of pendingData ?? []) guarded(data);
|
|
76
|
-
},
|
|
77
|
-
onClose: (callback) => {
|
|
78
|
-
if (state.kind === "closed") guard(callback)(state.error);
|
|
79
|
-
else closeListeners.push(guard(callback));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
} finally {
|
|
83
|
-
pending--;
|
|
84
|
-
if (pending === 0) early.clear();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
2
|
// src/PluginStorage.ts
|
|
89
3
|
const pluginStorage = (data, unreadable, pathOf, write, warn) => {
|
|
90
4
|
const unreadableIds = new Set(unreadable);
|
|
@@ -750,7 +664,6 @@ ${SHORTCUT_BADGE}::after {
|
|
|
750
664
|
};
|
|
751
665
|
var Runtime = class {
|
|
752
666
|
#native;
|
|
753
|
-
#connect;
|
|
754
667
|
#data = /* @__PURE__ */ new Map();
|
|
755
668
|
#storage;
|
|
756
669
|
#entries = /* @__PURE__ */ new Map();
|
|
@@ -760,12 +673,13 @@ ${SHORTCUT_BADGE}::after {
|
|
|
760
673
|
#listeners = /* @__PURE__ */ new Set();
|
|
761
674
|
#updateListeners = /* @__PURE__ */ new Set();
|
|
762
675
|
#panels = /* @__PURE__ */ new Map();
|
|
676
|
+
#backends = /* @__PURE__ */ new Map();
|
|
677
|
+
#backendListeners = /* @__PURE__ */ new Map();
|
|
763
678
|
#settings;
|
|
764
679
|
#update;
|
|
765
680
|
info;
|
|
766
681
|
constructor(native, installed, settings, info, pluginData) {
|
|
767
682
|
this.#native = native;
|
|
768
|
-
this.#connect = localSockets(native);
|
|
769
683
|
for (const [id, data] of Object.entries(pluginData.data)) this.#data.set(id, { ...data });
|
|
770
684
|
const separator = info.home.includes("\\") ? "\\" : "/";
|
|
771
685
|
this.#storage = pluginStorage(this.#data, pluginData.unreadable, (id) => [
|
|
@@ -783,6 +697,40 @@ ${SHORTCUT_BADGE}::after {
|
|
|
783
697
|
} };
|
|
784
698
|
for (const plugin of installed) this.#entries.set(plugin.id, this.#entryFor(plugin));
|
|
785
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* Follows the plugins' backends. Main sends the current statuses before it answers, so plugins
|
|
702
|
+
* started after this see their backend's status from the first call.
|
|
703
|
+
*/
|
|
704
|
+
async followBackends() {
|
|
705
|
+
try {
|
|
706
|
+
this.#native.onBackendEvent((event) => this.#onBackendEvent(event));
|
|
707
|
+
await this.#native.backend({ _tag: "subscribe" });
|
|
708
|
+
} catch (error) {
|
|
709
|
+
this.log("warn", `Could not follow plugin backends: ${describe$1(error)}`);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
/** The plugin's backend, as main last reported it. Null: none runs. */
|
|
713
|
+
backendStatus(id) {
|
|
714
|
+
return this.#backends.get(id) ?? null;
|
|
715
|
+
}
|
|
716
|
+
#onBackendEvent(event) {
|
|
717
|
+
if (event._tag === "status") {
|
|
718
|
+
if (event.status) this.#backends.set(event.plugin, event.status);
|
|
719
|
+
else this.#backends.delete(event.plugin);
|
|
720
|
+
this.#emit();
|
|
721
|
+
}
|
|
722
|
+
for (const listener of this.#backendListeners.get(event.plugin) ?? []) if (event._tag === "message") listener.message?.(event.data);
|
|
723
|
+
else listener.status?.(event.status);
|
|
724
|
+
}
|
|
725
|
+
#listenBackend(id, listener, add) {
|
|
726
|
+
let listeners = this.#backendListeners.get(id);
|
|
727
|
+
if (!listeners) {
|
|
728
|
+
listeners = /* @__PURE__ */ new Set();
|
|
729
|
+
this.#backendListeners.set(id, listeners);
|
|
730
|
+
}
|
|
731
|
+
listeners.add(listener);
|
|
732
|
+
add(() => listeners.delete(listener));
|
|
733
|
+
}
|
|
786
734
|
get plugins() {
|
|
787
735
|
return [...this.#entries.values()].map((entry) => entry.info).toSorted((a, b) => a.name.localeCompare(b.name));
|
|
788
736
|
}
|
|
@@ -846,6 +794,14 @@ ${SHORTCUT_BADGE}::after {
|
|
|
846
794
|
await this.#save(id, { options });
|
|
847
795
|
}
|
|
848
796
|
async retry(id) {
|
|
797
|
+
if (this.backendStatus(id)?.state === "failed") await this.#native.backend({
|
|
798
|
+
_tag: "retry",
|
|
799
|
+
plugin: id
|
|
800
|
+
}).catch((error) => {
|
|
801
|
+
this.log("warn", `Could not restart the backend of ${id}: ${describe$1(error)}`);
|
|
802
|
+
});
|
|
803
|
+
const kind = this.state(id).kind;
|
|
804
|
+
if (kind !== "failed" && kind !== "unavailable") return;
|
|
849
805
|
const entry = this.#entries.get(id);
|
|
850
806
|
if (!entry) return;
|
|
851
807
|
this.#stop(id);
|
|
@@ -867,12 +823,12 @@ ${SHORTCUT_BADGE}::after {
|
|
|
867
823
|
preview(input) {
|
|
868
824
|
return this.#ask("Preview", () => this.#native.plugins.preview(input));
|
|
869
825
|
}
|
|
870
|
-
async install(source, id) {
|
|
871
|
-
const result = await this.#ask("Install", () => this.#native.plugins.install(source, id));
|
|
826
|
+
async install(source, id, approved) {
|
|
827
|
+
const result = await this.#ask("Install", () => this.#native.plugins.install(source, id, approved));
|
|
872
828
|
return this.#loadAndStart(result);
|
|
873
829
|
}
|
|
874
|
-
async updatePlugin(id) {
|
|
875
|
-
const result = await this.#ask("Update", () => this.#native.plugins.update(id));
|
|
830
|
+
async updatePlugin(id, approved) {
|
|
831
|
+
const result = await this.#ask("Update", () => this.#native.plugins.update(id, approved));
|
|
876
832
|
return this.#loadAndStart(result);
|
|
877
833
|
}
|
|
878
834
|
async remove(id) {
|
|
@@ -1121,7 +1077,6 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1121
1077
|
const add = (cleanup) => cleanups.push(cleanup);
|
|
1122
1078
|
const api = {
|
|
1123
1079
|
id,
|
|
1124
|
-
sockets: { connect: (name) => this.#connect(id, name, alive, guard, add) },
|
|
1125
1080
|
options: optionValues(definition.options, storedOptions ?? this.#settings.plugins[id]?.options),
|
|
1126
1081
|
css: (text) => {
|
|
1127
1082
|
const style = document.createElement("style");
|
|
@@ -1204,6 +1159,20 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1204
1159
|
react: {
|
|
1205
1160
|
findPropsUp,
|
|
1206
1161
|
findHookState
|
|
1162
|
+
},
|
|
1163
|
+
disks: () => this.#native.disks(),
|
|
1164
|
+
backend: {
|
|
1165
|
+
send: (data) => alive() ? this.#native.backend({
|
|
1166
|
+
_tag: "send",
|
|
1167
|
+
plugin: id,
|
|
1168
|
+
data
|
|
1169
|
+
}) : Promise.resolve(false),
|
|
1170
|
+
onMessage: (callback) => this.#listenBackend(id, { message: guard(callback) }, add),
|
|
1171
|
+
onStatus: (callback) => {
|
|
1172
|
+
const run = guard(callback);
|
|
1173
|
+
this.#listenBackend(id, { status: run }, add);
|
|
1174
|
+
run(this.backendStatus(id));
|
|
1175
|
+
}
|
|
1207
1176
|
}
|
|
1208
1177
|
};
|
|
1209
1178
|
try {
|
|
@@ -1214,6 +1183,11 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1214
1183
|
}
|
|
1215
1184
|
};
|
|
1216
1185
|
// ../shared/src/Plugins.ts
|
|
1186
|
+
const declaredAccess = (manifest) => ({
|
|
1187
|
+
backend: manifest.backend !== void 0,
|
|
1188
|
+
mcp: manifest.mcp !== void 0
|
|
1189
|
+
});
|
|
1190
|
+
const accessLines = (access) => [...access.backend ? ["Runs a program outside T3 Code's window"] : [], ...access.mcp ? ["Adds tools to your agents"] : []];
|
|
1217
1191
|
const sourceLabel = (source) => source.kind === "github" ? `${source.owner}/${source.repo}${source.tag === void 0 ? "" : `@${source.tag}`}` : `linked from ${source.path}`;
|
|
1218
1192
|
// src/ui/updatesSection.ts
|
|
1219
1193
|
const MB = 1048576;
|
|
@@ -1315,7 +1289,7 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1315
1289
|
];
|
|
1316
1290
|
const canRetry = (runtime, plugin) => {
|
|
1317
1291
|
const kind = runtime.state(plugin.id).kind;
|
|
1318
|
-
return kind === "failed" || kind === "unavailable" && (plugin.error === void 0 || plugin.source.kind === "local");
|
|
1292
|
+
return kind === "failed" || kind === "unavailable" && (plugin.error === void 0 || plugin.source.kind === "local") || runtime.backendStatus(plugin.id)?.state === "failed";
|
|
1319
1293
|
};
|
|
1320
1294
|
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1321
1295
|
const busy = async (control, action) => {
|
|
@@ -1333,6 +1307,17 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1333
1307
|
};
|
|
1334
1308
|
const status = (runtime, plugin) => {
|
|
1335
1309
|
const state = runtime.state(plugin.id);
|
|
1310
|
+
const backend = runtime.backendStatus(plugin.id);
|
|
1311
|
+
if (state.kind !== "failed" && state.kind !== "unavailable") {
|
|
1312
|
+
if (backend?.state === "failed") return {
|
|
1313
|
+
tone: "failed",
|
|
1314
|
+
text: `Backend stopped after ${backend.crashes} crashes: ${backend.error}`
|
|
1315
|
+
};
|
|
1316
|
+
if (backend?.state === "restarting") return {
|
|
1317
|
+
tone: "waiting",
|
|
1318
|
+
text: `Backend restarting after a crash: ${backend.error}`
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1336
1321
|
switch (state.kind) {
|
|
1337
1322
|
case "off": return {
|
|
1338
1323
|
tone: "off",
|
|
@@ -1799,10 +1784,10 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1799
1784
|
}), h("p", {
|
|
1800
1785
|
className: native.rowDescription,
|
|
1801
1786
|
text: `${by}github.com/${sourceLabel(source)}`
|
|
1802
|
-
}), manifest.
|
|
1787
|
+
}), ...accessLines(declaredAccess(manifest)).map((text) => h("p", {
|
|
1803
1788
|
className: native.rowDescription,
|
|
1804
|
-
text
|
|
1805
|
-
})
|
|
1789
|
+
text
|
|
1790
|
+
})), manifest.description ? h("p", {
|
|
1806
1791
|
className: native.rowDescription,
|
|
1807
1792
|
text: manifest.description
|
|
1808
1793
|
}) : null, preview.offers.length > 1 ? confirm : null);
|
|
@@ -1837,7 +1822,7 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1837
1822
|
installed,
|
|
1838
1823
|
id: offer.manifest.id
|
|
1839
1824
|
});
|
|
1840
|
-
const result = await this.#runtime.install(offer.source, offer.manifest.id);
|
|
1825
|
+
const result = await this.#runtime.install(offer.source, offer.manifest.id, declaredAccess(offer.manifest));
|
|
1841
1826
|
if (!result.ok) {
|
|
1842
1827
|
if (preview.offers.length === 1) {
|
|
1843
1828
|
this.#setStep({
|
|
@@ -1880,6 +1865,32 @@ ${SHORTCUT_BADGE}::after {
|
|
|
1880
1865
|
}
|
|
1881
1866
|
async #update(plugin) {
|
|
1882
1867
|
const result = await this.#runtime.updatePlugin(plugin.id);
|
|
1868
|
+
if (!result.ok && result.approval) {
|
|
1869
|
+
const approval = result.approval;
|
|
1870
|
+
const panel = h("div", { className: `${native.card} t3mode-confirm` }, h("h3", {
|
|
1871
|
+
className: native.rowTitle,
|
|
1872
|
+
text: `Approve update for ${plugin.name}`
|
|
1873
|
+
}), ...accessLines(result.approval).map((text) => h("p", {
|
|
1874
|
+
className: native.rowDescription,
|
|
1875
|
+
text
|
|
1876
|
+
})), h("div", { className: "t3mode-actions" }, button({
|
|
1877
|
+
text: "Approve and update",
|
|
1878
|
+
onClick: () => void busy(approve, async () => {
|
|
1879
|
+
const updated = await this.#runtime.updatePlugin(plugin.id, approval);
|
|
1880
|
+
toast(updated.ok ? `${updated.value.name} is updated to ${updated.value.version}.` : updated.error, updated.ok ? "info" : "error");
|
|
1881
|
+
panel.remove();
|
|
1882
|
+
})
|
|
1883
|
+
}), button({
|
|
1884
|
+
text: "Cancel",
|
|
1885
|
+
onClick: () => panel.remove()
|
|
1886
|
+
})));
|
|
1887
|
+
const approve = panel.querySelector("button");
|
|
1888
|
+
this.#body?.querySelector("[data-t3mode-approval]")?.remove();
|
|
1889
|
+
panel.setAttribute("data-t3mode-approval", plugin.id);
|
|
1890
|
+
this.#body?.prepend(panel);
|
|
1891
|
+
panel.scrollIntoView({ block: "nearest" });
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1883
1894
|
toast(result.ok ? `${result.value.name} is updated to ${result.value.version}.` : result.error, result.ok ? "info" : "error");
|
|
1884
1895
|
}
|
|
1885
1896
|
async #remove(plugin) {
|
|
@@ -2010,7 +2021,7 @@ ${SHORTCUT_BADGE}::after {
|
|
|
2010
2021
|
control
|
|
2011
2022
|
});
|
|
2012
2023
|
});
|
|
2013
|
-
body.append(section(plugin.name, null, group(
|
|
2024
|
+
body.append(section(plugin.name, null, group(row({
|
|
2014
2025
|
title: "Enabled",
|
|
2015
2026
|
description: plugin.description,
|
|
2016
2027
|
control: toggle
|
|
@@ -2154,6 +2165,7 @@ ${SHORTCUT_BADGE}::after {
|
|
|
2154
2165
|
]);
|
|
2155
2166
|
const runtime = new Runtime(native, installed, settings, info, pluginData);
|
|
2156
2167
|
window.__t3modeRuntime = runtime;
|
|
2168
|
+
await runtime.followBackends();
|
|
2157
2169
|
runtime.startAll();
|
|
2158
2170
|
runtime.watchUpdates();
|
|
2159
2171
|
const page = new SettingsPage(runtime);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Installs a T3 Code update after T3 Code quits, then puts the t3mode shim back.
|
|
2
2
|
# Started detached by the t3mode loader (packages/main/src/Updater.ts) from Electron's will-quit.
|
|
3
|
-
# 1. Wait for every T3 Code process to exit.
|
|
3
|
+
# 1. Wait for every T3 Code process to exit, stopping plugin tool servers that run its exe.
|
|
4
4
|
# 2. Run the downloaded installer silently, the way electron-updater does (--updated /S),
|
|
5
5
|
# and wait for that process.
|
|
6
6
|
# 3. Re-apply the shim with repair.cjs, run by T3 Code's own exe in Node mode.
|
|
@@ -17,7 +17,8 @@ param(
|
|
|
17
17
|
[string] $Version = "",
|
|
18
18
|
[string] $Relaunch = "0",
|
|
19
19
|
[string] $RelaunchArgs = "",
|
|
20
|
-
[string] $KeepUpdaterEnv = "0"
|
|
20
|
+
[string] $KeepUpdaterEnv = "0",
|
|
21
|
+
[string] $PluginFolders = ""
|
|
21
22
|
)
|
|
22
23
|
|
|
23
24
|
$ErrorActionPreference = "Stop"
|
|
@@ -43,6 +44,35 @@ function Get-T3Processes {
|
|
|
43
44
|
})
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
# Plugin tool servers run T3 Code's exe, started by Claude or Codex, so they can outlive T3 Code
|
|
48
|
+
# and would hold the update. Stops every process of an exe in the install folder whose command
|
|
49
|
+
# line names a file under <home>\plugins\ or a linked plugin's folder (-PluginFolders, base64
|
|
50
|
+
# JSON), the same match as stopProcessesScript in packages/shared/src/ToolServers.ts.
|
|
51
|
+
# Get-Process has no CommandLine in Windows PowerShell 5.1.
|
|
52
|
+
function Stop-PluginProcesses {
|
|
53
|
+
try {
|
|
54
|
+
$prefix = $InstallDir.TrimEnd("\") + "\"
|
|
55
|
+
$folders = @((Join-Path $HomeDir "plugins").TrimEnd("\") + "\")
|
|
56
|
+
if ($PluginFolders) {
|
|
57
|
+
$json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($PluginFolders))
|
|
58
|
+
# Windows PowerShell emits a JSON array as one object; foreach over it gets the items.
|
|
59
|
+
foreach ($folder in (ConvertFrom-Json $json)) { $folders += ([string] $folder).TrimEnd("\") + "\" }
|
|
60
|
+
}
|
|
61
|
+
$found = @(Get-CimInstance Win32_Process | Where-Object {
|
|
62
|
+
$p = $_
|
|
63
|
+
$p.ProcessId -ne $PID -and $p.ExecutablePath -and $p.CommandLine -and
|
|
64
|
+
$p.ExecutablePath.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase) -and
|
|
65
|
+
@($folders | Where-Object { $p.CommandLine.IndexOf($_, [StringComparison]::OrdinalIgnoreCase) -ge 0 }).Count -gt 0
|
|
66
|
+
})
|
|
67
|
+
if ($found.Count -eq 0) { return }
|
|
68
|
+
foreach ($p in $found) { Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue }
|
|
69
|
+
foreach ($p in $found) { Wait-Process -Id $p.ProcessId -Timeout 10 -ErrorAction SilentlyContinue }
|
|
70
|
+
Write-Log "Stopped $($found.Count) plugin process(es): $(($found | ForEach-Object { $_.ProcessId }) -join ', ')"
|
|
71
|
+
} catch {
|
|
72
|
+
Write-Log "Could not stop plugin processes: $_"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
function Get-T3Exe {
|
|
47
77
|
Get-ChildItem -LiteralPath $InstallDir -Filter "*.exe" |
|
|
48
78
|
Where-Object { $_.Name -notlike "Uninstall*" } |
|
|
@@ -60,6 +90,8 @@ try {
|
|
|
60
90
|
try { Wait-Process -Id $ParentPid -Timeout 120 -ErrorAction SilentlyContinue } catch {}
|
|
61
91
|
$deadline = (Get-Date).AddSeconds(120)
|
|
62
92
|
while ((Get-T3Processes).Count -gt 0) {
|
|
93
|
+
Stop-PluginProcesses
|
|
94
|
+
if ((Get-T3Processes).Count -eq 0) { break }
|
|
63
95
|
if ((Get-Date) -gt $deadline) {
|
|
64
96
|
Write-Log "T3 Code is still running after 2 minutes; the update is skipped until the next quit."
|
|
65
97
|
exit 1
|
package/dist/repair.cjs
CHANGED
|
@@ -31790,6 +31790,8 @@ const homeLayout = (root) => {
|
|
|
31790
31790
|
repairJs: node_path.join(dist, "repair.cjs"),
|
|
31791
31791
|
shimJs: node_path.join(dist, "shim.cjs"),
|
|
31792
31792
|
updateHelper: node_path.join(dist, "update-helper.ps1"),
|
|
31793
|
+
backendHost: node_path.join(dist, "backend-host.cjs"),
|
|
31794
|
+
pluginLogs: node_path.join(logs, "plugins"),
|
|
31793
31795
|
updates: node_path.join(root, "updates"),
|
|
31794
31796
|
updateReady: node_path.join(root, "updates", "ready.json"),
|
|
31795
31797
|
updateLog: node_path.join(logs, "update.log"),
|
|
@@ -31815,7 +31817,7 @@ const decodeMarker = decodeUnknownEffect(fromJsonString(Struct({
|
|
|
31815
31817
|
name: Literal("t3mode"),
|
|
31816
31818
|
shimVersion: Int
|
|
31817
31819
|
})));
|
|
31818
|
-
var AsarArchive = class extends Service()("
|
|
31820
|
+
var AsarArchive = class extends Service()("t3mode/Asar/AsarArchive") {};
|
|
31819
31821
|
const readRootFile = (archive, file) => try_({
|
|
31820
31822
|
try: () => {
|
|
31821
31823
|
uncacheFilesystem(archive);
|