@muloka/figma-console-mcp 0.6.5 → 0.6.6
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 +12 -5
- package/dist/apps/design-system-dashboard/mcp-app.html +20 -20
- package/dist/apps/design-system-dashboard/scoring/accessibility.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/accessibility.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/accessibility.js.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/coverage.js.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js +2 -1
- package/dist/apps/design-system-dashboard/scoring/token-architecture.js.map +1 -1
- package/dist/apps/design-system-dashboard/server.d.ts.map +1 -1
- package/dist/apps/design-system-dashboard/server.js +2 -1
- package/dist/apps/design-system-dashboard/server.js.map +1 -1
- package/dist/core/annotation-tools.d.ts.map +1 -1
- package/dist/core/annotation-tools.js +7 -6
- package/dist/core/annotation-tools.js.map +1 -1
- package/dist/core/comment-tools.d.ts.map +1 -1
- package/dist/core/comment-tools.js +4 -3
- package/dist/core/comment-tools.js.map +1 -1
- package/dist/core/deep-component-tools.d.ts.map +1 -1
- package/dist/core/deep-component-tools.js +5 -4
- package/dist/core/deep-component-tools.js.map +1 -1
- package/dist/core/design-code-tools.d.ts.map +1 -1
- package/dist/core/design-code-tools.js +4 -3
- package/dist/core/design-code-tools.js.map +1 -1
- package/dist/core/design-system-tools.d.ts.map +1 -1
- package/dist/core/design-system-tools.js +2 -1
- package/dist/core/design-system-tools.js.map +1 -1
- package/dist/core/diagnose-tool.d.ts +2 -0
- package/dist/core/diagnose-tool.d.ts.map +1 -1
- package/dist/core/diagnose-tool.js +6 -5
- package/dist/core/diagnose-tool.js.map +1 -1
- package/dist/core/figjam-tools.d.ts.map +1 -1
- package/dist/core/figjam-tools.js +5 -4
- package/dist/core/figjam-tools.js.map +1 -1
- package/dist/core/figma-api.d.ts.map +1 -1
- package/dist/core/figma-api.js +2 -1
- package/dist/core/figma-api.js.map +1 -1
- package/dist/core/figma-tools.d.ts.map +1 -1
- package/dist/core/figma-tools.js +39 -38
- package/dist/core/figma-tools.js.map +1 -1
- package/dist/core/library-tools.d.ts.map +1 -1
- package/dist/core/library-tools.js +7 -6
- package/dist/core/library-tools.js.map +1 -1
- package/dist/core/logger.d.ts +11 -0
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +13 -1
- package/dist/core/logger.js.map +1 -1
- package/dist/core/plugin-import-dir.d.ts +9 -0
- package/dist/core/plugin-import-dir.d.ts.map +1 -0
- package/dist/core/plugin-import-dir.js +47 -0
- package/dist/core/plugin-import-dir.js.map +1 -0
- package/dist/core/plugin-name.d.ts +26 -0
- package/dist/core/plugin-name.d.ts.map +1 -0
- package/dist/core/plugin-name.js +35 -0
- package/dist/core/plugin-name.js.map +1 -0
- package/dist/core/port-discovery.d.ts +2 -2
- package/dist/core/port-discovery.d.ts.map +1 -1
- package/dist/core/port-discovery.js +8 -6
- package/dist/core/port-discovery.js.map +1 -1
- package/dist/core/slides-tools.d.ts.map +1 -1
- package/dist/core/slides-tools.js +2 -1
- package/dist/core/slides-tools.js.map +1 -1
- package/dist/core/slot-tools.d.ts.map +1 -1
- package/dist/core/slot-tools.js +3 -2
- package/dist/core/slot-tools.js.map +1 -1
- package/dist/core/tokens-tools.d.ts.map +1 -1
- package/dist/core/tokens-tools.js +2 -1
- package/dist/core/tokens-tools.js.map +1 -1
- package/dist/core/variable-resolver.d.ts.map +1 -1
- package/dist/core/variable-resolver.js +3 -2
- package/dist/core/variable-resolver.js.map +1 -1
- package/dist/core/version-tools.d.ts.map +1 -1
- package/dist/core/version-tools.js +9 -8
- package/dist/core/version-tools.js.map +1 -1
- package/dist/core/websocket-connector.d.ts.map +1 -1
- package/dist/core/websocket-connector.js +3 -2
- package/dist/core/websocket-connector.js.map +1 -1
- package/dist/core/websocket-server.d.ts.map +1 -1
- package/dist/core/websocket-server.js +6 -5
- package/dist/core/websocket-server.js.map +1 -1
- package/dist/core/write-tools.d.ts.map +1 -1
- package/dist/core/write-tools.js +283 -232
- package/dist/core/write-tools.js.map +1 -1
- package/dist/local.d.ts +1 -1
- package/dist/local.d.ts.map +1 -1
- package/dist/local.js +76 -147
- package/dist/local.js.map +1 -1
- package/figma-desktop-bridge/README.md +15 -63
- package/figma-desktop-bridge/code.js +31 -29
- package/figma-desktop-bridge/manifest.json +5 -9
- package/figma-desktop-bridge/ui.html +768 -924
- package/package.json +1 -1
|
@@ -9,407 +9,334 @@
|
|
|
9
9
|
padding: 0;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
--
|
|
23
|
-
--
|
|
12
|
+
[hidden] {
|
|
13
|
+
display: none !important;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* ===== Colour tokens =====
|
|
17
|
+
applyTheme() mirrors Figma's theme onto body[data-theme]. The window
|
|
18
|
+
background is Figma's own --figma-color-bg (showUI themeColors);
|
|
19
|
+
--bg-fallback only applies where Figma injects nothing. */
|
|
20
|
+
body[data-theme="dark"] {
|
|
21
|
+
color-scheme: dark;
|
|
22
|
+
--bg-fallback: #2c2c2c;
|
|
23
|
+
--scroll-thumb: rgba(255, 255, 255, 0.28);
|
|
24
|
+
--scroll-thumb-hover: rgba(255, 255, 255, 0.45);
|
|
25
|
+
--text-1: rgba(255, 255, 255, 0.92);
|
|
26
|
+
--text-2: rgba(255, 255, 255, 0.7);
|
|
27
|
+
--text-3: rgba(255, 255, 255, 0.55);
|
|
28
|
+
--divider: #3a3a3a;
|
|
29
|
+
--link: #4db5ff;
|
|
30
|
+
--bad: #ff8f78;
|
|
31
|
+
--update-bg: rgba(13, 153, 255, 0.14);
|
|
32
|
+
--update-border: rgba(13, 153, 255, 0.4);
|
|
33
|
+
--update-dot: #0d99ff;
|
|
34
|
+
--status-ok: #3ccf7f;
|
|
35
|
+
--status-wait: #f7bd5c;
|
|
36
|
+
--status-pause: rgba(255, 255, 255, 0.75);
|
|
37
|
+
--status-err: #ff8f78;
|
|
38
|
+
--pressed-bg: rgba(255, 255, 255, 0.1);
|
|
39
|
+
--resume-bg: rgba(20, 174, 92, 0.2);
|
|
40
|
+
--resume-icon: #3ccf7f;
|
|
41
|
+
}
|
|
42
|
+
body[data-theme="light"] {
|
|
43
|
+
color-scheme: light;
|
|
44
|
+
--bg-fallback: #ffffff;
|
|
45
|
+
--scroll-thumb: rgba(0, 0, 0, 0.25);
|
|
46
|
+
--scroll-thumb-hover: rgba(0, 0, 0, 0.42);
|
|
47
|
+
--text-1: rgba(0, 0, 0, 0.9);
|
|
48
|
+
--text-2: rgba(0, 0, 0, 0.62);
|
|
49
|
+
--text-3: rgba(0, 0, 0, 0.58);
|
|
50
|
+
--divider: #e6e6e6;
|
|
51
|
+
--link: #0a6dc2;
|
|
52
|
+
--bad: #c4320a;
|
|
53
|
+
--update-bg: rgba(13, 153, 255, 0.08);
|
|
54
|
+
--update-border: rgba(13, 153, 255, 0.35);
|
|
55
|
+
--update-dot: #0d99ff;
|
|
56
|
+
--status-ok: #0b8a47;
|
|
57
|
+
--status-wait: #9a5b00;
|
|
58
|
+
--status-pause: rgba(0, 0, 0, 0.6);
|
|
59
|
+
--status-err: #c4320a;
|
|
60
|
+
--pressed-bg: rgba(0, 0, 0, 0.06);
|
|
61
|
+
--resume-bg: rgba(20, 174, 92, 0.14);
|
|
62
|
+
--resume-icon: #0b8a47;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
html,
|
|
66
|
+
body {
|
|
67
|
+
margin: 0;
|
|
68
|
+
padding: 0;
|
|
24
69
|
}
|
|
25
70
|
|
|
26
71
|
body {
|
|
27
|
-
font-family:
|
|
72
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
28
73
|
font-size: 11px;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
74
|
+
line-height: 14px;
|
|
75
|
+
background: var(--figma-color-bg, var(--bg-fallback, #2c2c2c));
|
|
76
|
+
color: var(--text-1);
|
|
32
77
|
user-select: none;
|
|
33
78
|
}
|
|
34
79
|
|
|
35
80
|
/* Visible keyboard focus for all interactive elements (WCAG 2.4.7) */
|
|
36
|
-
button:focus-visible
|
|
37
|
-
input:focus-visible {
|
|
81
|
+
button:focus-visible {
|
|
38
82
|
outline: 2px solid var(--figma-color-bg-brand, #0d99ff);
|
|
39
83
|
outline-offset: 1px;
|
|
40
|
-
border-radius: 3px;
|
|
41
84
|
}
|
|
42
85
|
/* Hide outline when mouse-clicking but keep it for keyboard nav */
|
|
43
|
-
button:focus:not(:focus-visible)
|
|
44
|
-
input:focus:not(:focus-visible) {
|
|
86
|
+
button:focus:not(:focus-visible) {
|
|
45
87
|
outline: none;
|
|
46
88
|
}
|
|
47
89
|
|
|
48
|
-
.wrap
|
|
90
|
+
.wrap,
|
|
91
|
+
.full {
|
|
49
92
|
display: flex;
|
|
50
93
|
flex-direction: column;
|
|
51
|
-
gap: 4px;
|
|
52
94
|
width: 100%;
|
|
53
95
|
}
|
|
54
96
|
|
|
55
|
-
/* =====
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
gap: 6px;
|
|
60
|
-
white-space: nowrap;
|
|
61
|
-
padding-left: 4px; /* visual offset to align with Figma title bar icon */
|
|
97
|
+
/* ===== Status text: two one-line rows, 40px in all ===== */
|
|
98
|
+
.status {
|
|
99
|
+
height: 40px;
|
|
100
|
+
padding: 8px 12px 2px;
|
|
62
101
|
}
|
|
63
102
|
|
|
64
|
-
.status-
|
|
103
|
+
.status-line {
|
|
65
104
|
display: flex;
|
|
66
105
|
align-items: center;
|
|
67
|
-
gap:
|
|
68
|
-
|
|
69
|
-
/* Take the free space so long status sentences ellipsize gracefully
|
|
70
|
-
instead of pushing the CTA/icons off the 240px canvas. */
|
|
71
|
-
flex: 1;
|
|
72
|
-
min-width: 0;
|
|
106
|
+
gap: 6px;
|
|
107
|
+
height: 14px;
|
|
73
108
|
}
|
|
74
109
|
|
|
75
|
-
.status-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
110
|
+
.status-icon {
|
|
111
|
+
display: inline-flex;
|
|
112
|
+
width: 14px;
|
|
113
|
+
height: 14px;
|
|
79
114
|
flex-shrink: 0;
|
|
80
|
-
background: var(--color-idle);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.status-indicator.loading {
|
|
84
|
-
background: var(--color-waiting);
|
|
85
|
-
animation: pulse 1.5s ease-in-out infinite;
|
|
86
115
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
116
|
+
.status-icon svg {
|
|
117
|
+
display: block;
|
|
118
|
+
width: 14px;
|
|
119
|
+
height: 14px;
|
|
91
120
|
}
|
|
121
|
+
.status-icon[data-badge="ok"] { color: var(--status-ok); }
|
|
122
|
+
.status-icon[data-badge="wait"] { color: var(--status-wait); }
|
|
123
|
+
.status-icon[data-badge="pause"] { color: var(--status-pause); }
|
|
124
|
+
.status-icon[data-badge="err"] { color: var(--status-err); }
|
|
92
125
|
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
/* The wait icon's track is a full circle, so turning the whole icon
|
|
127
|
+
spins only the arc. */
|
|
128
|
+
.status-icon[data-badge="wait"] svg {
|
|
129
|
+
animation: status-spin 1s linear infinite;
|
|
95
130
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
animation, so a pause never reads as "trying to connect". */
|
|
99
|
-
.status-indicator.paused {
|
|
100
|
-
background: var(--color-idle);
|
|
131
|
+
@keyframes status-spin {
|
|
132
|
+
to { transform: rotate(360deg); }
|
|
101
133
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
0%, 100% { opacity: 0.4; }
|
|
105
|
-
50% { opacity: 1; }
|
|
134
|
+
@media (prefers-reduced-motion: reduce) {
|
|
135
|
+
.status-icon[data-badge="wait"] svg { animation-duration: 4s; }
|
|
106
136
|
}
|
|
107
137
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
font-
|
|
111
|
-
|
|
112
|
-
font-stretch: 75%;
|
|
113
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.6));
|
|
138
|
+
.status-title {
|
|
139
|
+
min-width: 0;
|
|
140
|
+
font-weight: 500;
|
|
141
|
+
color: var(--text-2);
|
|
114
142
|
overflow: hidden;
|
|
115
143
|
text-overflow: ellipsis;
|
|
116
144
|
white-space: nowrap;
|
|
117
|
-
min-width: 0;
|
|
118
145
|
}
|
|
119
146
|
|
|
120
|
-
.status-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.status-indicator.error + #status-state {
|
|
125
|
-
color: var(--color-error);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.cta-btn {
|
|
129
|
-
background: transparent;
|
|
130
|
-
color: var(--figma-color-text, rgba(255, 255, 255, 0.9));
|
|
131
|
-
border: 1px solid var(--figma-color-border, #4a4a4a);
|
|
132
|
-
border-radius: 3px;
|
|
133
|
-
font-family: inherit;
|
|
134
|
-
font-size: 10px;
|
|
135
|
-
font-weight: 500;
|
|
136
|
-
padding: 4px;
|
|
137
|
-
cursor: pointer;
|
|
138
|
-
line-height: 1.4;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
.cta-btn:disabled {
|
|
142
|
-
opacity: 0.6;
|
|
143
|
-
cursor: default;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.cta-btn:hover {
|
|
147
|
-
background: var(--figma-color-bg-secondary, #383838);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* ===== Status meta line — connection count + proof of life ===== */
|
|
151
|
-
.status-meta {
|
|
152
|
-
display: none; /* toggled to flex from JS when there's something to show */
|
|
153
|
-
align-items: center;
|
|
154
|
-
gap: 8px;
|
|
155
|
-
padding-left: 17px; /* aligns with the pill text (4px row offset + 8px dot + 5px gap) */
|
|
156
|
-
font-size: 9px;
|
|
157
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.5));
|
|
147
|
+
.status-count {
|
|
148
|
+
flex-shrink: 0;
|
|
149
|
+
color: var(--text-3);
|
|
158
150
|
white-space: nowrap;
|
|
159
151
|
}
|
|
160
152
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
font-size: 9px;
|
|
169
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.5));
|
|
153
|
+
.status-sub {
|
|
154
|
+
height: 14px;
|
|
155
|
+
margin-top: 2px;
|
|
156
|
+
padding-left: 20px; /* 14px icon + 6px gap: lines up under the title */
|
|
157
|
+
color: var(--text-3);
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
text-overflow: ellipsis;
|
|
170
160
|
white-space: nowrap;
|
|
171
161
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.status-error-hint {
|
|
175
|
-
display: none; /* shown from JS while in the error state */
|
|
176
|
-
padding-left: 17px;
|
|
177
|
-
font-size: 10px;
|
|
178
|
-
line-height: 1.4;
|
|
179
|
-
color: var(--color-error);
|
|
162
|
+
.status-sub.is-bad {
|
|
163
|
+
color: var(--bad);
|
|
180
164
|
}
|
|
181
165
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
border-radius: 3px;
|
|
186
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.6));
|
|
187
|
-
width: 24px;
|
|
188
|
-
height: 24px;
|
|
189
|
-
padding: 0;
|
|
166
|
+
/* ===== Icon buttons ===== */
|
|
167
|
+
.btn {
|
|
168
|
+
position: relative;
|
|
190
169
|
display: inline-flex;
|
|
191
170
|
align-items: center;
|
|
192
171
|
justify-content: center;
|
|
172
|
+
flex-shrink: 0;
|
|
173
|
+
width: 24px;
|
|
174
|
+
height: 24px;
|
|
175
|
+
padding: 0;
|
|
176
|
+
border: none;
|
|
177
|
+
border-radius: 6px;
|
|
178
|
+
background: transparent;
|
|
179
|
+
color: var(--text-2);
|
|
180
|
+
font: inherit;
|
|
193
181
|
cursor: pointer;
|
|
194
|
-
font-family: inherit;
|
|
195
|
-
font-size: 14px;
|
|
196
|
-
line-height: 1;
|
|
197
182
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
183
|
+
.btn svg {
|
|
184
|
+
display: block;
|
|
185
|
+
width: 14px;
|
|
186
|
+
height: 14px;
|
|
202
187
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
.icon-btn--borderless,
|
|
207
|
-
.icon-btn--borderless:hover,
|
|
208
|
-
.icon-btn--borderless.active {
|
|
209
|
-
border-color: transparent !important;
|
|
188
|
+
.btn:hover {
|
|
189
|
+
background: var(--pressed-bg);
|
|
190
|
+
color: var(--text-1);
|
|
210
191
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
font-size: 18px;
|
|
215
|
-
font-weight: 400;
|
|
216
|
-
line-height: 1;
|
|
192
|
+
.btn[aria-expanded="true"] {
|
|
193
|
+
background: var(--pressed-bg);
|
|
194
|
+
color: var(--text-1);
|
|
217
195
|
}
|
|
218
|
-
|
|
219
|
-
.
|
|
220
|
-
|
|
221
|
-
color: var(--
|
|
222
|
-
border-color: var(--figma-color-bg-brand, #0d99ff);
|
|
196
|
+
.btn.is-resume,
|
|
197
|
+
.btn.is-resume:hover {
|
|
198
|
+
background: var(--resume-bg);
|
|
199
|
+
color: var(--resume-icon);
|
|
223
200
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
height: 14px;
|
|
201
|
+
.btn-small {
|
|
202
|
+
width: 20px;
|
|
203
|
+
height: 20px;
|
|
228
204
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
display: none;
|
|
233
|
-
width: 100%;
|
|
205
|
+
.btn-small svg {
|
|
206
|
+
width: 12px;
|
|
207
|
+
height: 12px;
|
|
234
208
|
}
|
|
235
209
|
|
|
236
|
-
|
|
210
|
+
/* ===== Controls row: 28px ===== */
|
|
211
|
+
.controls {
|
|
237
212
|
display: flex;
|
|
213
|
+
align-items: center;
|
|
214
|
+
justify-content: space-between;
|
|
215
|
+
height: 28px;
|
|
216
|
+
padding: 0 6px 4px;
|
|
217
|
+
}
|
|
218
|
+
.controls-left {
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: center;
|
|
221
|
+
gap: 2px;
|
|
238
222
|
}
|
|
239
223
|
|
|
240
|
-
|
|
241
|
-
|
|
224
|
+
/* ===== Plugin update strip ===== */
|
|
225
|
+
.update-strip {
|
|
226
|
+
display: flex;
|
|
227
|
+
align-items: flex-start;
|
|
242
228
|
gap: 4px;
|
|
243
|
-
|
|
229
|
+
margin: 6px 12px 4px;
|
|
230
|
+
padding: 8px 6px 8px 10px;
|
|
231
|
+
border: 1px solid var(--update-border);
|
|
232
|
+
border-radius: 8px;
|
|
233
|
+
background: var(--update-bg);
|
|
244
234
|
}
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
.update-text {
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: column;
|
|
238
|
+
gap: 2px;
|
|
247
239
|
flex: 1;
|
|
248
240
|
min-width: 0;
|
|
249
|
-
background: var(--figma-color-bg, #2c2c2c);
|
|
250
|
-
border: 1px solid var(--figma-color-border, #4a4a4a);
|
|
251
|
-
border-radius: 3px;
|
|
252
|
-
color: var(--figma-color-text, rgba(255, 255, 255, 0.9));
|
|
253
|
-
font-family: monospace;
|
|
254
|
-
font-size: 11px;
|
|
255
|
-
padding: 3px 5px;
|
|
256
|
-
text-transform: uppercase;
|
|
257
|
-
letter-spacing: 2px;
|
|
258
|
-
text-align: center;
|
|
259
|
-
box-sizing: border-box;
|
|
260
241
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
text-
|
|
264
|
-
letter-spacing: normal;
|
|
265
|
-
font-family: inherit;
|
|
266
|
-
font-size: 10px;
|
|
267
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.3));
|
|
242
|
+
.update-title {
|
|
243
|
+
font-weight: 600;
|
|
244
|
+
color: var(--text-1);
|
|
268
245
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
.cloud-pair button:not(.icon-btn) {
|
|
272
|
-
flex-shrink: 0;
|
|
273
|
-
background: var(--figma-color-bg-brand, #0d99ff);
|
|
274
|
-
color: #fff;
|
|
275
|
-
border: none;
|
|
276
|
-
border-radius: 3px;
|
|
277
|
-
font-family: inherit;
|
|
278
|
-
font-size: 10px;
|
|
279
|
-
font-weight: 500;
|
|
280
|
-
padding: 4px 10px;
|
|
281
|
-
cursor: pointer;
|
|
246
|
+
.update-body {
|
|
247
|
+
color: var(--text-2);
|
|
282
248
|
}
|
|
283
249
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
.cloud-help {
|
|
250
|
+
/* ===== Activity log ===== */
|
|
251
|
+
.log-panel {
|
|
252
|
+
display: flex;
|
|
290
253
|
flex-direction: column;
|
|
291
|
-
gap:
|
|
292
|
-
padding: 6px
|
|
293
|
-
|
|
294
|
-
border-radius: 3px;
|
|
295
|
-
font-size: 10px;
|
|
296
|
-
line-height: 1.4;
|
|
297
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.7));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.cloud-help p {
|
|
301
|
-
margin: 0;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
body[data-theme="light"] .cloud-help {
|
|
305
|
-
background: #f0f0f0;
|
|
306
|
-
color: #555;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
.cloud-status {
|
|
310
|
-
display: none;
|
|
311
|
-
font-size: 9px;
|
|
312
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.5));
|
|
313
|
-
text-align: center;
|
|
314
|
-
padding: 2px 0;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
.cloud-status:not(:empty) {
|
|
318
|
-
display: block;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
.cloud-status.connected {
|
|
322
|
-
color: var(--color-connected);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
.cloud-status.error {
|
|
326
|
-
color: var(--color-error);
|
|
254
|
+
gap: 6px;
|
|
255
|
+
padding: 6px 12px 10px;
|
|
256
|
+
border-top: 1px solid var(--divider);
|
|
327
257
|
}
|
|
328
258
|
|
|
329
|
-
|
|
330
|
-
|
|
259
|
+
.log-header {
|
|
260
|
+
display: flex;
|
|
331
261
|
align-items: center;
|
|
262
|
+
justify-content: space-between;
|
|
332
263
|
gap: 8px;
|
|
333
|
-
flex-wrap: nowrap;
|
|
334
|
-
padding-left: 4px; /* match row-top alignment with Figma title bar icon */
|
|
335
264
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
background: transparent;
|
|
339
|
-
border: none;
|
|
340
|
-
padding: 2px 0;
|
|
341
|
-
color: var(--figma-color-text-secondary, rgba(255, 255, 255, 0.6));
|
|
342
|
-
font-family: inherit;
|
|
265
|
+
.log-version {
|
|
266
|
+
min-width: 0;
|
|
343
267
|
font-size: 10px;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
gap: 3px;
|
|
268
|
+
color: var(--text-3);
|
|
269
|
+
overflow: hidden;
|
|
270
|
+
text-overflow: ellipsis;
|
|
348
271
|
white-space: nowrap;
|
|
349
272
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
color: var(--figma-color-text, rgba(255, 255, 255, 0.9));
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
.sub-btn.active {
|
|
356
|
-
color: var(--figma-color-bg-brand, #0d99ff);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
.sub-btn svg {
|
|
360
|
-
width: 11px;
|
|
361
|
-
height: 11px;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/* ===== Row: plugin update banner ===== */
|
|
365
|
-
.update-banner {
|
|
273
|
+
.log-copy {
|
|
274
|
+
display: inline-flex;
|
|
366
275
|
align-items: center;
|
|
367
|
-
gap:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
border:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
276
|
+
gap: 4px;
|
|
277
|
+
flex-shrink: 0;
|
|
278
|
+
padding: 0;
|
|
279
|
+
border: none;
|
|
280
|
+
background: transparent;
|
|
281
|
+
color: var(--link);
|
|
282
|
+
font: inherit;
|
|
283
|
+
font-size: 11px;
|
|
284
|
+
cursor: pointer;
|
|
375
285
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
286
|
+
.log-copy svg {
|
|
287
|
+
display: block;
|
|
288
|
+
width: 12px;
|
|
289
|
+
height: 12px;
|
|
380
290
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
.log-panel {
|
|
384
|
-
flex-direction: column;
|
|
385
|
-
gap: 0;
|
|
386
|
-
border: 1px solid var(--figma-color-border, #4a4a4a);
|
|
387
|
-
border-radius: 3px;
|
|
388
|
-
overflow: hidden;
|
|
389
|
-
background: var(--figma-color-bg, #1e1e1e);
|
|
291
|
+
.log-copy:hover {
|
|
292
|
+
text-decoration: underline;
|
|
390
293
|
}
|
|
391
294
|
|
|
392
295
|
.log-entries {
|
|
393
296
|
max-height: 160px;
|
|
394
297
|
overflow-y: auto;
|
|
395
|
-
padding: 4px 6px;
|
|
396
|
-
font-family: 'SF Mono', 'Menlo', Consolas, monospace;
|
|
397
|
-
font-size: 10px;
|
|
398
|
-
line-height: 1.4;
|
|
399
298
|
}
|
|
400
|
-
|
|
299
|
+
/* Where scrollbars take up room (Windows, Linux, a Mac set to always show
|
|
300
|
+
them), Chromium draws a bright one with arrows. There the log gets a thin
|
|
301
|
+
one in the theme's colours; macOS overlay scrollbars are left alone
|
|
302
|
+
(body[data-scrollbars] is set at startup by measuring one). Only
|
|
303
|
+
::-webkit-scrollbar: setting scrollbar-width or scrollbar-color would
|
|
304
|
+
turn these rules off in Chromium. */
|
|
305
|
+
body[data-scrollbars="thin"] .log-entries {
|
|
306
|
+
padding-right: 4px;
|
|
307
|
+
}
|
|
308
|
+
body[data-scrollbars="thin"] .log-entries::-webkit-scrollbar {
|
|
309
|
+
width: 8px;
|
|
310
|
+
}
|
|
311
|
+
body[data-scrollbars="thin"] .log-entries::-webkit-scrollbar-track {
|
|
312
|
+
background: transparent;
|
|
313
|
+
}
|
|
314
|
+
body[data-scrollbars="thin"] .log-entries::-webkit-scrollbar-button {
|
|
315
|
+
display: none;
|
|
316
|
+
width: 0;
|
|
317
|
+
height: 0;
|
|
318
|
+
}
|
|
319
|
+
body[data-scrollbars="thin"] .log-entries::-webkit-scrollbar-thumb {
|
|
320
|
+
background-color: var(--scroll-thumb);
|
|
321
|
+
border: 1px solid transparent;
|
|
322
|
+
background-clip: content-box;
|
|
323
|
+
border-radius: 4px;
|
|
324
|
+
}
|
|
325
|
+
body[data-scrollbars="thin"] .log-entries::-webkit-scrollbar-thumb:hover {
|
|
326
|
+
background-color: var(--scroll-thumb-hover);
|
|
327
|
+
}
|
|
401
328
|
.log-entry {
|
|
402
329
|
display: flex;
|
|
403
330
|
align-items: baseline;
|
|
404
|
-
gap:
|
|
405
|
-
|
|
406
|
-
line-height:
|
|
331
|
+
gap: 6px;
|
|
332
|
+
font-size: 11px;
|
|
333
|
+
line-height: 16px;
|
|
334
|
+
color: var(--text-2);
|
|
407
335
|
}
|
|
408
336
|
.log-ts {
|
|
409
337
|
flex-shrink: 0;
|
|
410
|
-
|
|
411
|
-
font-
|
|
412
|
-
user-select: none;
|
|
338
|
+
color: var(--text-3);
|
|
339
|
+
font-variant-numeric: tabular-nums;
|
|
413
340
|
}
|
|
414
341
|
.log-msg {
|
|
415
342
|
flex: 1;
|
|
@@ -418,134 +345,121 @@
|
|
|
418
345
|
text-overflow: ellipsis;
|
|
419
346
|
white-space: nowrap;
|
|
420
347
|
}
|
|
421
|
-
.log-dur {
|
|
422
|
-
display: none;
|
|
423
|
-
}
|
|
424
348
|
.log-count {
|
|
425
349
|
flex-shrink: 0;
|
|
426
|
-
|
|
427
|
-
font-
|
|
428
|
-
|
|
429
|
-
|
|
350
|
+
color: var(--text-3);
|
|
351
|
+
font-variant-numeric: tabular-nums;
|
|
352
|
+
}
|
|
353
|
+
.log-count:empty {
|
|
354
|
+
display: none;
|
|
355
|
+
}
|
|
356
|
+
.log-entry.error .log-msg,
|
|
357
|
+
.log-entry.error .log-count {
|
|
358
|
+
color: var(--bad);
|
|
430
359
|
}
|
|
431
360
|
|
|
432
|
-
|
|
433
|
-
.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
consumers cascade automatically. When no data-theme attribute is set,
|
|
440
|
-
Figma's themeColors:true (in code.js) controls the values natively. */
|
|
441
|
-
body[data-theme="light"] {
|
|
442
|
-
--figma-color-bg: #ffffff;
|
|
443
|
-
--figma-color-bg-secondary: #f5f5f5;
|
|
444
|
-
--figma-color-border: #e5e5e5;
|
|
445
|
-
--figma-color-text: #333333;
|
|
446
|
-
--figma-color-text-secondary: #777777;
|
|
447
|
-
--color-connected: #16a34a;
|
|
448
|
-
--color-connected-glow: rgba(22, 163, 74, 0.45);
|
|
449
|
-
--color-waiting: #d97706;
|
|
450
|
-
--color-error: #ef4444;
|
|
451
|
-
--color-idle: #6b7280;
|
|
452
|
-
--log-info: #00639e;
|
|
453
|
-
--log-success: #167016;
|
|
454
|
-
--log-error: #b81e2c;
|
|
455
|
-
--log-warn: #7a5c00;
|
|
361
|
+
/* ===== Minimized: one 32px row instead of everything above ===== */
|
|
362
|
+
.mini {
|
|
363
|
+
display: none;
|
|
364
|
+
align-items: center;
|
|
365
|
+
gap: 2px;
|
|
366
|
+
height: 32px;
|
|
367
|
+
padding: 4px 6px;
|
|
456
368
|
}
|
|
457
|
-
body[data-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
369
|
+
body[data-minimized="true"] .mini {
|
|
370
|
+
display: flex;
|
|
371
|
+
}
|
|
372
|
+
body[data-minimized="true"] .full {
|
|
373
|
+
display: none;
|
|
374
|
+
}
|
|
375
|
+
.mini-icon-cell {
|
|
376
|
+
display: inline-flex;
|
|
377
|
+
align-items: center;
|
|
378
|
+
justify-content: center;
|
|
379
|
+
flex-shrink: 0;
|
|
380
|
+
width: 24px;
|
|
381
|
+
height: 24px;
|
|
382
|
+
}
|
|
383
|
+
.mini-word {
|
|
384
|
+
flex: 1;
|
|
385
|
+
min-width: 0;
|
|
386
|
+
font-weight: 500;
|
|
387
|
+
color: var(--text-2);
|
|
388
|
+
overflow: hidden;
|
|
389
|
+
text-overflow: ellipsis;
|
|
390
|
+
white-space: nowrap;
|
|
391
|
+
}
|
|
392
|
+
.expand-dot {
|
|
393
|
+
position: absolute;
|
|
394
|
+
top: 3px;
|
|
395
|
+
right: 3px;
|
|
396
|
+
width: 6px;
|
|
397
|
+
height: 6px;
|
|
398
|
+
border-radius: 50%;
|
|
399
|
+
background: var(--update-dot);
|
|
472
400
|
}
|
|
473
401
|
</style>
|
|
474
402
|
</head>
|
|
475
403
|
<body>
|
|
476
404
|
<div class="wrap">
|
|
477
|
-
<!--
|
|
478
|
-
<div class="
|
|
479
|
-
<div class="status
|
|
480
|
-
<div class="status-
|
|
481
|
-
|
|
405
|
+
<!-- The full window: status text, update strip, controls, activity log -->
|
|
406
|
+
<div class="full">
|
|
407
|
+
<div class="status">
|
|
408
|
+
<div class="status-line">
|
|
409
|
+
<span class="status-icon" id="status-icon" data-badge="wait" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M21 12a9 9 0 1 1-18 0a9 9 0 0 1 18 0" opacity="0.3"/><path d="M12 3a9 9 0 0 1 9 9"/></svg></span>
|
|
410
|
+
<span class="status-title" id="status-title" role="status" aria-live="polite">Looking for your AI app</span>
|
|
411
|
+
<span class="status-count" id="status-count"></span>
|
|
412
|
+
</div>
|
|
413
|
+
<div class="status-sub" id="status-sub">Start it, or check it's running</div>
|
|
482
414
|
</div>
|
|
483
|
-
<!-- CTA starts hidden; the first state reconcile shows it with an honest label -->
|
|
484
|
-
<button class="cta-btn" id="cta-btn" onclick="toggleLocalConnection()" style="display:none">Pause</button>
|
|
485
|
-
<button class="icon-btn" id="cloud-icon" onclick="toggleCloudPair()" title="Cloud pairing" aria-label="Cloud pairing" aria-expanded="false">
|
|
486
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
487
|
-
<path d="M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z"/>
|
|
488
|
-
</svg>
|
|
489
|
-
</button>
|
|
490
|
-
<button class="icon-btn" id="expand-btn" onclick="toggleSubToolbar()" title="Show options" aria-label="Show options" aria-expanded="false">+</button>
|
|
491
|
-
</div>
|
|
492
|
-
|
|
493
|
-
<!-- Status meta — connection count + proof of life (shown when connected) -->
|
|
494
|
-
<div class="status-meta" id="status-meta">
|
|
495
|
-
<span id="status-conn-count"></span>
|
|
496
|
-
<span id="status-last-action"></span>
|
|
497
|
-
</div>
|
|
498
415
|
|
|
499
|
-
|
|
500
|
-
|
|
416
|
+
<!-- Shown when the server reports a newer plugin; dismiss lasts for the session -->
|
|
417
|
+
<div class="update-strip" id="update-strip" hidden>
|
|
418
|
+
<div class="update-text">
|
|
419
|
+
<div class="update-title">Plugin update available</div>
|
|
420
|
+
<div class="update-body">Re-import it: Plugins → Development → Import plugin from manifest…</div>
|
|
421
|
+
</div>
|
|
422
|
+
<button class="btn btn-small" onclick="dismissUpdateBanner()" aria-label="Dismiss update notice" title="Dismiss update notice">
|
|
423
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M7 7l10 10M17 7L7 17"/></svg>
|
|
424
|
+
</button>
|
|
425
|
+
</div>
|
|
501
426
|
|
|
502
|
-
|
|
503
|
-
|
|
427
|
+
<div class="controls">
|
|
428
|
+
<div class="controls-left">
|
|
429
|
+
<!-- Pause / Resume / Try again: drawn by deriveAndRenderStatus() -->
|
|
430
|
+
<button class="btn" id="action-btn" data-action="" onclick="toggleLocalConnection(this.dataset.action)" hidden></button>
|
|
431
|
+
<button class="btn" id="activity-btn" onclick="toggleLog()" aria-label="Activity" title="Activity" aria-expanded="false" aria-controls="log-panel">
|
|
432
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01"/></svg>
|
|
433
|
+
</button>
|
|
434
|
+
</div>
|
|
435
|
+
<button class="btn" id="minimize-btn" onclick="onMinimizeClick()" aria-label="Minimize" title="Minimize">
|
|
436
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M6 12h12"/></svg>
|
|
437
|
+
</button>
|
|
438
|
+
</div>
|
|
504
439
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
440
|
+
<div class="log-panel" id="log-panel" hidden>
|
|
441
|
+
<div class="log-header">
|
|
442
|
+
<span class="log-version" id="log-version">Plugin —</span>
|
|
443
|
+
<button class="log-copy" id="log-copy-btn" onclick="copyLogToClipboard()" title="Copy activity to clipboard">
|
|
444
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
|
|
445
|
+
Copy
|
|
446
|
+
</button>
|
|
447
|
+
</div>
|
|
448
|
+
<div class="log-entries" id="log-entries"></div>
|
|
449
|
+
</div>
|
|
509
450
|
</div>
|
|
510
451
|
|
|
511
|
-
<!--
|
|
512
|
-
<div class="
|
|
513
|
-
<
|
|
514
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
452
|
+
<!-- The minimized window: one row -->
|
|
453
|
+
<div class="mini">
|
|
454
|
+
<span class="mini-icon-cell">
|
|
455
|
+
<span class="status-icon" id="mini-icon" data-badge="wait" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M21 12a9 9 0 1 1-18 0a9 9 0 0 1 18 0" opacity="0.3"/><path d="M12 3a9 9 0 0 1 9 9"/></svg></span>
|
|
456
|
+
</span>
|
|
457
|
+
<span class="mini-word" id="mini-word" role="status" aria-live="polite">Looking for your AI app</span>
|
|
458
|
+
<button class="btn" id="mini-action-btn" data-action="" onclick="toggleLocalConnection(this.dataset.action)" hidden></button>
|
|
459
|
+
<button class="btn" id="mini-expand-btn" onclick="onExpandClick()" aria-label="Expand" title="Expand">
|
|
460
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M14 4h6v6M10 20H4v-6"/></svg>
|
|
461
|
+
<span class="expand-dot" id="expand-dot" hidden></span>
|
|
519
462
|
</button>
|
|
520
|
-
<input type="text" id="cloud-code" maxlength="6" placeholder="Pairing code" autocomplete="off" aria-label="Cloud pairing code" />
|
|
521
|
-
<button id="cloud-btn" onclick="cloudConnect()">Connect</button>
|
|
522
|
-
</div>
|
|
523
|
-
<div class="row cloud-help" id="cloud-help" role="region" aria-label="About pairing codes">
|
|
524
|
-
<p>Use this when Claude is on a different device from Figma.</p>
|
|
525
|
-
<p>Generate a 6-char code in Claude and paste it here.</p>
|
|
526
|
-
</div>
|
|
527
|
-
<div class="cloud-status" id="cloud-status"></div>
|
|
528
|
-
|
|
529
|
-
<!-- Sub-toolbar (shown when [+] active) -->
|
|
530
|
-
<div class="row sub-toolbar" id="sub-toolbar">
|
|
531
|
-
<button class="sub-btn" id="log-toggle" onclick="toggleLog()" aria-expanded="false" aria-controls="log-panel">
|
|
532
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
533
|
-
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
|
|
534
|
-
<circle cx="12" cy="12" r="3"/>
|
|
535
|
-
</svg>
|
|
536
|
-
Activity
|
|
537
|
-
</button>
|
|
538
|
-
<button class="icon-btn" id="copy-log-btn" onclick="copyLogToClipboard()" title="Copy activity to clipboard" aria-label="Copy activity to clipboard" style="display:none">
|
|
539
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
540
|
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
|
541
|
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
|
542
|
-
</svg>
|
|
543
|
-
</button>
|
|
544
|
-
</div>
|
|
545
|
-
|
|
546
|
-
<!-- Activity panel (shown when Activity active) -->
|
|
547
|
-
<div class="row log-panel" id="log-panel">
|
|
548
|
-
<div class="log-entries" id="log-entries"></div>
|
|
549
463
|
</div>
|
|
550
464
|
</div>
|
|
551
465
|
|
|
@@ -566,103 +480,74 @@
|
|
|
566
480
|
// VARIABLES_DATA clears it (the plugin recovered).
|
|
567
481
|
var bridgeError = false;
|
|
568
482
|
|
|
569
|
-
//
|
|
570
|
-
//
|
|
571
|
-
//
|
|
572
|
-
//
|
|
573
|
-
//
|
|
574
|
-
//
|
|
575
|
-
//
|
|
576
|
-
//
|
|
577
|
-
//
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
483
|
+
// The window's own state, read by deriveAndRenderStatus():
|
|
484
|
+
// _lastAction { summary, failed, at } for the newest command the
|
|
485
|
+
// wrapper logged; failed turns true if that command fails.
|
|
486
|
+
// _retryFailed set when a Resume / Try again press found no server
|
|
487
|
+
// within its poll; cleared on the next press, or whenever
|
|
488
|
+
// a server is connected.
|
|
489
|
+
// _ctaState what setCtaState() was last given: 'on' | 'paused' |
|
|
490
|
+
// 'reconnect' | 'scanning', or null before the first one.
|
|
491
|
+
// _minimized the one-row view, set through setMinimized().
|
|
492
|
+
// _viewChosenByClick set by a Minimize / Expand click; from then on
|
|
493
|
+
// the stored setting (UI_PREFS at startup) is ignored.
|
|
494
|
+
var _lastAction = null;
|
|
495
|
+
var _retryFailed = false;
|
|
496
|
+
var _ctaState = null;
|
|
497
|
+
var _minimized = false;
|
|
498
|
+
var _viewChosenByClick = false;
|
|
499
|
+
|
|
500
|
+
// window-model:begin
|
|
501
|
+
// The window's status as a pure function of the facts: no DOM, window or
|
|
502
|
+
// globals, so tests/plugin-window-status.test.ts evaluates this block alone.
|
|
503
|
+
//
|
|
504
|
+
// f: { bridgeError: boolean, paused: boolean, live: number, retryFailed: boolean,
|
|
505
|
+
// ctaState: 'on'|'paused'|'reconnect'|'scanning'|null,
|
|
506
|
+
// lastAction: { summary: string, failed: boolean, at: number } | null, now: number }
|
|
507
|
+
// returns { badge: 'err'|'pause'|'ok'|'wait', title: string, count: string, sub: string,
|
|
508
|
+
// subTone: 'muted'|'bad', button: 'pause'|'resume'|'retry'|null }
|
|
509
|
+
function windowStatus(f) {
|
|
510
|
+
if (f.bridgeError) {
|
|
511
|
+
return { badge: 'err', title: 'Something went wrong', count: '',
|
|
512
|
+
sub: 'Close this window and run it again', subTone: 'muted', button: null };
|
|
587
513
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
var dotClass, text;
|
|
593
|
-
if (bridgeError) {
|
|
594
|
-
dotClass = 'error';
|
|
595
|
-
text = 'Something broke';
|
|
596
|
-
} else if (paused) {
|
|
597
|
-
dotClass = 'paused';
|
|
598
|
-
text = 'Paused — AI can\'t make changes';
|
|
599
|
-
} else if (live >= 1) {
|
|
600
|
-
dotClass = 'active';
|
|
601
|
-
text = 'Connected — AI can work in this file';
|
|
602
|
-
} else if (scanning) {
|
|
603
|
-
dotClass = 'loading';
|
|
604
|
-
text = 'Looking for your AI app…';
|
|
605
|
-
} else {
|
|
606
|
-
// Defensive fallback: discovery is always on unless paused, so this
|
|
607
|
-
// only renders if the discovery loop is somehow disabled.
|
|
608
|
-
dotClass = '';
|
|
609
|
-
text = 'Not connected';
|
|
514
|
+
if (f.paused) {
|
|
515
|
+
return { badge: 'pause', title: 'Paused', count: '',
|
|
516
|
+
sub: 'AI can\'t make changes', subTone: 'muted', button: 'resume' };
|
|
610
517
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// Build-version line under the meta row. Two independently-versioned
|
|
623
|
-
// halves, so both are labelled rather than merged into one number:
|
|
624
|
-
// Plugin — figma-desktop-bridge/code.js, cached by Figma at import time
|
|
625
|
-
// and only bumped on releases that actually touch plugin files
|
|
626
|
-
// Server — the npx sidecar's package version, learned over the wire
|
|
627
|
-
// Either can be unknown: the plugin version arrives from code.js ~500ms
|
|
628
|
-
// after open, the server version only once a connection lands. An unknown
|
|
629
|
-
// half renders "—" rather than a stale or guessed number.
|
|
630
|
-
function renderVersionLine() {
|
|
631
|
-
var el = document.getElementById('status-version');
|
|
632
|
-
if (!el) return;
|
|
633
|
-
var server = (typeof window.__wsServerVersion === 'function')
|
|
634
|
-
? window.__wsServerVersion()
|
|
635
|
-
: null;
|
|
636
|
-
el.textContent = 'Plugin ' + (PLUGIN_VERSION || '—') +
|
|
637
|
-
' · Server ' + (server ? 'v' + server : '—');
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
// Small always-visible line under the pill: "Connected to N AI app(s)"
|
|
641
|
-
// plus proof of life ("Last action: Xs ago"). Hidden entirely when there
|
|
642
|
-
// is nothing to show (zero connections).
|
|
643
|
-
function renderStatusMeta(liveCount) {
|
|
644
|
-
var meta = document.getElementById('status-meta');
|
|
645
|
-
var countEl = document.getElementById('status-conn-count');
|
|
646
|
-
var lastEl = document.getElementById('status-last-action');
|
|
647
|
-
if (!meta || !countEl || !lastEl) return;
|
|
648
|
-
var anything = false;
|
|
649
|
-
if (liveCount >= 1) {
|
|
650
|
-
countEl.textContent = 'Connected to ' + liveCount + ' AI app' + (liveCount === 1 ? '' : 's');
|
|
651
|
-
countEl.style.display = '';
|
|
652
|
-
anything = true;
|
|
653
|
-
} else {
|
|
654
|
-
countEl.textContent = '';
|
|
655
|
-
countEl.style.display = 'none';
|
|
518
|
+
if (f.live >= 1) {
|
|
519
|
+
var count = '· ' + f.live + ' AI app' + (f.live === 1 ? '' : 's');
|
|
520
|
+
if (!f.lastAction) {
|
|
521
|
+
return { badge: 'ok', title: 'Connected', count: count,
|
|
522
|
+
sub: 'Ready', subTone: 'muted', button: 'pause' };
|
|
523
|
+
}
|
|
524
|
+
return { badge: 'ok', title: 'Connected', count: count,
|
|
525
|
+
sub: formatAgo(f.now - f.lastAction.at) + ': ' + actionLabel(f.lastAction.summary, f.lastAction.failed),
|
|
526
|
+
subTone: f.lastAction.failed ? 'bad' : 'muted', button: 'pause' };
|
|
656
527
|
}
|
|
657
|
-
if (
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
anything = true;
|
|
661
|
-
} else {
|
|
662
|
-
lastEl.textContent = '';
|
|
663
|
-
lastEl.style.display = 'none';
|
|
528
|
+
if (f.retryFailed) {
|
|
529
|
+
return { badge: 'err', title: 'Couldn\'t connect', count: '',
|
|
530
|
+
sub: 'Is your AI app open?', subTone: 'muted', button: 'retry' };
|
|
664
531
|
}
|
|
665
|
-
|
|
532
|
+
return { badge: 'wait', title: 'Looking for your AI app', count: '',
|
|
533
|
+
sub: 'Start it, or check it\'s running', subTone: 'muted',
|
|
534
|
+
button: f.ctaState === 'reconnect' ? 'retry' : null };
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// The activity header's version: "Plugin r2 · Server 0.6.6". The server
|
|
538
|
+
// half shows only while one is connected; the revision reads "—" until
|
|
539
|
+
// code.js reports it.
|
|
540
|
+
function footerText(revision, serverVersion, live) {
|
|
541
|
+
var text = 'Plugin ' + (revision === null || revision === undefined ? '—' : 'r' + revision);
|
|
542
|
+
if (live >= 1 && serverVersion) text += ' · Server ' + serverVersion;
|
|
543
|
+
return text;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// The status line's name for the last command. A summary starting with
|
|
547
|
+
// <Code> is a script with no recognised Figma call and no leading comment.
|
|
548
|
+
function actionLabel(summary, failed) {
|
|
549
|
+
if (summary.indexOf('<Code>') === 0) return failed ? 'Script failed' : 'Ran a script';
|
|
550
|
+
return failed ? summary + ' failed' : summary;
|
|
666
551
|
}
|
|
667
552
|
|
|
668
553
|
function formatAgo(ms) {
|
|
@@ -673,6 +558,138 @@
|
|
|
673
558
|
var h = Math.floor(m / 60);
|
|
674
559
|
return h + 'h ago';
|
|
675
560
|
}
|
|
561
|
+
// window-model:end
|
|
562
|
+
|
|
563
|
+
// Open WebSocket connections, the "live" count the status reads.
|
|
564
|
+
function countLive() {
|
|
565
|
+
var conns = (typeof window.__wsGetActiveConnections === 'function') ? (window.__wsGetActiveConnections() || []) : [];
|
|
566
|
+
var live = 0;
|
|
567
|
+
for (var i = 0; i < conns.length; i++) {
|
|
568
|
+
if (conns[i] && conns[i].ws && conns[i].ws.readyState === 1) live++;
|
|
569
|
+
}
|
|
570
|
+
return live;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Sets an element's text, and optionally its tooltip, only when they
|
|
574
|
+
// change, so the 2s repaint doesn't churn the DOM or the live regions.
|
|
575
|
+
function setText(id, text, tooltip) {
|
|
576
|
+
var el = document.getElementById(id);
|
|
577
|
+
if (!el) return null;
|
|
578
|
+
if (el.textContent !== text) el.textContent = text;
|
|
579
|
+
if (tooltip !== undefined && el.title !== tooltip) el.title = tooltip;
|
|
580
|
+
return el;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Opens every icon. It sets fill="none", so a filled icon sets fill on
|
|
584
|
+
// its path: a second fill on the <svg> tag would be dropped by the HTML
|
|
585
|
+
// parser, which keeps only the first of a repeated attribute.
|
|
586
|
+
var SVG_OPEN = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false" ';
|
|
587
|
+
var STATUS_CIRCLE = 'M21 12a9 9 0 1 1-18 0a9 9 0 0 1 18 0';
|
|
588
|
+
var STATUS_GLYPHS = {
|
|
589
|
+
ok: 'M8.5 12.5l2.5 2.5 4.5-5',
|
|
590
|
+
pause: 'M10 9v6M14 9v6',
|
|
591
|
+
err: 'M12 8v4.5M12 16v.01'
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
function statusIconSvg(badge) {
|
|
595
|
+
if (badge === 'wait') {
|
|
596
|
+
return SVG_OPEN + 'stroke-width="2.4"><path d="' + STATUS_CIRCLE + '" opacity="0.3"/><path d="M12 3a9 9 0 0 1 9 9"/></svg>';
|
|
597
|
+
}
|
|
598
|
+
return SVG_OPEN + 'stroke-width="2.4"><path d="' + STATUS_CIRCLE + '"/><path d="' + STATUS_GLYPHS[badge] + '"/></svg>';
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Redraws only on a change, so the wait icon's spin never restarts.
|
|
602
|
+
function renderStatusIcon(id, badge) {
|
|
603
|
+
var el = document.getElementById(id);
|
|
604
|
+
if (!el || el.getAttribute('data-badge') === badge) return;
|
|
605
|
+
el.setAttribute('data-badge', badge);
|
|
606
|
+
el.innerHTML = statusIconSvg(badge);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
var ACTION_BUTTONS = {
|
|
610
|
+
pause: { label: 'Pause', svg: SVG_OPEN + 'stroke-width="2.4"><path d="M9 7v10M15 7v10"/></svg>' },
|
|
611
|
+
resume: { label: 'Resume', svg: SVG_OPEN + 'stroke-width="2.2"><path d="M8.5 5.5v13l10.5-6.5z" fill="currentColor"/></svg>' },
|
|
612
|
+
retry: { label: 'Try again', svg: SVG_OPEN + 'stroke-width="2.2"><path d="M20 11a8 8 0 1 0-2.3 5.7"/><path d="M20 4v7h-7"/></svg>' }
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// The action button carries the action windowStatus() chose, in
|
|
616
|
+
// data-action; its click handler reads it from there. When it hides
|
|
617
|
+
// while focused (a Resume / Try again press hides it while it polls),
|
|
618
|
+
// focus moves to Activity, or to Expand in the minimized row, which has
|
|
619
|
+
// no Activity button, so keyboard users keep their place.
|
|
620
|
+
function renderActionButton(id, action) {
|
|
621
|
+
var el = document.getElementById(id);
|
|
622
|
+
if (!el) return;
|
|
623
|
+
var next = action || '';
|
|
624
|
+
if (el.getAttribute('data-action') === next) return;
|
|
625
|
+
el.setAttribute('data-action', next);
|
|
626
|
+
el.classList.toggle('is-resume', action === 'resume');
|
|
627
|
+
if (!action) {
|
|
628
|
+
var hadFocus = document.activeElement === el;
|
|
629
|
+
el.hidden = true;
|
|
630
|
+
el.innerHTML = '';
|
|
631
|
+
if (hadFocus) {
|
|
632
|
+
var successor = document.getElementById(id === 'mini-action-btn' ? 'mini-expand-btn' : 'activity-btn');
|
|
633
|
+
if (successor) successor.focus();
|
|
634
|
+
}
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
var b = ACTION_BUTTONS[action];
|
|
638
|
+
el.innerHTML = b.svg;
|
|
639
|
+
el.setAttribute('aria-label', b.label);
|
|
640
|
+
el.title = b.label;
|
|
641
|
+
el.hidden = false;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Single source of truth for the window's status. Gathers the facts:
|
|
645
|
+
// - live WS connections from the connection pool
|
|
646
|
+
// - userPaused (pool exposes __wsIsPaused)
|
|
647
|
+
// - bridgeError (ERROR message from code.js)
|
|
648
|
+
// - _retryFailed, _ctaState and _lastAction (this file's own state)
|
|
649
|
+
// then draws the full and the minimized view from windowStatus().
|
|
650
|
+
// window.__figmaVariablesReady (set by VARIABLES_DATA) deliberately isn't
|
|
651
|
+
// an input: a Figma-side data event says nothing about whether an AI app
|
|
652
|
+
// is actually connected.
|
|
653
|
+
function deriveAndRenderStatus() {
|
|
654
|
+
var live = countLive();
|
|
655
|
+
var paused = (typeof window.__wsIsPaused === 'function') ? window.__wsIsPaused() : false;
|
|
656
|
+
if (live >= 1) _retryFailed = false;
|
|
657
|
+
|
|
658
|
+
var s = windowStatus({
|
|
659
|
+
bridgeError: bridgeError,
|
|
660
|
+
paused: paused,
|
|
661
|
+
live: live,
|
|
662
|
+
retryFailed: _retryFailed,
|
|
663
|
+
ctaState: _ctaState,
|
|
664
|
+
lastAction: _lastAction,
|
|
665
|
+
now: Date.now()
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
renderStatusIcon('status-icon', s.badge);
|
|
669
|
+
renderStatusIcon('mini-icon', s.badge);
|
|
670
|
+
setText('status-title', s.title, s.title);
|
|
671
|
+
setText('status-count', s.count);
|
|
672
|
+
var sub = setText('status-sub', s.sub, s.sub);
|
|
673
|
+
if (sub) sub.classList.toggle('is-bad', s.subTone === 'bad');
|
|
674
|
+
// Minimized: the status word only; hovering it shows the full status.
|
|
675
|
+
setText('mini-word', s.title, s.title + (s.count ? ' ' + s.count : '') + '\n' + s.sub);
|
|
676
|
+
renderActionButton('action-btn', s.button);
|
|
677
|
+
renderActionButton('mini-action-btn', s.button);
|
|
678
|
+
|
|
679
|
+
renderVersionLine(live);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// The activity header's version. The revision comes from code.js's
|
|
683
|
+
// GET_FILE_INFO_RESULT (sent ~500ms after open, connected or not); the
|
|
684
|
+
// server version from the first live connection. `live` is optional.
|
|
685
|
+
function renderVersionLine(live) {
|
|
686
|
+
if (typeof live !== 'number') live = countLive();
|
|
687
|
+
var server = (typeof window.__wsServerVersion === 'function')
|
|
688
|
+
? window.__wsServerVersion()
|
|
689
|
+
: null;
|
|
690
|
+
var text = footerText(PLUGIN_REVISION, server, live);
|
|
691
|
+
setText('log-version', text, text);
|
|
692
|
+
}
|
|
676
693
|
|
|
677
694
|
// ============================================================================
|
|
678
695
|
// COMMAND INFRASTRUCTURE - Generic plugin command sender
|
|
@@ -712,8 +729,8 @@
|
|
|
712
729
|
.catch(function(err) { return { success: false, error: err.message || String(err) }; });
|
|
713
730
|
};
|
|
714
731
|
|
|
715
|
-
window.updateVariable = (variableId, modeId, value) => {
|
|
716
|
-
return window.sendPluginCommand('UPDATE_VARIABLE', { variableId: variableId, modeId: modeId, value: value })
|
|
732
|
+
window.updateVariable = (variableId, modeId, value, literalStrings) => {
|
|
733
|
+
return window.sendPluginCommand('UPDATE_VARIABLE', { variableId: variableId, modeId: modeId, value: value, literalStrings: literalStrings === true })
|
|
717
734
|
.catch(function(err) { return { success: false, error: err.message || String(err) }; });
|
|
718
735
|
};
|
|
719
736
|
|
|
@@ -966,7 +983,7 @@
|
|
|
966
983
|
// NEW: SCREENSHOT & INSTANCE PROPERTIES (Fix for visual validation loop)
|
|
967
984
|
// ============================================================================
|
|
968
985
|
|
|
969
|
-
// Capture screenshot using plugin's exportAsync (reads current plugin state
|
|
986
|
+
// Capture screenshot using plugin's exportAsync (reads current plugin state)
|
|
970
987
|
// This solves the race condition where REST API screenshots show stale state
|
|
971
988
|
window.captureScreenshot = (nodeId, options) => {
|
|
972
989
|
var params = { nodeId: nodeId };
|
|
@@ -1090,7 +1107,7 @@
|
|
|
1090
1107
|
// Method-to-function mapping
|
|
1091
1108
|
var methodMap = {
|
|
1092
1109
|
'EXECUTE_CODE': function(params) { return window.executeCode(params.code, params.timeout); },
|
|
1093
|
-
'UPDATE_VARIABLE': function(params) { return window.updateVariable(params.variableId, params.modeId, params.value); },
|
|
1110
|
+
'UPDATE_VARIABLE': function(params) { return window.updateVariable(params.variableId, params.modeId, params.value, params.literalStrings === true); },
|
|
1094
1111
|
'CREATE_VARIABLE': function(params) { return window.createVariable(params.name, params.collectionId, params.resolvedType, params); },
|
|
1095
1112
|
'DELETE_VARIABLE': function(params) { return window.deleteVariable(params.variableId); },
|
|
1096
1113
|
'DELETE_VARIABLE_COLLECTION': function(params) { return window.deleteVariableCollection(params.collectionId); },
|
|
@@ -1154,7 +1171,7 @@
|
|
|
1154
1171
|
if (window.__figmaVariablesReady && window.__figmaVariablesData) {
|
|
1155
1172
|
return Promise.resolve(window.__figmaVariablesData);
|
|
1156
1173
|
}
|
|
1157
|
-
return Promise.reject(new Error('Variables data not ready. Make sure the
|
|
1174
|
+
return Promise.reject(new Error('Variables data not ready. Make sure the plugin has loaded.'));
|
|
1158
1175
|
},
|
|
1159
1176
|
'GET_FILE_INFO': function() {
|
|
1160
1177
|
return window.sendPluginCommand('GET_FILE_INFO', {});
|
|
@@ -1325,7 +1342,7 @@
|
|
|
1325
1342
|
|
|
1326
1343
|
/**
|
|
1327
1344
|
* Update backward-compat variables (ws, wsPort, wsConnected) and
|
|
1328
|
-
* re-render the status pill so the
|
|
1345
|
+
* re-render the status pill so the connection count reflects
|
|
1329
1346
|
* the new connection set.
|
|
1330
1347
|
*/
|
|
1331
1348
|
function updateCompatState() {
|
|
@@ -1355,12 +1372,21 @@
|
|
|
1355
1372
|
}));
|
|
1356
1373
|
}
|
|
1357
1374
|
|
|
1358
|
-
// Proactively report file identity to this server
|
|
1359
|
-
|
|
1375
|
+
// Proactively report file identity to this server. This is the
|
|
1376
|
+
// plugin's own handshake, so it takes the unwrapped sender (defined
|
|
1377
|
+
// later in this script, assigned long before any socket opens): it
|
|
1378
|
+
// isn't the window's last action, which stays "Ready" until something
|
|
1379
|
+
// the AI asked for runs. A success writes nothing to the activity
|
|
1380
|
+
// log; a failure or timeout writes one error entry.
|
|
1381
|
+
_origSendPluginCommand('GET_FILE_INFO', {})
|
|
1360
1382
|
.then(function(info) {
|
|
1361
|
-
if (
|
|
1383
|
+
if (info && info.success === false) {
|
|
1384
|
+
logWithHistory('Get file info failed (port ' + port + '): ' + (info.error || 'Unknown error'), 'error');
|
|
1385
|
+
} else if (connWs.readyState === 1 && info) {
|
|
1362
1386
|
connWs.send(JSON.stringify({ type: 'FILE_INFO', data: info.fileInfo || info }));
|
|
1363
1387
|
}
|
|
1388
|
+
}, function(err) {
|
|
1389
|
+
logWithHistory('Get file info failed (port ' + port + '): ' + (err && err.message ? err.message : String(err)), 'error');
|
|
1364
1390
|
})
|
|
1365
1391
|
.catch(function() { /* non-critical */ });
|
|
1366
1392
|
}
|
|
@@ -1375,11 +1401,15 @@
|
|
|
1375
1401
|
// After connecting, disconnect-triggered retries have their own limit.
|
|
1376
1402
|
var initialScanAttempts = 0;
|
|
1377
1403
|
var MAX_INITIAL_SCANS = 3;
|
|
1378
|
-
// Set true only when the user clicks Pause.
|
|
1379
|
-
//
|
|
1404
|
+
// Set true only when the user clicks Pause. While it is set nothing
|
|
1405
|
+
// connects: the scan, its retries, the health discovery loop and all
|
|
1406
|
+
// three dialers check it, so a deliberate pause is not undone.
|
|
1380
1407
|
var userPaused = false;
|
|
1408
|
+
// The scan's pending retry, so Pause can cancel it.
|
|
1409
|
+
var scanRetryTimer = null;
|
|
1381
1410
|
|
|
1382
1411
|
function wsScanAndConnect() {
|
|
1412
|
+
if (userPaused) return; // a deliberate pause holds until Resume
|
|
1383
1413
|
if (isScanning) return;
|
|
1384
1414
|
isScanning = true;
|
|
1385
1415
|
|
|
@@ -1407,6 +1437,8 @@
|
|
|
1407
1437
|
testWs.onopen = function() {
|
|
1408
1438
|
clearTimeout(timeout);
|
|
1409
1439
|
clearConnecting(port, testWs);
|
|
1440
|
+
// Opened after Pause: close it, and let its onclose count it.
|
|
1441
|
+
if (userPaused) { try { testWs.close(1000, 'Manual disconnect'); } catch (e) {} return; }
|
|
1410
1442
|
foundAny = true;
|
|
1411
1443
|
activeConnections.push({ port: port, ws: testWs });
|
|
1412
1444
|
updateCompatState();
|
|
@@ -1431,7 +1463,7 @@
|
|
|
1431
1463
|
if (pending <= 0) {
|
|
1432
1464
|
isScanning = false;
|
|
1433
1465
|
// Retry with backoff if no servers found, up to MAX_INITIAL_SCANS
|
|
1434
|
-
if (!foundAny && activeConnections.length === 0) {
|
|
1466
|
+
if (!userPaused && !foundAny && activeConnections.length === 0) {
|
|
1435
1467
|
// Fast burst on load: a couple of quick retries with backoff.
|
|
1436
1468
|
// Once the burst exhausts we STOP re-arming here — the HTTP
|
|
1437
1469
|
// /health discovery loop takes over and keeps probing quietly
|
|
@@ -1443,7 +1475,7 @@
|
|
|
1443
1475
|
if (initialScanAttempts < MAX_INITIAL_SCANS) {
|
|
1444
1476
|
var delay = 3000 * initialScanAttempts; // 3s, 6s
|
|
1445
1477
|
console.log('[MCP Bridge] No servers found, retry ' + initialScanAttempts + '/' + MAX_INITIAL_SCANS + ' in ' + (delay/1000) + 's');
|
|
1446
|
-
setTimeout(wsScanAndConnect, delay);
|
|
1478
|
+
scanRetryTimer = setTimeout(wsScanAndConnect, delay);
|
|
1447
1479
|
} else {
|
|
1448
1480
|
console.log('[MCP Bridge] No MCP server yet — health discovery keeps probing every ' + (DISCOVERY_IDLE_MS/1000) + 's until one appears (no restart needed).');
|
|
1449
1481
|
}
|
|
@@ -1463,13 +1495,6 @@
|
|
|
1463
1495
|
* slower is picked up by the /health discovery loop.
|
|
1464
1496
|
*/
|
|
1465
1497
|
function wsReconnectPort(port) {
|
|
1466
|
-
if (port === 'cloud') {
|
|
1467
|
-
// The cloud connection is a wss:// relay, not a localhost port —
|
|
1468
|
-
// 'ws://localhost:cloud' is an invalid URL. Re-dial through the
|
|
1469
|
-
// cloud code (correct URL + its own bounded retry/give-up).
|
|
1470
|
-
if (typeof window.__cloudReconnect === 'function') window.__cloudReconnect();
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
1498
|
if (userPaused || isPortConnected(port)) return;
|
|
1474
1499
|
try {
|
|
1475
1500
|
var testWs = new WebSocket('ws://localhost:' + port);
|
|
@@ -1481,6 +1506,7 @@
|
|
|
1481
1506
|
testWs.onopen = function() {
|
|
1482
1507
|
clearTimeout(timeout);
|
|
1483
1508
|
clearConnecting(port, testWs);
|
|
1509
|
+
if (userPaused) { try { testWs.close(1000, 'Manual disconnect'); } catch (e) {} return; }
|
|
1484
1510
|
activeConnections.push({ port: port, ws: testWs });
|
|
1485
1511
|
updateCompatState();
|
|
1486
1512
|
console.log('[MCP Bridge] Reconnected to port ' + port + ' (' + activeConnections.length + ' server(s) total)');
|
|
@@ -1519,6 +1545,7 @@
|
|
|
1519
1545
|
testWs.onopen = function() {
|
|
1520
1546
|
clearTimeout(timeout);
|
|
1521
1547
|
clearConnecting(port, testWs);
|
|
1548
|
+
if (userPaused) { try { testWs.close(1000, 'Manual disconnect'); } catch (e) {} return; }
|
|
1522
1549
|
var conn = { port: port, ws: testWs };
|
|
1523
1550
|
if (serverVersion) conn.serverVersion = serverVersion;
|
|
1524
1551
|
activeConnections.push(conn);
|
|
@@ -1558,6 +1585,8 @@
|
|
|
1558
1585
|
conn.serverInfo = message.data;
|
|
1559
1586
|
if (message.data.serverVersion) conn.serverVersion = message.data.serverVersion;
|
|
1560
1587
|
}
|
|
1588
|
+
// The server version is known from here: repaint the activity header.
|
|
1589
|
+
if (typeof renderVersionLine === 'function') renderVersionLine();
|
|
1561
1590
|
return;
|
|
1562
1591
|
}
|
|
1563
1592
|
|
|
@@ -1711,22 +1740,6 @@
|
|
|
1711
1740
|
}
|
|
1712
1741
|
};
|
|
1713
1742
|
|
|
1714
|
-
// Expose functions for Cloud Mode to add connections to the same pool
|
|
1715
|
-
window.__wsAddCloudConnection = function(cloudWs, label, onDisconnect) {
|
|
1716
|
-
activeConnections.push({ port: label, ws: cloudWs });
|
|
1717
|
-
updateCompatState();
|
|
1718
|
-
attachWsHandlers(cloudWs, label);
|
|
1719
|
-
// Chain cloud disconnect callback after attachWsHandlers' onclose
|
|
1720
|
-
if (onDisconnect) {
|
|
1721
|
-
var origOnClose = cloudWs.onclose;
|
|
1722
|
-
cloudWs.onclose = function(event) {
|
|
1723
|
-
if (origOnClose) origOnClose.call(cloudWs, event);
|
|
1724
|
-
onDisconnect();
|
|
1725
|
-
};
|
|
1726
|
-
}
|
|
1727
|
-
initializeConnection(cloudWs, label);
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
1743
|
window.__wsGetActiveConnections = function() { return activeConnections; };
|
|
1731
1744
|
|
|
1732
1745
|
window.__wsDisconnectAll = function() {
|
|
@@ -1747,6 +1760,7 @@
|
|
|
1747
1760
|
// Reset scan state so a future Resume gets a clean retry budget.
|
|
1748
1761
|
isScanning = false;
|
|
1749
1762
|
initialScanAttempts = 0;
|
|
1763
|
+
if (scanRetryTimer) { clearTimeout(scanRetryTimer); scanRetryTimer = null; }
|
|
1750
1764
|
// Deliberate user pause — keep discovery quiet until Resume.
|
|
1751
1765
|
userPaused = true;
|
|
1752
1766
|
};
|
|
@@ -1863,25 +1877,9 @@
|
|
|
1863
1877
|
})();
|
|
1864
1878
|
|
|
1865
1879
|
// ============================================================================
|
|
1866
|
-
//
|
|
1867
|
-
//
|
|
1868
|
-
|
|
1869
|
-
var CLOUD_RELAY_HOST = 'wss://figma-console-mcp.southleft.com';
|
|
1870
|
-
var _lastCloudCode = null; // most recent code that successfully paired
|
|
1871
|
-
var _cloudUserDisconnected = false; // user clicked Disconnect — suppress auto re-dial
|
|
1872
|
-
var _cloudWasConnectedBeforePause = false; // restore cloud on Resume after Pause
|
|
1873
|
-
var _cloudRetryCount = 0; // bounded auto-reconnect budget
|
|
1874
|
-
var CLOUD_MAX_RETRIES = 5;
|
|
1875
|
-
var _cloudEverConnected = false; // paired successfully THIS session — separates a real
|
|
1876
|
-
// drop (worth telling the user) from a stale restored
|
|
1877
|
-
// code that never connected (stay quiet)
|
|
1878
|
-
|
|
1879
|
-
// ============================================================================
|
|
1880
|
-
// 3-STAGE UI TOGGLES
|
|
1881
|
-
// Stage 1: row-top (always visible)
|
|
1882
|
-
// Stage 2: sub-toolbar (revealed by [+])
|
|
1883
|
-
// Stage 3: log panel (revealed by Show log)
|
|
1884
|
-
// Cloud pairing is an independent row triggered by the cloud icon.
|
|
1880
|
+
// WINDOW LAYOUT
|
|
1881
|
+
// Full: status text, update strip, controls row, activity log (by Activity).
|
|
1882
|
+
// Minimized: one row, through setMinimized().
|
|
1885
1883
|
// ============================================================================
|
|
1886
1884
|
|
|
1887
1885
|
// Fixed 240px width matches Figma right-side nav min.
|
|
@@ -1897,7 +1895,10 @@
|
|
|
1897
1895
|
var wrap = document.querySelector('.wrap');
|
|
1898
1896
|
if (!wrap) return;
|
|
1899
1897
|
var bs = window.getComputedStyle(document.body);
|
|
1900
|
-
|
|
1898
|
+
// getBoundingClientRect keeps the fraction that offsetHeight rounds
|
|
1899
|
+
// away, so Math.ceil never leaves the window 1px short (a scrollbar at
|
|
1900
|
+
// fractional display scaling).
|
|
1901
|
+
var h = wrap.getBoundingClientRect().height
|
|
1901
1902
|
+ (parseFloat(bs.paddingTop) || 0)
|
|
1902
1903
|
+ (parseFloat(bs.paddingBottom) || 0);
|
|
1903
1904
|
parent.postMessage({
|
|
@@ -1934,70 +1935,63 @@
|
|
|
1934
1935
|
setTimeout(sendResize, 600);
|
|
1935
1936
|
});
|
|
1936
1937
|
|
|
1937
|
-
function
|
|
1938
|
-
var
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1938
|
+
function isLogOpen() {
|
|
1939
|
+
var panel = document.getElementById('log-panel');
|
|
1940
|
+
return !!panel && !panel.hidden;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
// Opens or closes the activity log under the controls. The Activity
|
|
1944
|
+
// button shows a pressed background while it's open (aria-expanded).
|
|
1945
|
+
function setLogOpen(open) {
|
|
1946
|
+
var panel = document.getElementById('log-panel');
|
|
1947
|
+
var btn = document.getElementById('activity-btn');
|
|
1948
|
+
if (!panel) return;
|
|
1949
|
+
panel.hidden = !open;
|
|
1950
|
+
if (btn) btn.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
1951
|
+
if (open) {
|
|
1952
|
+
renderVersionLine();
|
|
1953
|
+
ensureLogRefs();
|
|
1954
|
+
// Newest entry at the bottom: rows appended while closed didn't scroll.
|
|
1955
|
+
if (logEntriesEl) logEntriesEl.scrollTop = logEntriesEl.scrollHeight;
|
|
1948
1956
|
}
|
|
1949
1957
|
autoResize();
|
|
1950
|
-
return opening;
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
function closeSubToolbarIfOpen() {
|
|
1954
|
-
var sub = document.getElementById('sub-toolbar');
|
|
1955
|
-
if (sub && sub.classList.contains('visible')) toggleSubToolbar();
|
|
1956
1958
|
}
|
|
1957
1959
|
|
|
1958
|
-
function
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1960
|
+
function toggleLog() {
|
|
1961
|
+
setLogOpen(!isLogOpen());
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
// The one-row view. Minimizing closes the activity log; Expand brings
|
|
1965
|
+
// the full window back with it closed. `persist` stores the choice in
|
|
1966
|
+
// code.js (clientStorage), so the plugin reopens the same way in every
|
|
1967
|
+
// file. Only a person's click persists; the stored value read back at
|
|
1968
|
+
// startup doesn't write it again.
|
|
1969
|
+
function setMinimized(on, persist) {
|
|
1970
|
+
// The stored setting arrives shortly after startup; a click before it wins.
|
|
1971
|
+
if (!persist && _viewChosenByClick) return;
|
|
1972
|
+
if (persist) _viewChosenByClick = true;
|
|
1973
|
+
_minimized = on === true;
|
|
1974
|
+
document.body.dataset.minimized = _minimized ? 'true' : 'false';
|
|
1975
|
+
if (_minimized) setLogOpen(false);
|
|
1976
|
+
deriveAndRenderStatus();
|
|
1977
|
+
autoResize();
|
|
1978
|
+
if (persist) {
|
|
1979
|
+
parent.postMessage({ pluginMessage: { type: 'SET_UI_PREFS', minimized: _minimized } }, '*');
|
|
1965
1980
|
}
|
|
1966
1981
|
}
|
|
1967
1982
|
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
// routine states while keeping actionable ones ("pairing lost") visible.
|
|
1975
|
-
renderCloudStatus();
|
|
1983
|
+
// The clicked button disappears with its view, so keyboard focus moves
|
|
1984
|
+
// to its counterpart in the other view.
|
|
1985
|
+
function onMinimizeClick() {
|
|
1986
|
+
setMinimized(true, true);
|
|
1987
|
+
var expand = document.getElementById('mini-expand-btn');
|
|
1988
|
+
if (expand) expand.focus();
|
|
1976
1989
|
}
|
|
1977
1990
|
|
|
1978
|
-
function
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
function toggleSubToolbar() {
|
|
1983
|
-
var opening = !document.getElementById('sub-toolbar').classList.contains('visible');
|
|
1984
|
-
if (opening) closeCloudPairIfOpen();
|
|
1985
|
-
var nowOpen = toggleRow('sub-toolbar', 'expand-btn');
|
|
1986
|
-
document.getElementById('expand-btn').textContent = nowOpen ? '−' : '+';
|
|
1987
|
-
if (!nowOpen) {
|
|
1988
|
-
// Collapse the Activity panel if sub-toolbar closes
|
|
1989
|
-
var log = document.getElementById('log-panel');
|
|
1990
|
-
if (log.classList.contains('visible')) toggleLog();
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
function toggleLog() {
|
|
1995
|
-
var logVisible = document.getElementById('log-panel').classList.contains('visible');
|
|
1996
|
-
var opening = !logVisible;
|
|
1997
|
-
toggleRow('log-panel', 'log-toggle');
|
|
1998
|
-
// Reveal the Copy button only when the Activity panel is open
|
|
1999
|
-
document.getElementById('copy-log-btn').style.display = opening ? '' : 'none';
|
|
2000
|
-
autoResize();
|
|
1991
|
+
function onExpandClick() {
|
|
1992
|
+
setMinimized(false, true);
|
|
1993
|
+
var minimize = document.getElementById('minimize-btn');
|
|
1994
|
+
if (minimize) minimize.focus();
|
|
2001
1995
|
}
|
|
2002
1996
|
|
|
2003
1997
|
// Follow Figma's theme. With themeColors:true, Figma adds a "figma-light" /
|
|
@@ -2023,9 +2017,20 @@
|
|
|
2023
2017
|
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', applyTheme);
|
|
2024
2018
|
}
|
|
2025
2019
|
|
|
2020
|
+
// The thin log scrollbar (see the styles) replaces scrollbars that take up
|
|
2021
|
+
// room; overlay scrollbars, which take none, are left alone.
|
|
2022
|
+
(function markScrollbarKind() {
|
|
2023
|
+
var probe = document.createElement('div');
|
|
2024
|
+
probe.style.cssText = 'position:absolute;top:-200px;width:50px;height:50px;overflow:scroll;visibility:hidden';
|
|
2025
|
+
document.body.appendChild(probe);
|
|
2026
|
+
var takesRoom = probe.offsetWidth - probe.clientWidth > 0;
|
|
2027
|
+
document.body.removeChild(probe);
|
|
2028
|
+
if (takesRoom) document.body.dataset.scrollbars = 'thin';
|
|
2029
|
+
})();
|
|
2030
|
+
|
|
2026
2031
|
|
|
2027
2032
|
// ============================================================================
|
|
2028
|
-
//
|
|
2033
|
+
// ACTIVITY LOG, CONNECTION BUTTON, CLIPBOARD EXPORT
|
|
2029
2034
|
// ============================================================================
|
|
2030
2035
|
|
|
2031
2036
|
// Populated from code.js's own PLUGIN_VERSION via GET_FILE_INFO_RESULT
|
|
@@ -2035,16 +2040,14 @@
|
|
|
2035
2040
|
// drifted to the package version (0.3.0) while code.js reported the
|
|
2036
2041
|
// plugin version (1.35.0) — two different numbers for the same field.
|
|
2037
2042
|
var PLUGIN_VERSION = null;
|
|
2043
|
+
// code.js's FORK_PLUGIN_REVISION, from the same GET_FILE_INFO_RESULT, or
|
|
2044
|
+
// null until it arrives. Shown in the activity header and the copied log.
|
|
2045
|
+
var PLUGIN_REVISION = null;
|
|
2038
2046
|
var logHistory = [];
|
|
2039
2047
|
var logEntriesEl = null;
|
|
2040
|
-
var _ctaBtn = null;
|
|
2041
|
-
// Timestamp of the most recent command sent through the bridge (the same
|
|
2042
|
-
// event that appends to logHistory) — drives "Last action: Xs ago".
|
|
2043
|
-
var _lastActionAt = null;
|
|
2044
2048
|
|
|
2045
2049
|
function ensureLogRefs() {
|
|
2046
2050
|
if (!logEntriesEl) logEntriesEl = document.getElementById('log-entries');
|
|
2047
|
-
if (!_ctaBtn) _ctaBtn = document.getElementById('cta-btn');
|
|
2048
2051
|
}
|
|
2049
2052
|
|
|
2050
2053
|
function escHtml(s) {
|
|
@@ -2081,7 +2084,6 @@
|
|
|
2081
2084
|
entry.innerHTML =
|
|
2082
2085
|
'<span class="log-ts">' + escHtml(ts || '') + '</span>' +
|
|
2083
2086
|
'<span class="log-msg" title="' + escHtml(message) + '">' + escHtml(message) + '</span>' +
|
|
2084
|
-
'<span class="log-dur"></span>' +
|
|
2085
2087
|
'<span class="log-count"></span>';
|
|
2086
2088
|
logEntriesEl.appendChild(entry);
|
|
2087
2089
|
logEntriesEl.scrollTop = logEntriesEl.scrollHeight;
|
|
@@ -2100,16 +2102,28 @@
|
|
|
2100
2102
|
log(message, level, ts);
|
|
2101
2103
|
}
|
|
2102
2104
|
|
|
2105
|
+
// Failed entries get their one "[!]" here, from their level; the on-screen
|
|
2106
|
+
// row shows failure by colour instead.
|
|
2103
2107
|
function copyLogToClipboard() {
|
|
2104
2108
|
var lines = logHistory.map(function(e) {
|
|
2105
2109
|
var prefix = e.level === 'error' ? '[!] ' : e.level === 'warn' ? '[WARN] ' : '';
|
|
2106
2110
|
return e.ts + ' ' + prefix + e.message;
|
|
2107
2111
|
});
|
|
2108
|
-
var
|
|
2112
|
+
var pluginLine = (PLUGIN_REVISION !== null ? 'r' + PLUGIN_REVISION : 'r—')
|
|
2113
|
+
+ (PLUGIN_VERSION ? ' (' + PLUGIN_VERSION + ')' : '');
|
|
2114
|
+
var text = 'Toko Relay - Session Log\n'
|
|
2109
2115
|
+ 'Exported: ' + new Date().toISOString() + '\n'
|
|
2110
|
-
+ 'Plugin: ' +
|
|
2116
|
+
+ 'Plugin: ' + pluginLine + '\n'
|
|
2111
2117
|
+ '------------------------------------------------\n'
|
|
2112
2118
|
+ lines.join('\n') + '\n';
|
|
2119
|
+
// Selecting the textarea below takes focus. Give it back to Copy only
|
|
2120
|
+
// when Copy had keyboard focus: after a mouse click, refocusing it
|
|
2121
|
+
// would show a focus ring.
|
|
2122
|
+
var copyBtn = document.getElementById('log-copy-btn');
|
|
2123
|
+
var hadKeyFocus = false;
|
|
2124
|
+
if (copyBtn && document.activeElement === copyBtn) {
|
|
2125
|
+
try { hadKeyFocus = copyBtn.matches(':focus-visible'); } catch (e) { hadKeyFocus = true; }
|
|
2126
|
+
}
|
|
2113
2127
|
var ta = document.createElement('textarea');
|
|
2114
2128
|
ta.value = text;
|
|
2115
2129
|
ta.style.position = 'fixed';
|
|
@@ -2119,6 +2133,7 @@
|
|
|
2119
2133
|
var ok = false;
|
|
2120
2134
|
try { ok = document.execCommand('copy'); } catch (e) {}
|
|
2121
2135
|
document.body.removeChild(ta);
|
|
2136
|
+
if (hadKeyFocus) copyBtn.focus();
|
|
2122
2137
|
if (ok) {
|
|
2123
2138
|
logWithHistory('Copied to clipboard (' + logHistory.length + ' entries)', 'success');
|
|
2124
2139
|
} else {
|
|
@@ -2175,7 +2190,10 @@
|
|
|
2175
2190
|
if (type === 'EXECUTE_CODE' && params && params.code) {
|
|
2176
2191
|
var firstLine = params.code.trim().split('\n')[0].trim();
|
|
2177
2192
|
if (firstLine.indexOf('//') === 0) {
|
|
2178
|
-
|
|
2193
|
+
var comment = firstLine.replace(/^\/\/\s*/, '').replace(/[—–]/g, '-');
|
|
2194
|
+
// A bare "//", or a separator such as "// =====", names nothing:
|
|
2195
|
+
// fall through to the pattern match.
|
|
2196
|
+
if (/[\p{L}\p{N}]/u.test(comment)) return truncate(comment);
|
|
2179
2197
|
}
|
|
2180
2198
|
var hits = [];
|
|
2181
2199
|
for (var i = 0; i < FIGMA_API_PATTERNS.length; i++) {
|
|
@@ -2205,179 +2223,188 @@
|
|
|
2205
2223
|
return type.replace(/_/g, ' ').toLowerCase().replace(/^\w/, function(c) { return c.toUpperCase(); });
|
|
2206
2224
|
}
|
|
2207
2225
|
|
|
2208
|
-
// Wrap sendPluginCommand so every sent command is logged with a human
|
|
2226
|
+
// Wrap sendPluginCommand so every sent command is logged with a human
|
|
2227
|
+
// summary, and becomes the window's last action.
|
|
2209
2228
|
var _origSendPluginCommand = window.sendPluginCommand;
|
|
2210
2229
|
window.sendPluginCommand = function(type, params, timeoutMs) {
|
|
2211
2230
|
var summary = summariseCommand(type, params);
|
|
2212
|
-
var
|
|
2231
|
+
var logRow = null;
|
|
2213
2232
|
var histIdx = -1;
|
|
2233
|
+
var action = null;
|
|
2214
2234
|
if (summary) {
|
|
2215
|
-
|
|
2235
|
+
action = { summary: summary, failed: false, at: Date.now() };
|
|
2236
|
+
_lastAction = action;
|
|
2216
2237
|
logWithHistory(summary, 'info');
|
|
2217
2238
|
histIdx = logHistory.length - 1;
|
|
2218
2239
|
ensureLogRefs();
|
|
2219
|
-
|
|
2240
|
+
logRow = logEntriesEl ? logEntriesEl.lastElementChild : null;
|
|
2241
|
+
deriveAndRenderStatus();
|
|
2242
|
+
}
|
|
2243
|
+
// Only this command's own action turns red: a newer command has
|
|
2244
|
+
// replaced _lastAction by the time an older one fails.
|
|
2245
|
+
function markActionFailed() {
|
|
2246
|
+
if (action && _lastAction === action) {
|
|
2247
|
+
action.failed = true;
|
|
2248
|
+
deriveAndRenderStatus();
|
|
2249
|
+
}
|
|
2220
2250
|
}
|
|
2221
|
-
var t0 = Date.now();
|
|
2222
2251
|
return _origSendPluginCommand(type, params, timeoutMs).then(
|
|
2223
2252
|
function(result) {
|
|
2224
|
-
if (
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
durEntry.className = durEntry.className.replace(/\b(info|success|warn)\b/, 'error');
|
|
2229
|
-
durEntry.dataset.logLevel = 'error';
|
|
2230
|
-
var m = durEntry.querySelector('.log-msg');
|
|
2231
|
-
if (m && m.textContent.indexOf('[!]') !== 0) m.textContent = '[!] ' + m.textContent;
|
|
2253
|
+
if (result && result.success === false) {
|
|
2254
|
+
if (logRow) {
|
|
2255
|
+
logRow.className = logRow.className.replace(/\b(info|success|warn)\b/, 'error');
|
|
2256
|
+
logRow.dataset.logLevel = 'error';
|
|
2232
2257
|
if (histIdx >= 0 && logHistory[histIdx]) {
|
|
2233
2258
|
logHistory[histIdx].level = 'error';
|
|
2234
2259
|
}
|
|
2235
2260
|
}
|
|
2261
|
+
markActionFailed();
|
|
2236
2262
|
}
|
|
2237
2263
|
return result;
|
|
2238
2264
|
},
|
|
2239
2265
|
function(err) {
|
|
2240
|
-
if (
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
durEntry.className = durEntry.className.replace(/\b(info|success|warn)\b/, 'error');
|
|
2244
|
-
durEntry.dataset.logLevel = 'error';
|
|
2245
|
-
var m = durEntry.querySelector('.log-msg');
|
|
2246
|
-
if (m && m.textContent.indexOf('[!]') !== 0) m.textContent = '[!] ' + m.textContent;
|
|
2266
|
+
if (logRow) {
|
|
2267
|
+
logRow.className = logRow.className.replace(/\b(info|success|warn)\b/, 'error');
|
|
2268
|
+
logRow.dataset.logLevel = 'error';
|
|
2247
2269
|
if (histIdx >= 0 && logHistory[histIdx]) {
|
|
2248
2270
|
logHistory[histIdx].level = 'error';
|
|
2249
|
-
logHistory[histIdx].message = '[!] ' + logHistory[histIdx].message;
|
|
2250
2271
|
}
|
|
2251
2272
|
}
|
|
2273
|
+
markActionFailed();
|
|
2252
2274
|
throw err;
|
|
2253
2275
|
}
|
|
2254
2276
|
);
|
|
2255
2277
|
};
|
|
2256
2278
|
|
|
2257
|
-
// Plugin update
|
|
2279
|
+
// Plugin update strip — shown when the server pushes
|
|
2258
2280
|
// PLUGIN_UPDATE_AVAILABLE over the WebSocket. Dismiss sticks for the
|
|
2259
|
-
// session so repeated pushes don't nag.
|
|
2281
|
+
// session so repeated pushes don't nag. While an update is waiting, the
|
|
2282
|
+
// minimized window's Expand button carries a dot and says so.
|
|
2283
|
+
var _updateAvailable = false;
|
|
2260
2284
|
var _updateBannerDismissed = false;
|
|
2261
|
-
function
|
|
2262
|
-
|
|
2263
|
-
var
|
|
2264
|
-
if (
|
|
2265
|
-
|
|
2266
|
-
|
|
2285
|
+
function renderUpdateNotice() {
|
|
2286
|
+
var waiting = _updateAvailable && !_updateBannerDismissed;
|
|
2287
|
+
var strip = document.getElementById('update-strip');
|
|
2288
|
+
if (strip) strip.hidden = !waiting;
|
|
2289
|
+
var dot = document.getElementById('expand-dot');
|
|
2290
|
+
if (dot) dot.hidden = !waiting;
|
|
2291
|
+
var expand = document.getElementById('mini-expand-btn');
|
|
2292
|
+
if (expand) {
|
|
2293
|
+
var label = waiting ? 'Expand (plugin update available)' : 'Expand';
|
|
2294
|
+
expand.setAttribute('aria-label', label);
|
|
2295
|
+
expand.title = label;
|
|
2267
2296
|
}
|
|
2268
2297
|
}
|
|
2298
|
+
function showUpdateBanner() {
|
|
2299
|
+
if (_updateBannerDismissed || _updateAvailable) return;
|
|
2300
|
+
_updateAvailable = true;
|
|
2301
|
+
renderUpdateNotice();
|
|
2302
|
+
autoResize();
|
|
2303
|
+
}
|
|
2269
2304
|
function dismissUpdateBanner() {
|
|
2305
|
+
if (_updateBannerDismissed) return;
|
|
2306
|
+
var strip = document.getElementById('update-strip');
|
|
2307
|
+
var hadFocus = !!(strip && document.activeElement && strip.contains(document.activeElement));
|
|
2270
2308
|
_updateBannerDismissed = true;
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2309
|
+
renderUpdateNotice();
|
|
2310
|
+
autoResize();
|
|
2311
|
+
// The × goes with the strip: keep keyboard users' place.
|
|
2312
|
+
if (hadFocus) {
|
|
2313
|
+
var activity = document.getElementById('activity-btn');
|
|
2314
|
+
if (activity) activity.focus();
|
|
2275
2315
|
}
|
|
2276
2316
|
}
|
|
2277
2317
|
|
|
2278
|
-
//
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
// Real Pause / Resume: toggles the local WebSocket bridge.
|
|
2318
|
+
// Real Pause / Resume: toggles the local WebSocket bridge. The connection
|
|
2319
|
+
// button's state: 'on' | 'paused' | 'reconnect' | 'scanning'. Callers
|
|
2320
|
+
// repaint with deriveAndRenderStatus(), which draws the button from
|
|
2321
|
+
// windowStatus(); 'scanning' (a press still polling) shows no button.
|
|
2285
2322
|
function setCtaState(state) {
|
|
2286
|
-
|
|
2287
|
-
if (!_ctaBtn) return;
|
|
2288
|
-
_ctaBtn.style.display = ''; // markup starts it hidden until first honest state
|
|
2289
|
-
if (state === 'on') { _ctaBtn.textContent = 'Pause'; _ctaBtn.disabled = false; }
|
|
2290
|
-
else if (state === 'paused') { _ctaBtn.textContent = 'Resume'; _ctaBtn.disabled = false; }
|
|
2291
|
-
else if (state === 'reconnect'){ _ctaBtn.textContent = 'Try again'; _ctaBtn.disabled = false; }
|
|
2292
|
-
else if (state === 'scanning') { _ctaBtn.textContent = 'Connecting…'; _ctaBtn.disabled = true; }
|
|
2323
|
+
_ctaState = state;
|
|
2293
2324
|
}
|
|
2294
2325
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2326
|
+
// A Resume / Try again press's poller, so Pause can stop it.
|
|
2327
|
+
var _reconnectPoller = null;
|
|
2328
|
+
|
|
2329
|
+
// `action` is the one windowStatus() gave the button: 'pause' runs the
|
|
2330
|
+
// pause path, 'resume' and 'retry' the resume path.
|
|
2331
|
+
function toggleLocalConnection(action) {
|
|
2332
|
+
if (action === 'pause') {
|
|
2333
|
+
// Pause shows as soon as a server connects, before the press's poller
|
|
2334
|
+
// has noticed; pausing then ends that press.
|
|
2335
|
+
if (_reconnectPoller) { clearInterval(_reconnectPoller); _reconnectPoller = null; }
|
|
2302
2336
|
if (typeof window.__wsDisconnectAll === 'function') window.__wsDisconnectAll();
|
|
2303
2337
|
setCtaState('paused');
|
|
2304
2338
|
deriveAndRenderStatus();
|
|
2305
2339
|
logWithHistory('Paused', 'warn');
|
|
2306
|
-
} else if (
|
|
2340
|
+
} else if (action === 'resume' || action === 'retry') {
|
|
2341
|
+
// A press is still polling: the old button sat disabled
|
|
2342
|
+
// ("Connecting…") until its poller settled.
|
|
2343
|
+
if (_ctaState === 'scanning') return;
|
|
2344
|
+
_retryFailed = false;
|
|
2307
2345
|
setCtaState('scanning');
|
|
2308
2346
|
logWithHistory('Looking for your AI app…', 'info');
|
|
2309
2347
|
if (typeof window.__wsManualScan === 'function') window.__wsManualScan();
|
|
2310
2348
|
else if (typeof window.__wsScanAndConnect === 'function') window.__wsScanAndConnect();
|
|
2311
|
-
// Re-establish the cloud connection if one existed before Pause
|
|
2312
|
-
// (the scan above only covers localhost ports).
|
|
2313
|
-
if (_cloudWasConnectedBeforePause) {
|
|
2314
|
-
_cloudWasConnectedBeforePause = false;
|
|
2315
|
-
if (_lastCloudCode && !_cloudUserDisconnected) {
|
|
2316
|
-
_cloudRetryCount = 0;
|
|
2317
|
-
cloudDial(_lastCloudCode, true);
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
2349
|
deriveAndRenderStatus();
|
|
2321
2350
|
// Watch for connection success or scan timeout.
|
|
2322
2351
|
var attempts = 0;
|
|
2323
2352
|
var poller = setInterval(function() {
|
|
2324
2353
|
attempts++;
|
|
2325
|
-
var n =
|
|
2354
|
+
var n = countLive();
|
|
2326
2355
|
if (n > 0) {
|
|
2327
2356
|
clearInterval(poller);
|
|
2357
|
+
if (_reconnectPoller === poller) _reconnectPoller = null;
|
|
2328
2358
|
setCtaState('on');
|
|
2329
2359
|
deriveAndRenderStatus();
|
|
2330
2360
|
} else if (attempts > 20) { // ~10s max
|
|
2331
2361
|
clearInterval(poller);
|
|
2362
|
+
if (_reconnectPoller === poller) _reconnectPoller = null;
|
|
2363
|
+
_retryFailed = true;
|
|
2332
2364
|
setCtaState('reconnect');
|
|
2333
2365
|
deriveAndRenderStatus();
|
|
2334
2366
|
logWithHistory('Couldn\'t find your AI app. Open Claude (or your AI assistant), then press Try again.', 'error');
|
|
2335
2367
|
}
|
|
2336
2368
|
}, 500);
|
|
2369
|
+
_reconnectPoller = poller;
|
|
2337
2370
|
}
|
|
2338
2371
|
}
|
|
2339
2372
|
|
|
2340
|
-
// Keep the
|
|
2341
|
-
// never-connected or dropped plugin
|
|
2342
|
-
//
|
|
2343
|
-
//
|
|
2373
|
+
// Keep the connection button honest about the real connection state: a
|
|
2374
|
+
// never-connected or dropped plugin offers "Try again" instead of a
|
|
2375
|
+
// misleading "Pause". Skips while a scan is mid-flight (a press still
|
|
2376
|
+
// polling, or __wsIsScanning) to avoid fighting the transient click state.
|
|
2344
2377
|
function reconcileCta() {
|
|
2345
|
-
|
|
2346
|
-
if (!_ctaBtn) return;
|
|
2347
|
-
if (_ctaBtn.disabled) return;
|
|
2378
|
+
if (_ctaState === 'scanning') return;
|
|
2348
2379
|
if (typeof window.__wsIsScanning === 'function' && window.__wsIsScanning()) return;
|
|
2349
|
-
var n = (
|
|
2380
|
+
var n = countLive();
|
|
2350
2381
|
var paused = (typeof window.__wsIsPaused === 'function') ? window.__wsIsPaused() : false;
|
|
2351
2382
|
if (paused) {
|
|
2352
|
-
if (
|
|
2383
|
+
if (_ctaState !== 'paused') setCtaState('paused');
|
|
2353
2384
|
} else if (n > 0) {
|
|
2354
|
-
if (
|
|
2385
|
+
if (_ctaState !== 'on') setCtaState('on');
|
|
2355
2386
|
} else {
|
|
2356
|
-
if (
|
|
2387
|
+
if (_ctaState !== 'reconnect') setCtaState('reconnect');
|
|
2357
2388
|
}
|
|
2358
|
-
// First reconcile also unhides the button with its honest label.
|
|
2359
|
-
if (_ctaBtn.style.display === 'none') _ctaBtn.style.display = '';
|
|
2360
2389
|
}
|
|
2361
2390
|
|
|
2362
|
-
//
|
|
2363
|
-
// the
|
|
2364
|
-
|
|
2365
|
-
renderVersionLine();
|
|
2391
|
+
// Draw the status from the model straight away, so the first paint
|
|
2392
|
+
// already matches what the reconcile tick would show.
|
|
2393
|
+
deriveAndRenderStatus();
|
|
2366
2394
|
|
|
2367
|
-
// Periodic reconcile of
|
|
2368
|
-
// refreshes "
|
|
2369
|
-
// deriveAndRenderStatus.
|
|
2395
|
+
// Periodic reconcile of the connection button + status (cheap, <1ms).
|
|
2396
|
+
// Also refreshes the "Xs ago" of the last action.
|
|
2370
2397
|
setInterval(function() {
|
|
2371
2398
|
reconcileCta();
|
|
2372
2399
|
deriveAndRenderStatus();
|
|
2373
2400
|
}, 2000);
|
|
2374
2401
|
|
|
2375
2402
|
// One-shot on first ready: render honest initial state and capture the
|
|
2376
|
-
// plugin's own version (shown in the
|
|
2377
|
-
//
|
|
2378
|
-
//
|
|
2379
|
-
//
|
|
2380
|
-
//
|
|
2403
|
+
// plugin's own version and revision (shown in the activity header and the
|
|
2404
|
+
// copied log) without logging a command line — hence the unwrapped sender.
|
|
2405
|
+
// They're read from the GET_FILE_INFO_RESULT handler below. This fires
|
|
2406
|
+
// regardless of connection state, which is what lets the activity header
|
|
2407
|
+
// show the plugin's revision while no server is attached.
|
|
2381
2408
|
setTimeout(function() {
|
|
2382
2409
|
reconcileCta();
|
|
2383
2410
|
deriveAndRenderStatus();
|
|
@@ -2387,187 +2414,6 @@
|
|
|
2387
2414
|
// Size the plugin window to fit content on first paint.
|
|
2388
2415
|
requestAnimationFrame(autoResize);
|
|
2389
2416
|
|
|
2390
|
-
// Single source of truth for the cloud pairing status line — derives the
|
|
2391
|
-
// text from actual state (same philosophy as deriveAndRenderStatus for the
|
|
2392
|
-
// pill) instead of trusting one-off events. Every string is prefixed
|
|
2393
|
-
// "Cloud" so it can never read as the plugin's overall status, and the
|
|
2394
|
-
// line stays empty (hidden via :not(:empty)) unless it has something
|
|
2395
|
-
// useful to say — a background failure like an expired pairing code
|
|
2396
|
-
// restored from a previous session stays silent. Transient messages
|
|
2397
|
-
// ("Cloud: connecting…", bad-code errors) are written directly by
|
|
2398
|
-
// cloudDial/cloudConnect and survive until the next state change.
|
|
2399
|
-
function renderCloudStatus() {
|
|
2400
|
-
var statusEl = document.getElementById('cloud-status');
|
|
2401
|
-
if (!statusEl) return;
|
|
2402
|
-
var cp = document.getElementById('cloud-pair');
|
|
2403
|
-
var panelOpen = !!(cp && cp.classList.contains('visible'));
|
|
2404
|
-
var paused = (typeof window.__wsIsPaused === 'function') ? window.__wsIsPaused() : false;
|
|
2405
|
-
|
|
2406
|
-
if (paused) {
|
|
2407
|
-
// Pause closes the cloud socket deliberately and Resume redials it —
|
|
2408
|
-
// never present that as a lost pairing (retry is suppressed while
|
|
2409
|
-
// paused, so "reconnecting…" would also be untrue).
|
|
2410
|
-
statusEl.textContent = panelOpen ? 'Cloud: paused' : '';
|
|
2411
|
-
statusEl.className = 'cloud-status';
|
|
2412
|
-
} else if (hasLiveCloudConnection()) {
|
|
2413
|
-
statusEl.textContent = panelOpen ? 'Cloud: connected' : '';
|
|
2414
|
-
statusEl.className = 'cloud-status connected';
|
|
2415
|
-
} else if (!_cloudUserDisconnected && _cloudEverConnected && _cloudRetryCount < CLOUD_MAX_RETRIES) {
|
|
2416
|
-
// Paired earlier this session and dropped — actionable, so it shows
|
|
2417
|
-
// even while the panel is collapsed.
|
|
2418
|
-
statusEl.textContent = 'Cloud pairing lost — reconnecting…';
|
|
2419
|
-
statusEl.className = 'cloud-status';
|
|
2420
|
-
} else if (!_cloudUserDisconnected && _cloudEverConnected) {
|
|
2421
|
-
statusEl.textContent = 'Cloud pairing lost. Generate a fresh code in Claude and reconnect.';
|
|
2422
|
-
statusEl.className = 'cloud-status error';
|
|
2423
|
-
} else {
|
|
2424
|
-
statusEl.textContent = panelOpen ? 'Cloud: not connected' : '';
|
|
2425
|
-
statusEl.className = 'cloud-status';
|
|
2426
|
-
}
|
|
2427
|
-
autoResize();
|
|
2428
|
-
}
|
|
2429
|
-
|
|
2430
|
-
function resetCloudUI() {
|
|
2431
|
-
var btn = document.getElementById('cloud-btn');
|
|
2432
|
-
renderCloudStatus();
|
|
2433
|
-
if (btn) {
|
|
2434
|
-
btn.disabled = false;
|
|
2435
|
-
btn.textContent = 'Connect';
|
|
2436
|
-
btn.onclick = cloudConnect;
|
|
2437
|
-
}
|
|
2438
|
-
cloudWs = null;
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
// Shared dialer used by manual Connect, auto-reconnect after a drop,
|
|
2442
|
-
// restored-config auto-connect, and Resume-after-Pause. `isAuto` softens
|
|
2443
|
-
// the error UX for background attempts and arms the bounded retry chain.
|
|
2444
|
-
function cloudDial(code, isAuto) {
|
|
2445
|
-
var btn = document.getElementById('cloud-btn');
|
|
2446
|
-
var statusEl = document.getElementById('cloud-status');
|
|
2447
|
-
|
|
2448
|
-
// Close existing cloud connection if any (manual reason suppresses
|
|
2449
|
-
// the pool's same-port retry for the old socket).
|
|
2450
|
-
if (cloudWs && cloudWs.readyState <= 1) {
|
|
2451
|
-
try { cloudWs.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
if (btn) btn.disabled = true;
|
|
2455
|
-
// Manual attempts show progress; auto re-dials render the derived state
|
|
2456
|
-
// ("Cloud pairing lost — reconnecting…", or silence for a background
|
|
2457
|
-
// restore) so an unlabeled transient never floats under the main pill.
|
|
2458
|
-
if (isAuto) {
|
|
2459
|
-
renderCloudStatus();
|
|
2460
|
-
} else if (statusEl) {
|
|
2461
|
-
statusEl.textContent = 'Cloud: connecting…';
|
|
2462
|
-
statusEl.className = 'cloud-status';
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
|
-
try {
|
|
2466
|
-
var opened = false;
|
|
2467
|
-
var sawError = false;
|
|
2468
|
-
cloudWs = new WebSocket(CLOUD_RELAY_HOST + '/ws/pair?code=' + code);
|
|
2469
|
-
|
|
2470
|
-
cloudWs.onopen = function() {
|
|
2471
|
-
opened = true;
|
|
2472
|
-
_lastCloudCode = code;
|
|
2473
|
-
_cloudUserDisconnected = false;
|
|
2474
|
-
_cloudRetryCount = 0;
|
|
2475
|
-
_cloudEverConnected = true;
|
|
2476
|
-
if (btn) { btn.disabled = false; btn.textContent = 'Disconnect'; btn.onclick = cloudDisconnect; }
|
|
2477
|
-
|
|
2478
|
-
// Add to the shared connection pool (uses same handlers as localhost).
|
|
2479
|
-
// Pass resetCloudUI as disconnect callback — attachWsHandlers overwrites
|
|
2480
|
-
// onclose, so this callback ensures cloud UI resets on server-initiated close.
|
|
2481
|
-
if (window.__wsAddCloudConnection) {
|
|
2482
|
-
window.__wsAddCloudConnection(cloudWs, 'cloud', resetCloudUI);
|
|
2483
|
-
}
|
|
2484
|
-
|
|
2485
|
-
// After the pool add, so hasLiveCloudConnection() sees this socket.
|
|
2486
|
-
renderCloudStatus();
|
|
2487
|
-
|
|
2488
|
-
// Persist cloud config via code.js clientStorage
|
|
2489
|
-
parent.postMessage({ pluginMessage: {
|
|
2490
|
-
type: 'STORE_CLOUD_CONFIG',
|
|
2491
|
-
code: code
|
|
2492
|
-
}}, '*');
|
|
2493
|
-
};
|
|
2494
|
-
|
|
2495
|
-
cloudWs.onerror = function() {
|
|
2496
|
-
sawError = true;
|
|
2497
|
-
if (statusEl && !isAuto) {
|
|
2498
|
-
statusEl.textContent = 'That code didn\'t work. Ask Claude for a fresh pairing code and try again.';
|
|
2499
|
-
statusEl.className = 'cloud-status error';
|
|
2500
|
-
}
|
|
2501
|
-
if (btn) btn.disabled = false;
|
|
2502
|
-
};
|
|
2503
|
-
|
|
2504
|
-
// Note: onclose here handles pre-connection close (e.g., bad code).
|
|
2505
|
-
// After onopen, attachWsHandlers overwrites this — resetCloudUI callback
|
|
2506
|
-
// handles post-connection close instead.
|
|
2507
|
-
cloudWs.onclose = function(event) {
|
|
2508
|
-
if (!opened && sawError && !isAuto) {
|
|
2509
|
-
// Keep the visible error message (onclose fires right after
|
|
2510
|
-
// onerror and would otherwise clobber it); restore the button.
|
|
2511
|
-
if (btn) { btn.disabled = false; btn.textContent = 'Connect'; btn.onclick = cloudConnect; }
|
|
2512
|
-
cloudWs = null;
|
|
2513
|
-
} else {
|
|
2514
|
-
resetCloudUI();
|
|
2515
|
-
}
|
|
2516
|
-
// Auto attempt that never opened → keep trying within the budget.
|
|
2517
|
-
if (isAuto && !opened) scheduleCloudRetry();
|
|
2518
|
-
};
|
|
2519
|
-
} catch (e) {
|
|
2520
|
-
if (statusEl) { statusEl.textContent = 'Failed: ' + e.message; statusEl.className = 'cloud-status error'; }
|
|
2521
|
-
if (btn) btn.disabled = false;
|
|
2522
|
-
}
|
|
2523
|
-
}
|
|
2524
|
-
|
|
2525
|
-
// Bounded auto-reconnect with backoff. Gives up after CLOUD_MAX_RETRIES,
|
|
2526
|
-
// never fires while paused or after a deliberate user Disconnect.
|
|
2527
|
-
function scheduleCloudRetry() {
|
|
2528
|
-
if (_cloudUserDisconnected || !_lastCloudCode) return;
|
|
2529
|
-
if (typeof window.__wsIsPaused === 'function' && window.__wsIsPaused()) return;
|
|
2530
|
-
if (_cloudRetryCount >= CLOUD_MAX_RETRIES) return;
|
|
2531
|
-
_cloudRetryCount++;
|
|
2532
|
-
setTimeout(function() {
|
|
2533
|
-
if (_cloudUserDisconnected || hasLiveCloudConnection()) return;
|
|
2534
|
-
if (typeof window.__wsIsPaused === 'function' && window.__wsIsPaused()) return;
|
|
2535
|
-
cloudDial(_lastCloudCode, true);
|
|
2536
|
-
}, Math.min(2000 * _cloudRetryCount, 10000));
|
|
2537
|
-
}
|
|
2538
|
-
|
|
2539
|
-
// Called by the connection pool when the pooled cloud connection drops —
|
|
2540
|
-
// re-dials the actual relay URL instead of 'ws://localhost:cloud'.
|
|
2541
|
-
window.__cloudReconnect = function() {
|
|
2542
|
-
scheduleCloudRetry();
|
|
2543
|
-
};
|
|
2544
|
-
|
|
2545
|
-
function cloudConnect() {
|
|
2546
|
-
var codeInput = document.getElementById('cloud-code');
|
|
2547
|
-
var statusEl = document.getElementById('cloud-status');
|
|
2548
|
-
var code = (codeInput.value || '').trim().toUpperCase();
|
|
2549
|
-
|
|
2550
|
-
if (!code || code.length < 4) {
|
|
2551
|
-
statusEl.textContent = 'Enter pairing code';
|
|
2552
|
-
statusEl.className = 'cloud-status error';
|
|
2553
|
-
return;
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
_cloudUserDisconnected = false;
|
|
2557
|
-
_cloudRetryCount = 0;
|
|
2558
|
-
cloudDial(code, false);
|
|
2559
|
-
}
|
|
2560
|
-
|
|
2561
|
-
function cloudDisconnect() {
|
|
2562
|
-
_cloudUserDisconnected = true; // deliberate — suppress auto re-dial
|
|
2563
|
-
_cloudEverConnected = false; // a deliberate disconnect is not a "lost" pairing
|
|
2564
|
-
if (cloudWs) {
|
|
2565
|
-
try { cloudWs.close(1000, 'Manual disconnect'); } catch (e) {}
|
|
2566
|
-
}
|
|
2567
|
-
// Reset UI immediately — don't rely on onclose (may be overwritten)
|
|
2568
|
-
resetCloudUI();
|
|
2569
|
-
}
|
|
2570
|
-
|
|
2571
2417
|
// ============================================================================
|
|
2572
2418
|
// MESSAGE HANDLER - Process responses from plugin worker
|
|
2573
2419
|
// ============================================================================
|
|
@@ -2635,7 +2481,7 @@
|
|
|
2635
2481
|
|
|
2636
2482
|
case 'ERROR':
|
|
2637
2483
|
window.__figmaVariablesReady = false;
|
|
2638
|
-
bridgeError = true; //
|
|
2484
|
+
bridgeError = true; // window shows "Something went wrong"
|
|
2639
2485
|
deriveAndRenderStatus();
|
|
2640
2486
|
console.error('[MCP Bridge] Error:', msg.error);
|
|
2641
2487
|
break;
|
|
@@ -2848,32 +2694,25 @@
|
|
|
2848
2694
|
|
|
2849
2695
|
// File info
|
|
2850
2696
|
case 'GET_FILE_INFO_RESULT':
|
|
2851
|
-
// Capture the plugin's own version for the
|
|
2852
|
-
//
|
|
2853
|
-
//
|
|
2697
|
+
// Capture the plugin's own version and revision for the activity
|
|
2698
|
+
// header and the copied log (any GET_FILE_INFO response keeps them
|
|
2699
|
+
// fresh, regardless of who asked).
|
|
2854
2700
|
var fileInfo = msg.fileInfo || msg.data;
|
|
2855
2701
|
if (fileInfo && fileInfo.pluginVersion) {
|
|
2856
2702
|
PLUGIN_VERSION = 'v' + fileInfo.pluginVersion;
|
|
2857
|
-
// Paint immediately instead of waiting up to 2s for the next
|
|
2858
|
-
// reconcile tick — this is the first moment the version is known.
|
|
2859
|
-
if (typeof renderVersionLine === 'function') renderVersionLine();
|
|
2860
2703
|
}
|
|
2704
|
+
if (fileInfo && typeof fileInfo.forkPluginRevision === 'number') {
|
|
2705
|
+
PLUGIN_REVISION = fileInfo.forkPluginRevision;
|
|
2706
|
+
}
|
|
2707
|
+
// Paint immediately instead of waiting up to 2s for the next
|
|
2708
|
+
// reconcile tick — this is the first moment the revision is known.
|
|
2709
|
+
if (fileInfo && typeof renderVersionLine === 'function') renderVersionLine();
|
|
2861
2710
|
handleResult('GET_FILE_INFO', 'fileInfo');
|
|
2862
2711
|
break;
|
|
2863
2712
|
|
|
2864
|
-
//
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
if (msg.config && msg.config.code && !_cloudUserDisconnected) {
|
|
2868
|
-
var restoredCode = String(msg.config.code).trim().toUpperCase();
|
|
2869
|
-
var restoredInput = document.getElementById('cloud-code');
|
|
2870
|
-
if (restoredInput) restoredInput.value = restoredCode;
|
|
2871
|
-
if (restoredCode.length >= 4 && !hasLiveCloudConnection()) {
|
|
2872
|
-
_lastCloudCode = restoredCode;
|
|
2873
|
-
_cloudRetryCount = 0;
|
|
2874
|
-
cloudDial(restoredCode, true);
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2713
|
+
// The stored window setting, asked for once at startup (below).
|
|
2714
|
+
case 'UI_PREFS':
|
|
2715
|
+
setMinimized(msg.minimized === true, false);
|
|
2877
2716
|
break;
|
|
2878
2717
|
|
|
2879
2718
|
// Plugin UI reload
|
|
@@ -2928,6 +2767,11 @@
|
|
|
2928
2767
|
break;
|
|
2929
2768
|
}
|
|
2930
2769
|
};
|
|
2770
|
+
|
|
2771
|
+
// Now that the listener is attached, ask code.js for the stored window
|
|
2772
|
+
// setting. It answers with UI_PREFS. A plain message, not a bridge
|
|
2773
|
+
// command, so it's never logged.
|
|
2774
|
+
parent.postMessage({ pluginMessage: { type: 'GET_UI_PREFS' } }, '*');
|
|
2931
2775
|
</script>
|
|
2932
2776
|
</body>
|
|
2933
2777
|
</html>
|