playcanvas-agent-bridge-cli 0.3.0 → 0.5.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 +182 -58
- package/README.zh-CN.md +175 -58
- package/dist/builder/manager.js +456 -0
- package/dist/cli.js +520 -87
- package/dist/config.js +1 -1
- package/dist/daemon/server.js +180 -6
- package/dist/daemon/target-registry.js +43 -3
- package/dist/shared/protocol.js +3 -1
- package/dist/snippets.js +726 -69
- package/dist/workspace/manager.js +1123 -0
- package/extension/icons/concepts/pcbridge-bridge.png +0 -0
- package/extension/icons/concepts/pcbridge-cube.png +0 -0
- package/extension/icons/concepts/pcbridge-p-active.png +0 -0
- package/extension/icons/concepts/pcbridge-p-arch.png +0 -0
- package/extension/icons/concepts/pcbridge-p-bridge.png +0 -0
- package/extension/icons/concepts/pcbridge-p-emblem.png +0 -0
- package/extension/icons/concepts/pcbridge-signal.png +0 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/isolated.js +147 -15
- package/extension/main.js +757 -24
- package/extension/manifest.json +14 -2
- package/extension/popup.html +179 -56
- package/extension/popup.js +204 -62
- package/extension/service-worker.js +331 -17
- package/package.json +3 -1
- package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +93 -28
- package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +148 -57
- package/skills/cursor/playcanvas-agent-bridge-cli.mdc +56 -24
- package/skills/windsurf/playcanvas-agent-bridge-cli.md +55 -25
package/extension/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "PlayCanvas Agent Bridge",
|
|
4
4
|
"description": "Connects open PlayCanvas Editor and Launch tabs to the local pcbridge daemon.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.5.0",
|
|
6
6
|
"permissions": ["activeTab", "storage"],
|
|
7
7
|
"host_permissions": [
|
|
8
8
|
"http://playcanvas.com/*",
|
|
@@ -14,7 +14,19 @@
|
|
|
14
14
|
],
|
|
15
15
|
"action": {
|
|
16
16
|
"default_popup": "popup.html",
|
|
17
|
-
"default_title": "PlayCanvas Agent Bridge"
|
|
17
|
+
"default_title": "PlayCanvas Agent Bridge",
|
|
18
|
+
"default_icon": {
|
|
19
|
+
"16": "icons/icon-16.png",
|
|
20
|
+
"32": "icons/icon-32.png",
|
|
21
|
+
"48": "icons/icon-48.png",
|
|
22
|
+
"128": "icons/icon-128.png"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"icons": {
|
|
26
|
+
"16": "icons/icon-16.png",
|
|
27
|
+
"32": "icons/icon-32.png",
|
|
28
|
+
"48": "icons/icon-48.png",
|
|
29
|
+
"128": "icons/icon-128.png"
|
|
18
30
|
},
|
|
19
31
|
"background": {
|
|
20
32
|
"service_worker": "service-worker.js"
|
package/extension/popup.html
CHANGED
|
@@ -1,88 +1,211 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html>
|
|
2
|
+
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
6
|
<title>PlayCanvas Agent Bridge</title>
|
|
6
7
|
<style>
|
|
8
|
+
:root {
|
|
9
|
+
color-scheme: dark;
|
|
10
|
+
--background: oklch(0.17 0.012 258);
|
|
11
|
+
--surface: oklch(0.215 0.014 258);
|
|
12
|
+
--surface-raised: oklch(0.25 0.016 258);
|
|
13
|
+
--foreground: oklch(0.96 0.008 258);
|
|
14
|
+
--muted: oklch(0.7 0.018 258);
|
|
15
|
+
--border: oklch(0.34 0.018 258);
|
|
16
|
+
--green: oklch(0.76 0.17 151);
|
|
17
|
+
--yellow: oklch(0.82 0.16 83);
|
|
18
|
+
--red: oklch(0.69 0.2 25);
|
|
19
|
+
--gray: oklch(0.58 0.02 258);
|
|
20
|
+
--accent: oklch(0.7 0.16 246);
|
|
21
|
+
--radius: 10px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
* { box-sizing: border-box; }
|
|
25
|
+
|
|
7
26
|
body {
|
|
8
|
-
|
|
9
|
-
|
|
27
|
+
background: var(--background);
|
|
28
|
+
color: var(--foreground);
|
|
29
|
+
font: 13px/1.4 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
10
30
|
margin: 0;
|
|
11
|
-
min-width:
|
|
12
|
-
padding: 14px;
|
|
31
|
+
min-width: 380px;
|
|
13
32
|
}
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
header {
|
|
35
|
+
align-items: center;
|
|
36
|
+
border-bottom: 1px solid var(--border);
|
|
37
|
+
display: flex;
|
|
38
|
+
justify-content: space-between;
|
|
39
|
+
padding: 14px 16px;
|
|
18
40
|
}
|
|
19
41
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
.brand { align-items: center; display: flex; gap: 10px; }
|
|
43
|
+
.brand-mark {
|
|
44
|
+
border: 1px solid color-mix(in oklch, var(--border) 75%, transparent);
|
|
45
|
+
border-radius: 8px;
|
|
46
|
+
display: block;
|
|
47
|
+
height: 28px;
|
|
48
|
+
object-fit: cover;
|
|
49
|
+
width: 28px;
|
|
25
50
|
}
|
|
26
51
|
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
h1 { font-size: 14px; line-height: 1.2; margin: 0; }
|
|
53
|
+
.version { color: var(--muted); font-size: 11px; margin-top: 2px; }
|
|
54
|
+
main { display: grid; gap: 10px; padding: 10px; }
|
|
55
|
+
|
|
56
|
+
section {
|
|
57
|
+
background: var(--surface);
|
|
58
|
+
border: 1px solid var(--border);
|
|
59
|
+
border-radius: var(--radius);
|
|
60
|
+
overflow: hidden;
|
|
29
61
|
}
|
|
30
62
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
63
|
+
.section-heading {
|
|
64
|
+
align-items: center;
|
|
65
|
+
display: flex;
|
|
66
|
+
justify-content: space-between;
|
|
67
|
+
padding: 10px 12px 8px;
|
|
34
68
|
}
|
|
35
69
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
margin
|
|
70
|
+
h2 {
|
|
71
|
+
color: var(--muted);
|
|
72
|
+
font-size: 10px;
|
|
73
|
+
letter-spacing: 0.09em;
|
|
74
|
+
margin: 0;
|
|
75
|
+
text-transform: uppercase;
|
|
41
76
|
}
|
|
42
77
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
padding: 8px;
|
|
78
|
+
.status {
|
|
79
|
+
align-items: center;
|
|
80
|
+
color: var(--muted);
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
font-size: 11px;
|
|
83
|
+
font-weight: 650;
|
|
84
|
+
gap: 6px;
|
|
51
85
|
}
|
|
52
86
|
|
|
53
|
-
|
|
54
|
-
background:
|
|
87
|
+
.status::before {
|
|
88
|
+
background: var(--gray);
|
|
89
|
+
border-radius: 999px;
|
|
90
|
+
box-shadow: 0 0 0 3px color-mix(in oklch, var(--gray) 15%, transparent);
|
|
91
|
+
content: "";
|
|
92
|
+
height: 7px;
|
|
93
|
+
width: 7px;
|
|
55
94
|
}
|
|
56
95
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
96
|
+
.status[data-state="success"] { color: var(--green); }
|
|
97
|
+
.status[data-state="success"]::before { background: var(--green); box-shadow: 0 0 0 3px color-mix(in oklch, var(--green) 15%, transparent); }
|
|
98
|
+
.status[data-state="warning"] { color: var(--yellow); }
|
|
99
|
+
.status[data-state="warning"]::before { background: var(--yellow); box-shadow: 0 0 0 3px color-mix(in oklch, var(--yellow) 15%, transparent); }
|
|
100
|
+
.status[data-state="danger"] { color: var(--red); }
|
|
101
|
+
.status[data-state="danger"]::before { background: var(--red); box-shadow: 0 0 0 3px color-mix(in oklch, var(--red) 15%, transparent); }
|
|
102
|
+
|
|
103
|
+
dl { display: grid; gap: 7px 10px; grid-template-columns: 72px 1fr; margin: 0; padding: 0 12px 11px; }
|
|
104
|
+
dt { color: var(--muted); }
|
|
105
|
+
dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
106
|
+
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
|
|
107
|
+
|
|
108
|
+
.path-row { align-items: center; display: flex; gap: 8px; padding: 0 12px 10px; }
|
|
109
|
+
.path {
|
|
110
|
+
background: var(--background);
|
|
111
|
+
border: 1px solid var(--border);
|
|
112
|
+
border-radius: 7px;
|
|
113
|
+
color: var(--muted);
|
|
114
|
+
flex: 1;
|
|
115
|
+
overflow: hidden;
|
|
116
|
+
padding: 7px 8px;
|
|
117
|
+
text-overflow: ellipsis;
|
|
118
|
+
white-space: nowrap;
|
|
60
119
|
}
|
|
61
120
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
121
|
+
.metrics { display: grid; gap: 1px; grid-template-columns: repeat(4, 1fr); margin: 0 12px 10px; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: var(--border); }
|
|
122
|
+
.metric { background: var(--surface-raised); padding: 8px 5px; text-align: center; }
|
|
123
|
+
.metric strong { display: block; font-size: 14px; }
|
|
124
|
+
.metric span { color: var(--muted); display: block; font-size: 9px; margin-top: 2px; text-transform: uppercase; }
|
|
125
|
+
|
|
126
|
+
.note { color: var(--muted); margin: 0; padding: 0 12px 10px; }
|
|
127
|
+
.note.error { color: var(--red); }
|
|
128
|
+
.actions { display: grid; gap: 7px; grid-template-columns: 1fr 1fr; padding: 0 12px 12px; }
|
|
129
|
+
|
|
130
|
+
button {
|
|
131
|
+
background: var(--surface-raised);
|
|
132
|
+
border: 1px solid var(--border);
|
|
133
|
+
border-radius: 8px;
|
|
134
|
+
color: var(--foreground);
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
font: inherit;
|
|
137
|
+
min-height: 36px;
|
|
138
|
+
padding: 7px 9px;
|
|
139
|
+
transition: background 160ms ease, border-color 160ms ease, transform 120ms ease;
|
|
66
140
|
}
|
|
141
|
+
button:hover:not(:disabled) { background: oklch(0.3 0.02 258); border-color: var(--accent); }
|
|
142
|
+
button:active:not(:disabled) { transform: scale(0.98); }
|
|
143
|
+
button.primary { background: oklch(0.58 0.16 246); border-color: oklch(0.66 0.16 246); }
|
|
144
|
+
button:disabled { cursor: not-allowed; opacity: 0.4; }
|
|
145
|
+
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
146
|
+
[hidden] { display: none !important; }
|
|
67
147
|
</style>
|
|
68
148
|
</head>
|
|
69
149
|
<body>
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
150
|
+
<header>
|
|
151
|
+
<div class="brand">
|
|
152
|
+
<img class="brand-mark" src="icons/icon-32.png" alt="" aria-hidden="true">
|
|
153
|
+
<div>
|
|
154
|
+
<h1>PlayCanvas Agent Bridge</h1>
|
|
155
|
+
<div class="version" id="version">Loading</div>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
<span class="status" id="overall-status" data-state="neutral">Loading</span>
|
|
159
|
+
</header>
|
|
160
|
+
|
|
161
|
+
<main>
|
|
162
|
+
<section aria-labelledby="connection-title">
|
|
163
|
+
<div class="section-heading">
|
|
164
|
+
<h2 id="connection-title">Connection</h2>
|
|
165
|
+
<span class="status" id="daemon-status" data-state="neutral">Checking</span>
|
|
166
|
+
</div>
|
|
167
|
+
<dl>
|
|
168
|
+
<dt>Current tab</dt><dd id="target">Loading</dd>
|
|
169
|
+
<dt>Project</dt><dd id="project">Unavailable</dd>
|
|
170
|
+
<dt>Scene</dt><dd id="scene">Unavailable</dd>
|
|
171
|
+
<dt>Branch</dt><dd id="branch">Unavailable</dd>
|
|
172
|
+
</dl>
|
|
173
|
+
</section>
|
|
174
|
+
|
|
175
|
+
<section aria-labelledby="workspace-title">
|
|
176
|
+
<div class="section-heading">
|
|
177
|
+
<h2 id="workspace-title">Workspace</h2>
|
|
178
|
+
<span class="status" id="workspace-status" data-state="neutral">Unavailable</span>
|
|
179
|
+
</div>
|
|
180
|
+
<div class="path-row">
|
|
181
|
+
<div class="path mono" id="workspace-path" title="">No project workspace</div>
|
|
182
|
+
<button id="copy-path" type="button" aria-label="Copy workspace path" disabled>Copy</button>
|
|
183
|
+
</div>
|
|
184
|
+
<div class="metrics">
|
|
185
|
+
<div class="metric"><strong id="metric-scripts">—</strong><span>Scripts</span></div>
|
|
186
|
+
<div class="metric"><strong id="metric-assets">—</strong><span>Assets</span></div>
|
|
187
|
+
<div class="metric"><strong id="metric-lazy">—</strong><span>Lazy</span></div>
|
|
188
|
+
<div class="metric"><strong id="metric-conflicts">—</strong><span>Conflicts</span></div>
|
|
189
|
+
</div>
|
|
190
|
+
<p class="note" id="workspace-note">Waiting for a ready Editor target.</p>
|
|
191
|
+
</section>
|
|
192
|
+
|
|
193
|
+
<section aria-labelledby="frontend-title">
|
|
194
|
+
<div class="section-heading">
|
|
195
|
+
<h2 id="frontend-title">Editor Frontend</h2>
|
|
196
|
+
<span class="status" id="frontend-status" data-state="neutral">Checking</span>
|
|
197
|
+
</div>
|
|
198
|
+
<dl>
|
|
199
|
+
<dt>Release</dt><dd id="frontend">Not installed</dd>
|
|
200
|
+
<dt>Mode</dt><dd id="mode">Unavailable</dd>
|
|
201
|
+
<dt>Project preference</dt><dd id="frontend-preference">Unavailable</dd>
|
|
202
|
+
</dl>
|
|
203
|
+
<div class="actions">
|
|
204
|
+
<button id="use-custom" class="primary" type="button">Use custom</button>
|
|
205
|
+
<button id="use-official" type="button">Use official</button>
|
|
206
|
+
</div>
|
|
207
|
+
</section>
|
|
208
|
+
</main>
|
|
86
209
|
<script src="popup.js"></script>
|
|
87
210
|
</body>
|
|
88
211
|
</html>
|
package/extension/popup.js
CHANGED
|
@@ -8,15 +8,13 @@ async function loadConfig() {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
async function
|
|
11
|
+
async function loadStatus(config, tabId) {
|
|
12
12
|
if (!config || !config.token) return null;
|
|
13
13
|
try {
|
|
14
14
|
const host = config.host || "127.0.0.1";
|
|
15
15
|
const port = config.port || 17329;
|
|
16
|
-
const response = await fetch(`http://${host}:${port}/
|
|
17
|
-
headers: {
|
|
18
|
-
"X-PCBridge-Token": config.token,
|
|
19
|
-
},
|
|
16
|
+
const response = await fetch(`http://${host}:${port}/status?tabId=${encodeURIComponent(tabId || "")}`, {
|
|
17
|
+
headers: { "X-PCBridge-Token": config.token }
|
|
20
18
|
});
|
|
21
19
|
if (!response.ok) return null;
|
|
22
20
|
const envelope = await response.json();
|
|
@@ -31,82 +29,226 @@ function isEditorUrl(url) {
|
|
|
31
29
|
url &&
|
|
32
30
|
(url.protocol === "https:" || url.protocol === "http:") &&
|
|
33
31
|
url.hostname === "playcanvas.com" &&
|
|
34
|
-
url.pathname.startsWith("/editor")
|
|
32
|
+
url.pathname.startsWith("/editor")
|
|
35
33
|
);
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
if (!
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
function projectIdFromUrl(url) {
|
|
37
|
+
if (!isEditorUrl(url)) return null;
|
|
38
|
+
const match = url.pathname.match(/^\/editor\/project\/(\d+)(?:\/|$)/);
|
|
39
|
+
return match ? match[1] : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function sendRuntimeMessage(message) {
|
|
43
|
+
try {
|
|
44
|
+
return await chrome.runtime.sendMessage(message);
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
44
47
|
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function setStatus(element, label, state) {
|
|
51
|
+
element.textContent = label;
|
|
52
|
+
element.dataset.state = state;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function identity(name, id) {
|
|
56
|
+
if (!name && !id) return "Unavailable";
|
|
57
|
+
if (!name) return String(id);
|
|
58
|
+
return id ? `${name} · ${id}` : String(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function relativeTime(value) {
|
|
62
|
+
if (!value) return "Never synced";
|
|
63
|
+
const seconds = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 1000));
|
|
64
|
+
if (seconds < 10) return "Synced just now";
|
|
65
|
+
if (seconds < 60) return `Synced ${seconds}s ago`;
|
|
66
|
+
const minutes = Math.round(seconds / 60);
|
|
67
|
+
if (minutes < 60) return `Synced ${minutes}m ago`;
|
|
68
|
+
return `Synced ${Math.round(minutes / 60)}h ago`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function switchFrontend(active, url, custom, projectId) {
|
|
72
|
+
if (!active || !url) return;
|
|
73
|
+
await sendRuntimeMessage({
|
|
74
|
+
type: "pcbridge:setFrontendPreference",
|
|
75
|
+
tabId: active.id,
|
|
76
|
+
url: url.toString(),
|
|
77
|
+
projectId,
|
|
78
|
+
mode: custom ? "custom" : "official"
|
|
79
|
+
});
|
|
80
|
+
if (custom) url.searchParams.set("use_local_frontend", "");
|
|
81
|
+
else url.searchParams.delete("use_local_frontend");
|
|
45
82
|
await chrome.tabs.update(active.id, { url: url.toString() });
|
|
46
83
|
window.close();
|
|
47
84
|
}
|
|
48
85
|
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const frontend =
|
|
54
|
-
|
|
55
|
-
const
|
|
86
|
+
function renderStatus(status, context) {
|
|
87
|
+
const { isEditor, isLaunch, customMode, rememberedMode } = context;
|
|
88
|
+
const target = status && status.target;
|
|
89
|
+
const workspace = status && status.workspace;
|
|
90
|
+
const frontend = status && status.frontend;
|
|
91
|
+
|
|
92
|
+
const overallStatus = document.getElementById("overall-status");
|
|
93
|
+
const daemonStatus = document.getElementById("daemon-status");
|
|
94
|
+
const workspaceStatus = document.getElementById("workspace-status");
|
|
95
|
+
const frontendStatus = document.getElementById("frontend-status");
|
|
96
|
+
const workspacePath = document.getElementById("workspace-path");
|
|
97
|
+
const workspaceNote = document.getElementById("workspace-note");
|
|
98
|
+
const copyPath = document.getElementById("copy-path");
|
|
56
99
|
const useCustom = document.getElementById("use-custom");
|
|
57
100
|
const useOfficial = document.getElementById("use-official");
|
|
58
101
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const isLaunch = Boolean(url && url.hostname === "launch.playcanvas.com");
|
|
63
|
-
const customMode = Boolean(isEditor && url.searchParams.has("use_local_frontend"));
|
|
64
|
-
const frontendStatus = await loadFrontendStatus(config);
|
|
65
|
-
const serverReady = Boolean(
|
|
66
|
-
frontendStatus &&
|
|
67
|
-
frontendStatus.ready &&
|
|
68
|
-
frontendStatus.server &&
|
|
69
|
-
frontendStatus.server.listening,
|
|
70
|
-
);
|
|
102
|
+
document.getElementById("version").textContent = status && status.daemon
|
|
103
|
+
? `v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
|
|
104
|
+
: "Daemon unavailable";
|
|
71
105
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
106
|
+
if (!status) {
|
|
107
|
+
setStatus(overallStatus, "Offline", "danger");
|
|
108
|
+
setStatus(daemonStatus, "Disconnected", "danger");
|
|
109
|
+
} else {
|
|
110
|
+
setStatus(daemonStatus, "Connected", "success");
|
|
111
|
+
if (target && target.connected && target.ready) setStatus(overallStatus, "Ready", "success");
|
|
112
|
+
else if (target && target.connected) setStatus(overallStatus, "Initializing", "warning");
|
|
113
|
+
else setStatus(overallStatus, "No target", "warning");
|
|
114
|
+
}
|
|
81
115
|
|
|
82
|
-
|
|
83
|
-
?
|
|
84
|
-
:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
116
|
+
document.getElementById("target").textContent = target
|
|
117
|
+
? `${target.kind === "launch" ? "Launch" : "Editor"} · ${target.ready ? "Ready" : "Initializing"}`
|
|
118
|
+
: isEditor || isLaunch
|
|
119
|
+
? "Not connected"
|
|
120
|
+
: "Not a PlayCanvas tab";
|
|
121
|
+
document.getElementById("project").textContent = target
|
|
122
|
+
? identity(target.projectName, target.projectId)
|
|
123
|
+
: "Unavailable";
|
|
124
|
+
document.getElementById("scene").textContent = target
|
|
125
|
+
? identity(target.sceneName, target.sceneId)
|
|
126
|
+
: "Unavailable";
|
|
127
|
+
document.getElementById("branch").textContent = target
|
|
128
|
+
? identity(target.branchName, target.branchId)
|
|
89
129
|
: "Unavailable";
|
|
90
130
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
131
|
+
const workspaceStates = {
|
|
132
|
+
initializing: ["Initializing", "warning"],
|
|
133
|
+
syncing: ["Syncing", "warning"],
|
|
134
|
+
synced: ["Synced", "success"],
|
|
135
|
+
"local-change": ["Local changes", "warning"],
|
|
136
|
+
"remote-change": ["Remote changes", "warning"],
|
|
137
|
+
conflict: ["Conflict", "danger"],
|
|
138
|
+
error: ["Sync error", "danger"],
|
|
139
|
+
unavailable: ["Unavailable", "neutral"]
|
|
140
|
+
};
|
|
141
|
+
const workspaceState = workspaceStates[(workspace && workspace.state) || "unavailable"] || workspaceStates.unavailable;
|
|
142
|
+
setStatus(workspaceStatus, workspaceState[0], workspaceState[1]);
|
|
143
|
+
|
|
144
|
+
if (workspace && workspace.available) {
|
|
145
|
+
const path = workspace.projectDirectory || workspace.rootDirectory || "";
|
|
146
|
+
workspacePath.textContent = path;
|
|
147
|
+
workspacePath.title = path;
|
|
148
|
+
copyPath.disabled = !path;
|
|
149
|
+
copyPath.dataset.path = path;
|
|
150
|
+
const counts = workspace.counts || {};
|
|
151
|
+
document.getElementById("metric-scripts").textContent = `${counts.scriptsSynced || 0}/${counts.scripts || 0}`;
|
|
152
|
+
document.getElementById("metric-assets").textContent = String(counts.assets || 0);
|
|
153
|
+
document.getElementById("metric-lazy").textContent = String(counts.lazyAssets || 0);
|
|
154
|
+
document.getElementById("metric-conflicts").textContent = String(counts.conflicts || 0);
|
|
155
|
+
const phaseLabels = {
|
|
156
|
+
snapshot: "Reading asset snapshot",
|
|
157
|
+
reconciling: "Comparing workspace files",
|
|
158
|
+
persisting: "Saving project catalog"
|
|
159
|
+
};
|
|
160
|
+
const progress = workspace.progress;
|
|
161
|
+
const actionLabels = {
|
|
162
|
+
comparing: "checking",
|
|
163
|
+
downloading: "downloading",
|
|
164
|
+
uploading: "uploading",
|
|
165
|
+
conflict: "saving conflict"
|
|
166
|
+
};
|
|
167
|
+
const progressText = progress && progress.phase === "reconciling" && Number.isFinite(progress.total)
|
|
168
|
+
? `${phaseLabels.reconciling} ${progress.completed || 0}/${progress.total || 0}` +
|
|
169
|
+
(progress.assetId ? ` · ${actionLabels[progress.action] || "checking"} #${progress.assetId}` : "")
|
|
170
|
+
: progress && phaseLabels[progress.phase];
|
|
171
|
+
workspaceNote.textContent = workspace.lastError || workspace.lastWarning ||
|
|
172
|
+
progressText ||
|
|
173
|
+
relativeTime(workspace.lastSyncedAt);
|
|
174
|
+
workspaceNote.classList.toggle("error", Boolean(workspace.lastError));
|
|
102
175
|
} else {
|
|
103
|
-
|
|
176
|
+
workspacePath.textContent = workspace && workspace.rootDirectory
|
|
177
|
+
? `Root: ${workspace.rootDirectory}`
|
|
178
|
+
: "No project workspace";
|
|
179
|
+
workspacePath.title = workspacePath.textContent;
|
|
180
|
+
workspaceNote.textContent = target && target.kind === "launch"
|
|
181
|
+
? "Workspace synchronization is managed by an Editor target."
|
|
182
|
+
: "Waiting for a ready Editor target.";
|
|
104
183
|
}
|
|
105
184
|
|
|
106
|
-
|
|
107
|
-
|
|
185
|
+
const serverReady = Boolean(frontend && frontend.ready && frontend.server && frontend.server.listening);
|
|
186
|
+
setStatus(
|
|
187
|
+
frontendStatus,
|
|
188
|
+
serverReady ? "Available" : frontend && frontend.ready ? "Server stopped" : "Not installed",
|
|
189
|
+
serverReady ? "success" : frontend && frontend.ready ? "warning" : "neutral"
|
|
190
|
+
);
|
|
191
|
+
document.getElementById("frontend").textContent = frontend && frontend.activeRelease
|
|
192
|
+
? frontend.activeRelease
|
|
193
|
+
: "Not installed";
|
|
194
|
+
document.getElementById("mode").textContent = isEditor
|
|
195
|
+
? customMode ? "Custom" : "Official"
|
|
196
|
+
: "Unavailable";
|
|
197
|
+
document.getElementById("frontend-preference").textContent = rememberedMode
|
|
198
|
+
? rememberedMode === "custom" ? "Custom · remembered" : "Official · remembered"
|
|
199
|
+
: isEditor ? "Follow current URL" : "Unavailable";
|
|
200
|
+
|
|
201
|
+
useCustom.disabled = !isEditor || !serverReady || rememberedMode === "custom" || (!rememberedMode && customMode);
|
|
202
|
+
useOfficial.disabled = !isEditor || rememberedMode === "official" || (!rememberedMode && !customMode);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function main() {
|
|
206
|
+
const [active] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
207
|
+
const url = active && active.url ? new URL(active.url) : null;
|
|
208
|
+
const isEditor = isEditorUrl(url);
|
|
209
|
+
const isLaunch = Boolean(url && url.hostname === "launch.playcanvas.com");
|
|
210
|
+
const customMode = Boolean(isEditor && url.searchParams.has("use_local_frontend"));
|
|
211
|
+
const config = await loadConfig();
|
|
212
|
+
let status = await loadStatus(config, active && active.id);
|
|
213
|
+
let projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
|
|
214
|
+
const frontendPreference = isEditor
|
|
215
|
+
? await sendRuntimeMessage({
|
|
216
|
+
type: "pcbridge:getFrontendPreference",
|
|
217
|
+
tabId: active && active.id,
|
|
218
|
+
url: url && url.toString(),
|
|
219
|
+
projectId
|
|
220
|
+
})
|
|
221
|
+
: null;
|
|
222
|
+
const context = {
|
|
223
|
+
isEditor,
|
|
224
|
+
isLaunch,
|
|
225
|
+
customMode,
|
|
226
|
+
rememberedMode: frontendPreference && frontendPreference.mode
|
|
227
|
+
};
|
|
228
|
+
renderStatus(status, context);
|
|
229
|
+
|
|
230
|
+
const copyPath = document.getElementById("copy-path");
|
|
231
|
+
const useCustom = document.getElementById("use-custom");
|
|
232
|
+
const useOfficial = document.getElementById("use-official");
|
|
233
|
+
useCustom.addEventListener("click", () => switchFrontend(active, url, true, projectId));
|
|
234
|
+
useOfficial.addEventListener("click", () => switchFrontend(active, url, false, projectId));
|
|
235
|
+
copyPath.addEventListener("click", async () => {
|
|
236
|
+
const path = copyPath.dataset.path;
|
|
237
|
+
if (!path || !navigator.clipboard) return;
|
|
238
|
+
await navigator.clipboard.writeText(path);
|
|
239
|
+
copyPath.textContent = "Copied";
|
|
240
|
+
setTimeout(() => { copyPath.textContent = "Copy"; }, 1000);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
setInterval(async () => {
|
|
244
|
+
status = await loadStatus(config, active && active.id);
|
|
245
|
+
projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
|
|
246
|
+
renderStatus(status, context);
|
|
247
|
+
}, 1000);
|
|
108
248
|
}
|
|
109
249
|
|
|
110
250
|
main().catch((error) => {
|
|
111
|
-
document.getElementById("
|
|
251
|
+
setStatus(document.getElementById("overall-status"), "Error", "danger");
|
|
252
|
+
document.getElementById("workspace-note").textContent = String(error);
|
|
253
|
+
document.getElementById("workspace-note").classList.add("error");
|
|
112
254
|
});
|