playcanvas-agent-bridge-cli 0.6.1 → 0.7.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/README.md +148 -31
- package/README.zh-CN.md +137 -33
- package/dist/cli.js +514 -95
- package/dist/config.js +23 -1
- package/dist/daemon/server.js +336 -28
- package/dist/daemon/target-registry.js +3 -0
- package/dist/plugins/host.js +260 -0
- package/dist/plugins/store.js +567 -0
- package/dist/processing/manager.js +265 -0
- package/dist/processing/tools.js +97 -0
- package/dist/snippets.js +27 -0
- package/dist/updates.js +475 -0
- package/dist/workspace/json-sync.js +821 -0
- package/dist/workspace/manager.js +1973 -326
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-256.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/isolated.js +59 -2
- package/extension/main.js +770 -275
- package/extension/manifest.json +60 -10
- package/extension/popup.html +115 -3
- package/extension/popup.js +398 -14
- package/extension/service-worker.js +221 -4
- package/package.json +18 -18
- package/plugins/index.json +14 -0
- package/plugins/tinyapp-builder/node/builder.js +589 -0
- package/plugins/tinyapp-builder/node/index.js +30 -0
- package/plugins/tinyapp-builder/package.json +13 -0
- package/plugins/tinyapp-builder/page/editor.js +249 -0
- package/plugins/tinyapp-builder/pcbridge-plugin.json +28 -0
- package/skills/claude/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +99 -43
- package/skills/codex/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/codex/pcbridge-plugin-authoring/agents/openai.yaml +4 -0
- package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +89 -62
- package/skills/cursor/pcbridge-plugin-authoring.mdc +221 -0
- package/skills/cursor/playcanvas-agent-bridge-cli.mdc +69 -33
- package/skills/windsurf/pcbridge-plugin-authoring.md +215 -0
- package/skills/windsurf/playcanvas-agent-bridge-cli.md +68 -33
- package/dist/builder/manager.js +0 -564
package/extension/popup.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
function clampEagerMaxMb(value) {
|
|
2
|
+
const parsed = Number(value);
|
|
3
|
+
if (!Number.isFinite(parsed)) return 2;
|
|
4
|
+
return Math.min(10, Math.max(1, Math.round(parsed)));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async function updateDaemonWorkspaceSettings(config, eagerMaxMb) {
|
|
8
|
+
if (!config || !config.token) return null;
|
|
9
|
+
try {
|
|
10
|
+
const host = config.host || "127.0.0.1";
|
|
11
|
+
const port = config.port || 17329;
|
|
12
|
+
const response = await fetch(`http://${host}:${port}/workspace/settings`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
"X-PCBridge-Token": config.token
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({ eagerMaxMb })
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) return null;
|
|
21
|
+
const envelope = await response.json();
|
|
22
|
+
return envelope.ok ? envelope.data : null;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
async function loadConfig() {
|
|
2
29
|
try {
|
|
3
30
|
const response = await fetch(chrome.runtime.getURL("config.json"));
|
|
@@ -8,12 +35,13 @@ async function loadConfig() {
|
|
|
8
35
|
}
|
|
9
36
|
}
|
|
10
37
|
|
|
11
|
-
async function loadStatus(config, tabId) {
|
|
38
|
+
async function loadStatus(config, tabId, refresh = false) {
|
|
12
39
|
if (!config || !config.token) return null;
|
|
13
40
|
try {
|
|
14
41
|
const host = config.host || "127.0.0.1";
|
|
15
42
|
const port = config.port || 17329;
|
|
16
|
-
const
|
|
43
|
+
const query = `tabId=${encodeURIComponent(tabId || "")}${refresh ? "&refresh=1" : ""}`;
|
|
44
|
+
const response = await fetch(`http://${host}:${port}/status?${query}`, {
|
|
17
45
|
headers: { "X-PCBridge-Token": config.token }
|
|
18
46
|
});
|
|
19
47
|
if (!response.ok) return null;
|
|
@@ -47,6 +75,185 @@ async function sendRuntimeMessage(message) {
|
|
|
47
75
|
}
|
|
48
76
|
}
|
|
49
77
|
|
|
78
|
+
async function pluginRequest(config, path, body) {
|
|
79
|
+
if (!config || !config.token) {
|
|
80
|
+
return { ok: false, error: { message: "pcbridge daemon configuration is unavailable." } };
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`http://${config.host || "127.0.0.1"}:${config.port || 17329}${path}`, {
|
|
84
|
+
method: body ? "POST" : "GET",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
"X-PCBridge-Token": config.token
|
|
88
|
+
},
|
|
89
|
+
body: body ? JSON.stringify(body) : undefined
|
|
90
|
+
});
|
|
91
|
+
return await response.json();
|
|
92
|
+
} catch {
|
|
93
|
+
return { ok: false, error: { message: "pcbridge daemon is offline. Run pcbridge daemon start." } };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function element(tag, className, text) {
|
|
98
|
+
const node = document.createElement(tag);
|
|
99
|
+
if (className) node.className = className;
|
|
100
|
+
if (text !== undefined) node.textContent = text;
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function setupPlugins(config) {
|
|
105
|
+
const view = document.getElementById("view-plugins");
|
|
106
|
+
const list = document.getElementById("plugin-list");
|
|
107
|
+
const available = document.getElementById("plugin-available");
|
|
108
|
+
const note = document.getElementById("plugin-note");
|
|
109
|
+
const source = document.getElementById("plugin-source");
|
|
110
|
+
const defaultNote = note.textContent;
|
|
111
|
+
const states = {
|
|
112
|
+
active: ["Active", "success"],
|
|
113
|
+
stopped: ["Stopped", "warning"],
|
|
114
|
+
disabled: ["Disabled", "neutral"],
|
|
115
|
+
error: ["Error", "danger"]
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function showNote(message, isError) {
|
|
119
|
+
note.textContent = message || defaultNote;
|
|
120
|
+
note.classList.toggle("error", Boolean(isError));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function run(path, body, pending) {
|
|
124
|
+
showNote(pending, false);
|
|
125
|
+
view.inert = true;
|
|
126
|
+
const result = await pluginRequest(config, path, body);
|
|
127
|
+
view.inert = false;
|
|
128
|
+
await refresh();
|
|
129
|
+
if (!result.ok) showNote(result.error.message, true);
|
|
130
|
+
return result.ok;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function action(label, handler, primary) {
|
|
134
|
+
const button = element("button", primary ? "primary" : "", label);
|
|
135
|
+
button.type = "button";
|
|
136
|
+
button.addEventListener("click", handler);
|
|
137
|
+
return button;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function installedRow(plugin) {
|
|
141
|
+
const row = element("div", "plugin");
|
|
142
|
+
const head = element("div", "plugin-head");
|
|
143
|
+
const versionLabel = plugin.updateAvailable && plugin.latestVersion
|
|
144
|
+
? `v${plugin.version || "?"} → v${plugin.latestVersion}`
|
|
145
|
+
: plugin.version
|
|
146
|
+
? `v${plugin.version}`
|
|
147
|
+
: "";
|
|
148
|
+
head.append(element("strong", "", plugin.name), element("span", "mono", versionLabel));
|
|
149
|
+
const status = element("span", "status");
|
|
150
|
+
if (plugin.updateAvailable) {
|
|
151
|
+
setStatus(status, plugin.compatible === false ? "Needs pcbridge ↑" : "Update ↑", "warning");
|
|
152
|
+
} else {
|
|
153
|
+
setStatus(status, ...states[plugin.state]);
|
|
154
|
+
}
|
|
155
|
+
head.append(status);
|
|
156
|
+
row.append(head);
|
|
157
|
+
if (plugin.description) row.append(element("p", "", plugin.description));
|
|
158
|
+
const runtimes = Object.keys(plugin.runtimes).filter((name) => plugin.runtimes[name]);
|
|
159
|
+
row.append(element("p", "mono", [plugin.id, ...runtimes, plugin.source.type].join(" · ")));
|
|
160
|
+
if (plugin.updateAvailable && plugin.compatible === false && plugin.minPcbridgeVersion) {
|
|
161
|
+
row.append(element("p", "error", `v${plugin.latestVersion} requires pcbridge v${plugin.minPcbridgeVersion}+. Update pcbridge first.`));
|
|
162
|
+
}
|
|
163
|
+
if (plugin.error) row.append(element("p", "error", plugin.error));
|
|
164
|
+
for (const page of plugin.pages || []) {
|
|
165
|
+
if (!page.ok) row.append(element("p", "error", `${page.target}: ${page.error}`));
|
|
166
|
+
}
|
|
167
|
+
const actions = element("div", "plugin-actions");
|
|
168
|
+
if (plugin.updateAvailable && plugin.compatible !== false) {
|
|
169
|
+
actions.append(
|
|
170
|
+
action("Update", () => run(`/plugins/${plugin.id}/update`, {}, `Updating ${plugin.name}…`), true)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
actions.append(
|
|
174
|
+
plugin.enabled
|
|
175
|
+
? action("Disable", () => run(`/plugins/${plugin.id}/disable`, {}, `Disabling ${plugin.name}…`))
|
|
176
|
+
: action("Enable", () => run(`/plugins/${plugin.id}/enable`, {}, `Enabling ${plugin.name}…`), !plugin.updateAvailable),
|
|
177
|
+
action("Remove", () => run(`/plugins/${plugin.id}/remove`, {}, `Removing ${plugin.name}…`))
|
|
178
|
+
);
|
|
179
|
+
row.append(actions);
|
|
180
|
+
return row;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function availableRow(plugin) {
|
|
184
|
+
const row = element("div", "plugin");
|
|
185
|
+
const head = element("div", "plugin-head");
|
|
186
|
+
head.append(element("strong", "", plugin.name), element("span", "mono", `v${plugin.version}`));
|
|
187
|
+
row.append(head);
|
|
188
|
+
if (plugin.description) row.append(element("p", "", plugin.description));
|
|
189
|
+
if (plugin.compatible === false && plugin.minPcbridgeVersion) {
|
|
190
|
+
row.append(element("p", "error", `Requires pcbridge v${plugin.minPcbridgeVersion}+`));
|
|
191
|
+
}
|
|
192
|
+
const actions = element("div", "plugin-actions");
|
|
193
|
+
const installBtn = action("Install", () => run("/plugins/add", { source: plugin.source }, `Installing ${plugin.name}…`), true);
|
|
194
|
+
installBtn.disabled = plugin.compatible === false;
|
|
195
|
+
actions.append(installBtn);
|
|
196
|
+
row.append(actions);
|
|
197
|
+
return row;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function refresh(forceRefresh = false) {
|
|
201
|
+
const result = await pluginRequest(config, `/plugins${forceRefresh ? "?refresh=1" : ""}`);
|
|
202
|
+
const count = document.getElementById("plugin-count");
|
|
203
|
+
const updateAllBtn = document.getElementById("plugin-update-all");
|
|
204
|
+
const pluginsTab = document.getElementById("tab-plugins");
|
|
205
|
+
const plugins = result.ok && result.data && Array.isArray(result.data.plugins) ? result.data.plugins : [];
|
|
206
|
+
const offered = result.ok && result.data && Array.isArray(result.data.available) ? result.data.available : [];
|
|
207
|
+
const updatable = plugins.filter((plugin) => plugin.updateAvailable && plugin.compatible !== false);
|
|
208
|
+
const anyUpdate = plugins.filter((plugin) => plugin.updateAvailable);
|
|
209
|
+
list.replaceChildren(...plugins.map(installedRow));
|
|
210
|
+
available.replaceChildren(...offered.map(availableRow));
|
|
211
|
+
document.getElementById("plugin-empty").hidden = !result.ok || plugins.length > 0;
|
|
212
|
+
document.getElementById("plugin-available-section").hidden = offered.length === 0;
|
|
213
|
+
document.getElementById("plugin-add").disabled = !result.ok;
|
|
214
|
+
updateAllBtn.hidden = updatable.length === 0;
|
|
215
|
+
pluginsTab.textContent = anyUpdate.length > 0 ? `Plugins · ${anyUpdate.length}↑` : "Plugins";
|
|
216
|
+
if (result.ok) {
|
|
217
|
+
const enabled = plugins.filter((plugin) => plugin.enabled).length;
|
|
218
|
+
setStatus(
|
|
219
|
+
count,
|
|
220
|
+
anyUpdate.length > 0 ? `${anyUpdate.length} update${anyUpdate.length === 1 ? "" : "s"}` : `${enabled} enabled`,
|
|
221
|
+
plugins.some((plugin) => plugin.state === "error")
|
|
222
|
+
? "danger"
|
|
223
|
+
: anyUpdate.length > 0
|
|
224
|
+
? "warning"
|
|
225
|
+
: enabled
|
|
226
|
+
? "success"
|
|
227
|
+
: "neutral"
|
|
228
|
+
);
|
|
229
|
+
showNote("", false);
|
|
230
|
+
} else {
|
|
231
|
+
setStatus(count, "Unavailable", "danger");
|
|
232
|
+
showNote(result.error.message, true);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
document.getElementById("plugin-update-all").addEventListener("click", async () => {
|
|
237
|
+
await run("/plugins/update-all", {}, "Updating plugins…");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
document.getElementById("plugin-add").addEventListener("click", async () => {
|
|
241
|
+
const value = source.value.trim();
|
|
242
|
+
if (value && await run("/plugins/add", { source: value }, "Installing plugin…")) source.value = "";
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const tabs = { bridge: document.getElementById("tab-bridge"), plugins: document.getElementById("tab-plugins") };
|
|
246
|
+
for (const [name, tab] of Object.entries(tabs)) {
|
|
247
|
+
tab.addEventListener("click", () => {
|
|
248
|
+
for (const [other, button] of Object.entries(tabs)) {
|
|
249
|
+
button.setAttribute("aria-selected", String(other === name));
|
|
250
|
+
document.getElementById(`view-${other}`).hidden = other !== name;
|
|
251
|
+
}
|
|
252
|
+
if (name === "plugins") void refresh(true);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
50
257
|
function setStatus(element, label, state) {
|
|
51
258
|
element.textContent = label;
|
|
52
259
|
element.dataset.state = state;
|
|
@@ -84,7 +291,7 @@ async function switchFrontend(active, url, custom, projectId) {
|
|
|
84
291
|
}
|
|
85
292
|
|
|
86
293
|
function renderStatus(status, context) {
|
|
87
|
-
const { isEditor, isLaunch, customMode, rememberedMode } = context;
|
|
294
|
+
const { isEditor, isSelfhostEditor, isLaunch, customMode, rememberedMode, sliderActive, fallbackEagerMaxMb } = context;
|
|
88
295
|
const target = status && status.target;
|
|
89
296
|
const workspace = status && status.workspace;
|
|
90
297
|
const frontend = status && status.frontend;
|
|
@@ -95,13 +302,65 @@ function renderStatus(status, context) {
|
|
|
95
302
|
const frontendStatus = document.getElementById("frontend-status");
|
|
96
303
|
const workspacePath = document.getElementById("workspace-path");
|
|
97
304
|
const workspaceNote = document.getElementById("workspace-note");
|
|
305
|
+
const frontendNote = document.getElementById("frontend-note");
|
|
98
306
|
const copyPath = document.getElementById("copy-path");
|
|
99
307
|
const useCustom = document.getElementById("use-custom");
|
|
100
308
|
const useOfficial = document.getElementById("use-official");
|
|
309
|
+
const eagerLimit = document.getElementById("eager-limit");
|
|
310
|
+
const eagerLimitValue = document.getElementById("eager-limit-value");
|
|
311
|
+
|
|
312
|
+
if (!sliderActive) {
|
|
313
|
+
const effectiveMb = clampEagerMaxMb(
|
|
314
|
+
(workspace && workspace.eagerMaxMb) ??
|
|
315
|
+
(status && status.daemon && status.daemon.eagerMaxMb) ??
|
|
316
|
+
fallbackEagerMaxMb ??
|
|
317
|
+
2
|
|
318
|
+
);
|
|
319
|
+
eagerLimit.value = String(effectiveMb);
|
|
320
|
+
eagerLimitValue.textContent = `${effectiveMb} MB`;
|
|
321
|
+
}
|
|
101
322
|
|
|
323
|
+
const extensionVersion = chrome.runtime.getManifest().version;
|
|
102
324
|
document.getElementById("version").textContent = status && status.daemon
|
|
103
|
-
? `v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
|
|
104
|
-
:
|
|
325
|
+
? `Extension v${extensionVersion} · Daemon v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
|
|
326
|
+
: `Extension v${extensionVersion} · Daemon unavailable`;
|
|
327
|
+
|
|
328
|
+
const updateBanner = document.getElementById("update-banner");
|
|
329
|
+
const updateStatus = document.getElementById("update-status");
|
|
330
|
+
const updateNote = document.getElementById("update-note");
|
|
331
|
+
const updateApply = document.getElementById("update-apply");
|
|
332
|
+
const updates = status && status.updates;
|
|
333
|
+
const coreUpdate = updates && updates.core;
|
|
334
|
+
const versionMismatch = Boolean(status && status.daemon && status.daemon.version !== extensionVersion);
|
|
335
|
+
const pluginUpdates = (updates && Array.isArray(updates.plugins)
|
|
336
|
+
? updates.plugins.filter((item) => item.updateAvailable)
|
|
337
|
+
: []);
|
|
338
|
+
const pluginsTab = document.getElementById("tab-plugins");
|
|
339
|
+
if (pluginsTab && updates && Array.isArray(updates.plugins)) {
|
|
340
|
+
pluginsTab.textContent = pluginUpdates.length > 0 ? `Plugins · ${pluginUpdates.length}↑` : "Plugins";
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!context.updatingCore) {
|
|
344
|
+
if (coreUpdate && coreUpdate.updateAvailable) {
|
|
345
|
+
updateBanner.hidden = false;
|
|
346
|
+
setStatus(updateStatus, `v${coreUpdate.latestVersion}`, "warning");
|
|
347
|
+
updateNote.classList.toggle("error", false);
|
|
348
|
+
updateNote.textContent = coreUpdate.canSelfUpdate
|
|
349
|
+
? `pcbridge v${coreUpdate.currentVersion} → v${coreUpdate.latestVersion} is available. Updates CLI, daemon, extension, and refreshes PlayCanvas tabs.`
|
|
350
|
+
: `pcbridge v${coreUpdate.latestVersion} is on npm (running from source v${coreUpdate.currentVersion}). Pull git changes and rebuild.`;
|
|
351
|
+
updateApply.disabled = !coreUpdate.canSelfUpdate;
|
|
352
|
+
updateApply.textContent = "Update & Reload";
|
|
353
|
+
} else if (versionMismatch || (coreUpdate && (coreUpdate.daemonRestartRequired || coreUpdate.extensionReloadRequired))) {
|
|
354
|
+
updateBanner.hidden = false;
|
|
355
|
+
setStatus(updateStatus, "Out of sync", "warning");
|
|
356
|
+
updateNote.classList.toggle("error", false);
|
|
357
|
+
updateNote.textContent = `Extension v${extensionVersion} and Daemon v${status.daemon.version} are out of sync.`;
|
|
358
|
+
updateApply.disabled = false;
|
|
359
|
+
updateApply.textContent = "Sync & Reload";
|
|
360
|
+
} else {
|
|
361
|
+
updateBanner.hidden = true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
105
364
|
|
|
106
365
|
if (!status) {
|
|
107
366
|
setStatus(overallStatus, "Offline", "danger");
|
|
@@ -115,7 +374,7 @@ function renderStatus(status, context) {
|
|
|
115
374
|
|
|
116
375
|
document.getElementById("target").textContent = target
|
|
117
376
|
? `${target.kind === "launch" ? "Launch" : "Editor"} · ${target.ready ? "Ready" : "Initializing"}`
|
|
118
|
-
: isEditor || isLaunch
|
|
377
|
+
: isEditor || isSelfhostEditor || isLaunch
|
|
119
378
|
? "Not connected"
|
|
120
379
|
: "Not a PlayCanvas tab";
|
|
121
380
|
document.getElementById("project").textContent = target
|
|
@@ -182,11 +441,19 @@ function renderStatus(status, context) {
|
|
|
182
441
|
: "Waiting for a ready Editor target.";
|
|
183
442
|
}
|
|
184
443
|
|
|
185
|
-
const
|
|
444
|
+
const customExpected = Boolean(isEditor && (customMode || rememberedMode === "custom"));
|
|
445
|
+
const frontendInstalled = Boolean(frontend && frontend.ready);
|
|
446
|
+
const serverReady = Boolean(frontendInstalled && frontend.server && frontend.server.listening);
|
|
186
447
|
setStatus(
|
|
187
448
|
frontendStatus,
|
|
188
|
-
serverReady
|
|
189
|
-
|
|
449
|
+
serverReady
|
|
450
|
+
? "Available"
|
|
451
|
+
: !status
|
|
452
|
+
? "Daemon offline"
|
|
453
|
+
: frontend && frontend.ready
|
|
454
|
+
? "Server stopped"
|
|
455
|
+
: "Not installed",
|
|
456
|
+
serverReady ? "success" : customExpected ? "danger" : status && frontendInstalled ? "warning" : "neutral"
|
|
190
457
|
);
|
|
191
458
|
document.getElementById("frontend").textContent = frontend && frontend.activeRelease
|
|
192
459
|
? frontend.activeRelease
|
|
@@ -198,18 +465,71 @@ function renderStatus(status, context) {
|
|
|
198
465
|
? rememberedMode === "custom" ? "Custom · remembered" : "Official · remembered"
|
|
199
466
|
: isEditor ? "Follow current URL" : "Unavailable";
|
|
200
467
|
|
|
201
|
-
|
|
202
|
-
|
|
468
|
+
const note = !customExpected || serverReady
|
|
469
|
+
? ""
|
|
470
|
+
: !status
|
|
471
|
+
? "Custom frontend unavailable: pcbridge daemon is offline."
|
|
472
|
+
: !frontendInstalled
|
|
473
|
+
? "Custom frontend unavailable: no active frontend release is installed."
|
|
474
|
+
: `Custom frontend unavailable: port ${frontend.server.port} is not listening.`;
|
|
475
|
+
frontendNote.textContent = note;
|
|
476
|
+
frontendNote.hidden = !note;
|
|
477
|
+
frontendNote.classList.toggle("error", Boolean(note));
|
|
478
|
+
|
|
479
|
+
useCustom.disabled = !isEditor || !serverReady || customMode;
|
|
480
|
+
useOfficial.disabled = !isEditor || !customMode;
|
|
203
481
|
}
|
|
204
482
|
|
|
205
483
|
async function main() {
|
|
206
484
|
const [active] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
207
485
|
const url = active && active.url ? new URL(active.url) : null;
|
|
208
486
|
const isEditor = isEditorUrl(url);
|
|
209
|
-
const
|
|
487
|
+
const isSelfhostEditor = Boolean(
|
|
488
|
+
url &&
|
|
489
|
+
(url.protocol === "https:" || url.protocol === "http:") &&
|
|
490
|
+
/^\/editor(?:\/|$)/.test(url.pathname)
|
|
491
|
+
);
|
|
492
|
+
const isLaunch = Boolean(
|
|
493
|
+
url &&
|
|
494
|
+
(url.hostname === "launch.playcanvas.com" ||
|
|
495
|
+
url.hostname === "pc-launch.sightp.com" ||
|
|
496
|
+
/^\/launch\//.test(url.pathname))
|
|
497
|
+
);
|
|
210
498
|
const customMode = Boolean(isEditor && url.searchParams.has("use_local_frontend"));
|
|
499
|
+
const site = await sendRuntimeMessage({ type: "pcbridge:siteStatus", url: url?.href });
|
|
500
|
+
const siteToggle = document.getElementById("site-toggle");
|
|
501
|
+
const siteStatus = document.getElementById("site-status");
|
|
502
|
+
siteStatus.textContent = site?.enabled ? "Enabled" : "Not enabled";
|
|
503
|
+
siteToggle.disabled = !site?.origin || site.builtin;
|
|
504
|
+
siteToggle.textContent = site?.enabled ? "Disable on this site" : "Enable on this site";
|
|
505
|
+
siteToggle.addEventListener("click", async () => {
|
|
506
|
+
const enabled = !site.enabled;
|
|
507
|
+
if (enabled && !(await chrome.permissions.request({ origins: [site.origin] }))) return;
|
|
508
|
+
const result = await sendRuntimeMessage({ type: "pcbridge:setSite", url: url.href, enabled });
|
|
509
|
+
if (!result || result.error) { siteStatus.textContent = result?.error || "Could not update site"; return; }
|
|
510
|
+
site.enabled = result.enabled;
|
|
511
|
+
siteToggle.textContent = site.enabled ? "Disable on this site" : "Enable on this site";
|
|
512
|
+
siteStatus.textContent = site.enabled ? "Enabled. Refresh Editor / Launch to connect." : "Disabled. Existing connections closed.";
|
|
513
|
+
});
|
|
211
514
|
const config = await loadConfig();
|
|
212
|
-
|
|
515
|
+
setupPlugins(config);
|
|
516
|
+
const storedWorkspaceSettings = await sendRuntimeMessage({ type: "pcbridge:getWorkspaceSettings" });
|
|
517
|
+
let fallbackEagerMaxMb = clampEagerMaxMb(storedWorkspaceSettings && storedWorkspaceSettings.eagerMaxMb);
|
|
518
|
+
let status = await loadStatus(config, active && active.id, true);
|
|
519
|
+
if (status && status.updates) {
|
|
520
|
+
void sendRuntimeMessage({ type: "pcbridge:syncUpdateBadge", updates: status.updates });
|
|
521
|
+
}
|
|
522
|
+
if (status && storedWorkspaceSettings && storedWorkspaceSettings.pendingDaemonSync) {
|
|
523
|
+
const synced = await updateDaemonWorkspaceSettings(config, fallbackEagerMaxMb);
|
|
524
|
+
if (synced) {
|
|
525
|
+
await sendRuntimeMessage({
|
|
526
|
+
type: "pcbridge:setWorkspaceSettings",
|
|
527
|
+
eagerMaxMb: fallbackEagerMaxMb,
|
|
528
|
+
pendingDaemonSync: false
|
|
529
|
+
});
|
|
530
|
+
status = await loadStatus(config, active && active.id);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
213
533
|
let projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
|
|
214
534
|
const frontendPreference = isEditor
|
|
215
535
|
? await sendRuntimeMessage({
|
|
@@ -221,12 +541,73 @@ async function main() {
|
|
|
221
541
|
: null;
|
|
222
542
|
const context = {
|
|
223
543
|
isEditor,
|
|
544
|
+
isSelfhostEditor,
|
|
224
545
|
isLaunch,
|
|
225
546
|
customMode,
|
|
226
|
-
rememberedMode: frontendPreference && frontendPreference.mode
|
|
547
|
+
rememberedMode: frontendPreference && frontendPreference.mode,
|
|
548
|
+
sliderActive: false,
|
|
549
|
+
fallbackEagerMaxMb,
|
|
550
|
+
updatingCore: false
|
|
227
551
|
};
|
|
228
552
|
renderStatus(status, context);
|
|
229
553
|
|
|
554
|
+
const updateApply = document.getElementById("update-apply");
|
|
555
|
+
const updateReloadExt = document.getElementById("update-reload-ext");
|
|
556
|
+
const updateNote = document.getElementById("update-note");
|
|
557
|
+
updateReloadExt.addEventListener("click", async () => {
|
|
558
|
+
updateReloadExt.disabled = true;
|
|
559
|
+
await sendRuntimeMessage({ type: "pcbridge:reloadExtension", reloadTabs: true });
|
|
560
|
+
window.close();
|
|
561
|
+
});
|
|
562
|
+
updateApply.addEventListener("click", async () => {
|
|
563
|
+
context.updatingCore = true;
|
|
564
|
+
updateApply.disabled = true;
|
|
565
|
+
updateReloadExt.disabled = true;
|
|
566
|
+
updateNote.classList.toggle("error", false);
|
|
567
|
+
updateNote.textContent = "Updating pcbridge, extension, and skills…";
|
|
568
|
+
const res = await pluginRequest(config, "/update", { includePlugins: true, reloadTabs: true });
|
|
569
|
+
if (!res || !res.ok) {
|
|
570
|
+
context.updatingCore = false;
|
|
571
|
+
updateApply.disabled = false;
|
|
572
|
+
updateReloadExt.disabled = false;
|
|
573
|
+
updateNote.classList.toggle("error", true);
|
|
574
|
+
updateNote.textContent = (res && res.error && res.error.message) || "Update failed.";
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
updateNote.textContent = "Reloading extension and PlayCanvas tabs…";
|
|
578
|
+
await sendRuntimeMessage({ type: "pcbridge:reloadExtension", reloadTabs: true });
|
|
579
|
+
window.close();
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const eagerLimit = document.getElementById("eager-limit");
|
|
583
|
+
const eagerLimitValue = document.getElementById("eager-limit-value");
|
|
584
|
+
eagerLimit.addEventListener("input", () => {
|
|
585
|
+
context.sliderActive = true;
|
|
586
|
+
const mb = clampEagerMaxMb(eagerLimit.value);
|
|
587
|
+
context.fallbackEagerMaxMb = mb;
|
|
588
|
+
eagerLimitValue.textContent = `${mb} MB`;
|
|
589
|
+
});
|
|
590
|
+
eagerLimit.addEventListener("change", async () => {
|
|
591
|
+
const mb = clampEagerMaxMb(eagerLimit.value);
|
|
592
|
+
context.fallbackEagerMaxMb = mb;
|
|
593
|
+
eagerLimit.value = String(mb);
|
|
594
|
+
eagerLimitValue.textContent = `${mb} MB`;
|
|
595
|
+
try {
|
|
596
|
+
const updated = await updateDaemonWorkspaceSettings(config, mb);
|
|
597
|
+
await sendRuntimeMessage({
|
|
598
|
+
type: "pcbridge:setWorkspaceSettings",
|
|
599
|
+
eagerMaxMb: mb,
|
|
600
|
+
pendingDaemonSync: !updated
|
|
601
|
+
});
|
|
602
|
+
if (updated) {
|
|
603
|
+
status = await loadStatus(config, active && active.id);
|
|
604
|
+
}
|
|
605
|
+
} finally {
|
|
606
|
+
context.sliderActive = false;
|
|
607
|
+
renderStatus(status, context);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
|
|
230
611
|
const copyPath = document.getElementById("copy-path");
|
|
231
612
|
const useCustom = document.getElementById("use-custom");
|
|
232
613
|
const useOfficial = document.getElementById("use-official");
|
|
@@ -242,6 +623,9 @@ async function main() {
|
|
|
242
623
|
|
|
243
624
|
setInterval(async () => {
|
|
244
625
|
status = await loadStatus(config, active && active.id);
|
|
626
|
+
if (status && status.updates) {
|
|
627
|
+
void sendRuntimeMessage({ type: "pcbridge:syncUpdateBadge", updates: status.updates });
|
|
628
|
+
}
|
|
245
629
|
projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
|
|
246
630
|
renderStatus(status, context);
|
|
247
631
|
}, 1000);
|