tailcat-webui 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +29 -0
- package/README.en.md +112 -0
- package/README.md +101 -2
- package/bin/tailcat-webui.js +12 -0
- package/docs/CORE-API.md +343 -0
- package/docs/DESIGN.md +398 -0
- package/docs/assets/character.jpg +0 -0
- package/docs/assets/portrait.jpg +0 -0
- package/docs/screenshots/01-overview-light.png +0 -0
- package/docs/screenshots/02-overview-dark.png +0 -0
- package/docs/screenshots/03-ticket-light.png +0 -0
- package/docs/screenshots/04-ticket-qr-light.png +0 -0
- package/docs/screenshots/05-settings-light.png +0 -0
- package/docs/screenshots/06-diagnostics-light.png +0 -0
- package/docs/screenshots/07-mobile-overview.png +0 -0
- package/docs/screenshots/08-install-missing.png +0 -0
- package/docs/screenshots/09-keeper.png +0 -0
- package/package.json +56 -4
- package/src/cli.js +238 -0
- package/src/config.js +167 -0
- package/src/devices.js +163 -0
- package/src/errors.js +24 -0
- package/src/index.js +19 -0
- package/src/installer.js +907 -0
- package/src/manager.js +647 -0
- package/src/parse.js +207 -0
- package/src/paths.js +97 -0
- package/src/preferences.js +190 -0
- package/src/qr.js +37 -0
- package/src/relay.js +76 -0
- package/src/runtime/node.js +281 -0
- package/src/serve-targets.js +127 -0
- package/src/server.js +674 -0
- package/src/settings.js +262 -0
- package/src/supervisor.js +833 -0
- package/vendor/qrcode.mjs +2289 -0
- package/web/api.js +114 -0
- package/web/assets/portrait.jpg +0 -0
- package/web/boot.js +29 -0
- package/web/components.js +558 -0
- package/web/dict.js +663 -0
- package/web/drawer-access.js +318 -0
- package/web/drawer-address.js +271 -0
- package/web/drawer-automation.js +223 -0
- package/web/drawer-relay.js +128 -0
- package/web/drawer-tunnel.js +309 -0
- package/web/drawer.js +302 -0
- package/web/format.js +252 -0
- package/web/icon.png +0 -0
- package/web/index.html +29 -0
- package/web/main.js +471 -0
- package/web/room-diagnostics.js +426 -0
- package/web/room-overview.js +438 -0
- package/web/room-settings.js +71 -0
- package/web/store.js +168 -0
- package/web/styles.css +2873 -0
- package/web/ticket.js +212 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room: overview.
|
|
3
|
+
*
|
|
4
|
+
* The three motifs live here: the status word with its fact sentence, the
|
|
5
|
+
* tunnel line drawn from the cat's tail, and the pairing ticket. The page also
|
|
6
|
+
* explains the connection in three steps and is the only place the
|
|
7
|
+
* post-quantum callout appears.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
h,
|
|
12
|
+
button,
|
|
13
|
+
icon,
|
|
14
|
+
pill,
|
|
15
|
+
alertBox,
|
|
16
|
+
fromMarkup,
|
|
17
|
+
codeBlock,
|
|
18
|
+
setText,
|
|
19
|
+
setHidden,
|
|
20
|
+
setDisabled,
|
|
21
|
+
setClass,
|
|
22
|
+
syncSignature,
|
|
23
|
+
pixelCat,
|
|
24
|
+
ribbonBow,
|
|
25
|
+
CAT_FACE_PATH,
|
|
26
|
+
CAT_EYES_PATH,
|
|
27
|
+
} from './components.js';
|
|
28
|
+
import { createTicket } from './ticket.js';
|
|
29
|
+
import {
|
|
30
|
+
phaseOf,
|
|
31
|
+
phaseKey,
|
|
32
|
+
tailcatOf,
|
|
33
|
+
settingsOf,
|
|
34
|
+
installerOf,
|
|
35
|
+
pairingOf,
|
|
36
|
+
formatDuration,
|
|
37
|
+
formatRegion,
|
|
38
|
+
failureText,
|
|
39
|
+
} from './format.js';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Build the tunnel line. The wire itself is one stretched SVG; the cat and the
|
|
43
|
+
* client device are fixed-size drawings at the ends so a wide window does not
|
|
44
|
+
* flatten them.
|
|
45
|
+
* @param {Function} t - translator.
|
|
46
|
+
* @returns {{ el: HTMLElement, update: (phase: string) => void }} tunnel line.
|
|
47
|
+
*/
|
|
48
|
+
function createTunnelLine(t) {
|
|
49
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
50
|
+
const clipId = 'tw-tunnel-reveal';
|
|
51
|
+
|
|
52
|
+
const cat = fromMarkup(`<svg class="tunnel-cat" viewBox="0 0 64 64" aria-hidden="true" focusable="false">
|
|
53
|
+
<g fill="currentColor">
|
|
54
|
+
<path d="M38 49c7 1.5 12-2 15-6 1.6-1.8 2.6-4 3-6" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>
|
|
55
|
+
<path d="M20 62c-3-7-4-15-2-22 1.2-4.6 3.4-8.2 6.4-10.6h15.2c3 2.4 5.2 6 6.4 10.6 2 7 1 15-2 22H20Z"/>
|
|
56
|
+
<g transform="translate(21 10) scale(0.62)">
|
|
57
|
+
<path fill="currentColor" fill-rule="evenodd" d="${CAT_FACE_PATH} ${CAT_EYES_PATH}"/>
|
|
58
|
+
</g>
|
|
59
|
+
</g>
|
|
60
|
+
</svg>`);
|
|
61
|
+
|
|
62
|
+
const device = fromMarkup(`<svg class="tunnel-device" viewBox="0 0 18 12" aria-hidden="true" focusable="false">
|
|
63
|
+
<rect x="0.75" y="0.75" width="16.5" height="8" rx="1.4" fill="none" stroke="currentColor" stroke-width="1.4"/>
|
|
64
|
+
<path d="M4.5 11h9" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>
|
|
65
|
+
</svg>`);
|
|
66
|
+
|
|
67
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
68
|
+
svg.setAttribute('class', 'tunnel-wire');
|
|
69
|
+
svg.setAttribute('viewBox', '0 0 720 64');
|
|
70
|
+
svg.setAttribute('preserveAspectRatio', 'none');
|
|
71
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
72
|
+
const defs = document.createElementNS(ns, 'defs');
|
|
73
|
+
const clip = document.createElementNS(ns, 'clipPath');
|
|
74
|
+
clip.setAttribute('id', clipId);
|
|
75
|
+
const reveal = document.createElementNS(ns, 'rect');
|
|
76
|
+
reveal.setAttribute('x', '0');
|
|
77
|
+
reveal.setAttribute('y', '0');
|
|
78
|
+
reveal.setAttribute('height', '64');
|
|
79
|
+
reveal.setAttribute('width', '720');
|
|
80
|
+
clip.append(reveal);
|
|
81
|
+
defs.append(clip);
|
|
82
|
+
svg.append(defs);
|
|
83
|
+
const group = document.createElementNS(ns, 'g');
|
|
84
|
+
group.setAttribute('class', 'tunnel-line-group');
|
|
85
|
+
group.setAttribute('clip-path', `url(#${clipId})`);
|
|
86
|
+
svg.append(group);
|
|
87
|
+
|
|
88
|
+
const labels = h('div', { class: 'tunnel-labels', 'aria-hidden': 'true' },
|
|
89
|
+
h('span', null, t('wireLocal')),
|
|
90
|
+
h('span', null, t('wireClient')));
|
|
91
|
+
|
|
92
|
+
const el = h('div', { class: 'tunnel', 'data-wire': 'stopped' },
|
|
93
|
+
h('div', { class: 'tunnel-stage' }, cat, svg, device),
|
|
94
|
+
labels);
|
|
95
|
+
|
|
96
|
+
let drawn = false;
|
|
97
|
+
let raf = 0;
|
|
98
|
+
let signature = '';
|
|
99
|
+
|
|
100
|
+
function paint(next) {
|
|
101
|
+
const shape = next === 'error' ? 'error' : 'line';
|
|
102
|
+
if (shape !== signature) {
|
|
103
|
+
signature = shape;
|
|
104
|
+
const paths = shape === 'error' ? ['M0 40 H322', 'M328 40 H720'] : ['M0 40 H720'];
|
|
105
|
+
group.replaceChildren(...paths.map((d) => {
|
|
106
|
+
const path = document.createElementNS(ns, 'path');
|
|
107
|
+
path.setAttribute('d', d);
|
|
108
|
+
return path;
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function drawIn() {
|
|
114
|
+
if (drawn) return;
|
|
115
|
+
drawn = true;
|
|
116
|
+
const reduce = typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
117
|
+
if (reduce) {
|
|
118
|
+
reveal.setAttribute('width', '720');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const start = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
122
|
+
const step = (now) => {
|
|
123
|
+
const progress = Math.min(1, (now - start) / 700);
|
|
124
|
+
const eased = 1 - Math.pow(1 - progress, 3);
|
|
125
|
+
reveal.setAttribute('width', String(720 * eased));
|
|
126
|
+
if (progress < 1) raf = requestAnimationFrame(step);
|
|
127
|
+
else raf = 0;
|
|
128
|
+
};
|
|
129
|
+
raf = requestAnimationFrame(step);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
el,
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} phase - pipeline phase.
|
|
136
|
+
*/
|
|
137
|
+
update(phase) {
|
|
138
|
+
let wire = 'stopped';
|
|
139
|
+
if (phase === 'online') wire = 'online';
|
|
140
|
+
else if (phase === 'starting' || phase === 'restarting' || phase === 'stopping') wire = 'pending';
|
|
141
|
+
else if (phase === 'error') wire = 'error';
|
|
142
|
+
el.setAttribute('data-wire', wire);
|
|
143
|
+
paint(phase);
|
|
144
|
+
drawIn();
|
|
145
|
+
},
|
|
146
|
+
dispose() {
|
|
147
|
+
if (raf !== 0) cancelAnimationFrame(raf);
|
|
148
|
+
raf = 0;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @param {object} ctx - shell context.
|
|
155
|
+
* @returns {{ el: HTMLElement, update: (state: object | null) => void }} room.
|
|
156
|
+
*/
|
|
157
|
+
export function createOverviewRoom(ctx) {
|
|
158
|
+
const t = ctx.t;
|
|
159
|
+
const ui = ctx.overviewUi;
|
|
160
|
+
if (typeof ui.rotateArmed !== 'boolean') ui.rotateArmed = false;
|
|
161
|
+
let rotateTimer = null;
|
|
162
|
+
let lastSpokenPhase = '';
|
|
163
|
+
let lastPhase = '';
|
|
164
|
+
|
|
165
|
+
const ticket = createTicket(ctx, ctx.ticketUi);
|
|
166
|
+
const tunnel = createTunnelLine(t);
|
|
167
|
+
|
|
168
|
+
/* Program banner -------------------------------------------------------- */
|
|
169
|
+
const programBanner = h('div', { class: 'program-banner', role: 'note', hidden: true },
|
|
170
|
+
h('span', { class: 'program-banner-icon', 'aria-hidden': 'true' }, icon('caution')),
|
|
171
|
+
h('div', { class: 'program-banner-copy' },
|
|
172
|
+
h('p', { class: 'program-banner-title' }, t('programMissingTitle')),
|
|
173
|
+
h('p', { class: 'program-banner-body' }, t('programBannerBody'))),
|
|
174
|
+
button({
|
|
175
|
+
label: t('programMissingAction'),
|
|
176
|
+
variant: 'secondary',
|
|
177
|
+
testid: 'program-banner-action',
|
|
178
|
+
onClick: () => ctx.goRoom('diagnostics'),
|
|
179
|
+
}));
|
|
180
|
+
|
|
181
|
+
const lastErrorText = h('p', { class: 'error-text' });
|
|
182
|
+
const errorAlert = alertBox({ tone: 'danger', title: t('lastErrorTitle'), children: lastErrorText });
|
|
183
|
+
setHidden(errorAlert, true);
|
|
184
|
+
|
|
185
|
+
/* Hero ------------------------------------------------------------------ */
|
|
186
|
+
const statusWord = h('h2', { class: 'hero-status', 'data-testid': 'status-phase' });
|
|
187
|
+
const statusDot = h('span', { class: 'hero-dot', 'aria-hidden': 'true' });
|
|
188
|
+
const pqPill = pill(t('pqPill'), 'pq');
|
|
189
|
+
setHidden(pqPill, true);
|
|
190
|
+
const fact = h('p', { class: 'hero-fact' });
|
|
191
|
+
const live = h('span', { class: 'sr-only', role: 'status', 'aria-live': 'polite' });
|
|
192
|
+
|
|
193
|
+
const stopButton = button({ label: t('heroStop'), testid: 'hero-stop', onClick: () => void run('stop', 'noticeStopped') });
|
|
194
|
+
const restartButton = button({ label: t('heroRestart'), testid: 'hero-restart', onClick: () => void run('restart', 'noticeRestarted') });
|
|
195
|
+
const rotateButton = button({ label: t('heroRotate'), variant: 'ghost', testid: 'hero-rotate', onClick: armOrRotate });
|
|
196
|
+
const rotateCancel = button({ label: t('cancel'), variant: 'ghost', hidden: true, testid: 'hero-rotate-cancel', onClick: disarmRotate });
|
|
197
|
+
|
|
198
|
+
const startButton = button({ label: t('heroStart'), variant: 'primary', testid: 'hero-start', onClick: () => void run('start', 'noticeStarted') });
|
|
199
|
+
const refreshButton = button({ label: t('refresh'), variant: 'ghost', testid: 'hero-refresh', onClick: () => void ctx.refresh() });
|
|
200
|
+
|
|
201
|
+
const runningActions = h('div', { class: 'hero-actions', hidden: true }, stopButton, restartButton, rotateButton, rotateCancel);
|
|
202
|
+
const idleActions = h('div', { class: 'hero-actions', hidden: true }, startButton, refreshButton);
|
|
203
|
+
const rotateNote = h('p', { class: 'hero-rotate-note', hidden: true }, t('rotateArmNote'));
|
|
204
|
+
const actionBlock = h('div', { class: 'hero-actions-block' }, runningActions, idleActions, rotateNote);
|
|
205
|
+
|
|
206
|
+
const hero = h('section', { class: 'hero', 'data-phase': 'unknown' },
|
|
207
|
+
h('div', { class: 'hero-main' },
|
|
208
|
+
h('div', { class: 'hero-status-row' }, statusDot, statusWord, pqPill),
|
|
209
|
+
fact,
|
|
210
|
+
live),
|
|
211
|
+
actionBlock);
|
|
212
|
+
|
|
213
|
+
/* Post-quantum callout -------------------------------------------------- */
|
|
214
|
+
const pqCallout = h('section', { class: 'pq-callout', 'data-testid': 'pq-warning' },
|
|
215
|
+
h('span', { class: 'pq-callout-icon', 'aria-hidden': 'true' }, icon('postquantum')),
|
|
216
|
+
h('div', { class: 'pq-callout-body' },
|
|
217
|
+
h('h2', { class: 'pq-callout-title' }, t('pqTitle')),
|
|
218
|
+
h('p', { class: 'pq-callout-text' }, t('pqBody')),
|
|
219
|
+
button({
|
|
220
|
+
label: t('pqAction'),
|
|
221
|
+
variant: 'ghost',
|
|
222
|
+
testid: 'pq-action',
|
|
223
|
+
onClick: () => {
|
|
224
|
+
ctx.goRoom('settings');
|
|
225
|
+
ctx.openDrawer('access', { focus: true, select: '[data-testid="switch-hybrid"]' });
|
|
226
|
+
},
|
|
227
|
+
})));
|
|
228
|
+
|
|
229
|
+
/* Steps ----------------------------------------------------------------- */
|
|
230
|
+
const stepCommandSlot = h('div', { class: 'step-code' });
|
|
231
|
+
const stepLocalSlot = h('div', { class: 'step-code' });
|
|
232
|
+
const steps = h('section', { class: 'steps' },
|
|
233
|
+
h('h2', { class: 'steps-title' }, t('stepsTitle')),
|
|
234
|
+
h('div', { class: 'steps-grid' },
|
|
235
|
+
h('article', { class: 'step' },
|
|
236
|
+
h('span', { class: 'step-num', 'aria-hidden': 'true' }, '1'),
|
|
237
|
+
h('div', { class: 'step-body' },
|
|
238
|
+
h('h3', { class: 'step-title' }, t('step1Title')),
|
|
239
|
+
h('p', { class: 'step-text' }, t('step1Body')),
|
|
240
|
+
h('a', {
|
|
241
|
+
class: 'step-link',
|
|
242
|
+
href: 'https://github.com/tailscale/tailcat#install',
|
|
243
|
+
target: '_blank',
|
|
244
|
+
rel: 'noopener noreferrer',
|
|
245
|
+
}, t('step1Link')))),
|
|
246
|
+
h('article', { class: 'step' },
|
|
247
|
+
h('span', { class: 'step-num', 'aria-hidden': 'true' }, '2'),
|
|
248
|
+
h('div', { class: 'step-body' },
|
|
249
|
+
h('h3', { class: 'step-title' }, t('step2Title')),
|
|
250
|
+
h('p', { class: 'step-text' }, t('step2Body')),
|
|
251
|
+
stepCommandSlot)),
|
|
252
|
+
h('article', { class: 'step' },
|
|
253
|
+
h('span', { class: 'step-num', 'aria-hidden': 'true' }, '3'),
|
|
254
|
+
h('div', { class: 'step-body' },
|
|
255
|
+
h('h3', { class: 'step-title' }, t('step3Title')),
|
|
256
|
+
h('p', { class: 'step-text' }, t('step3Body')),
|
|
257
|
+
stepLocalSlot))));
|
|
258
|
+
|
|
259
|
+
/* Keeper card ------------------------------------------------------------- */
|
|
260
|
+
const keeperArt = h('div', { class: 'keeper-art' },
|
|
261
|
+
h('img', {
|
|
262
|
+
class: 'keeper-portrait',
|
|
263
|
+
src: '/assets/portrait.jpg',
|
|
264
|
+
alt: '',
|
|
265
|
+
width: 176,
|
|
266
|
+
height: 176,
|
|
267
|
+
loading: 'lazy',
|
|
268
|
+
decoding: 'async',
|
|
269
|
+
}),
|
|
270
|
+
ribbonBow(30));
|
|
271
|
+
const keeper = h('section', { class: 'keeper', 'data-testid': 'keeper', 'aria-labelledby': 'keeper-title' },
|
|
272
|
+
keeperArt,
|
|
273
|
+
h('div', { class: 'keeper-copy' },
|
|
274
|
+
h('h2', { class: 'keeper-title', id: 'keeper-title' }, pixelCat(18), t('keeperTitle')),
|
|
275
|
+
h('p', { class: 'keeper-text' }, t('keeperBody')),
|
|
276
|
+
h('p', { class: 'keeper-credit' }, t('keeperCredit'))),
|
|
277
|
+
h('div', { class: 'keeper-plush', 'aria-hidden': 'true' }, pixelCat(56)));
|
|
278
|
+
|
|
279
|
+
const el = h('section', {
|
|
280
|
+
class: 'room',
|
|
281
|
+
'data-testid': 'room-panel-overview',
|
|
282
|
+
id: 'room-overview',
|
|
283
|
+
role: 'tabpanel',
|
|
284
|
+
'aria-labelledby': 'tab-overview',
|
|
285
|
+
}, programBanner, errorAlert, hero, tunnel.el, ticket.el, pqCallout, steps, keeper);
|
|
286
|
+
|
|
287
|
+
function disarmRotate() {
|
|
288
|
+
ui.rotateArmed = false;
|
|
289
|
+
if (rotateTimer !== null) {
|
|
290
|
+
clearTimeout(rotateTimer);
|
|
291
|
+
rotateTimer = null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function armOrRotate() {
|
|
296
|
+
if (ui.rotateArmed) {
|
|
297
|
+
void run('rotate', 'noticeRotated');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
ui.rotateArmed = true;
|
|
301
|
+
if (rotateTimer !== null) clearTimeout(rotateTimer);
|
|
302
|
+
rotateTimer = setTimeout(() => {
|
|
303
|
+
rotateTimer = null;
|
|
304
|
+
disarmRotate();
|
|
305
|
+
update(ctx.state());
|
|
306
|
+
}, 8_000);
|
|
307
|
+
update(ctx.state());
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @param {string} action - write action.
|
|
312
|
+
* @param {string} successKey - notice copy on success.
|
|
313
|
+
*/
|
|
314
|
+
async function run(action, successKey) {
|
|
315
|
+
disarmRotate();
|
|
316
|
+
const result = await ctx.act(action, {});
|
|
317
|
+
if (result.ok) ctx.notify('ok', t(successKey));
|
|
318
|
+
else ctx.notify('error', failureText(result.error, t, 'actionFailed'));
|
|
319
|
+
update(ctx.state());
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @param {object | null} state - latest snapshot.
|
|
324
|
+
*/
|
|
325
|
+
function update(state) {
|
|
326
|
+
if (!state) return;
|
|
327
|
+
const phase = phaseOf(state);
|
|
328
|
+
const tailcat = tailcatOf(state);
|
|
329
|
+
const settings = settingsOf(state);
|
|
330
|
+
const pairing = pairingOf(state);
|
|
331
|
+
const phaseWord = t(phaseKey(phase));
|
|
332
|
+
|
|
333
|
+
hero.setAttribute('data-phase', phase);
|
|
334
|
+
if (phase === 'online' && lastPhase !== 'online') {
|
|
335
|
+
ticket.el.classList.remove('is-stamped');
|
|
336
|
+
void ticket.el.offsetWidth;
|
|
337
|
+
ticket.el.classList.add('is-stamped');
|
|
338
|
+
}
|
|
339
|
+
lastPhase = phase;
|
|
340
|
+
setText(statusWord, phaseWord);
|
|
341
|
+
if (phaseWord !== lastSpokenPhase) {
|
|
342
|
+
lastSpokenPhase = phaseWord;
|
|
343
|
+
setText(live, phaseWord);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const parts = [];
|
|
347
|
+
const region = formatRegion(tailcat.region);
|
|
348
|
+
if (phase === 'online') {
|
|
349
|
+
if (region !== '') parts.push(t('factVia', { region }));
|
|
350
|
+
const since = tailcat.onlineAt || tailcat.startedAt;
|
|
351
|
+
if (typeof since === 'string') {
|
|
352
|
+
const started = Date.parse(since);
|
|
353
|
+
if (Number.isFinite(started)) parts.push(t('factUptime', { duration: formatDuration(Date.now() - started, t) }));
|
|
354
|
+
}
|
|
355
|
+
} else if (phase === 'starting') {
|
|
356
|
+
parts.push(t('factStarting'));
|
|
357
|
+
} else if (phase === 'restarting') {
|
|
358
|
+
parts.push(t('factRestarting'));
|
|
359
|
+
} else if (phase === 'stopping') {
|
|
360
|
+
parts.push(t('factStopping'));
|
|
361
|
+
}
|
|
362
|
+
setText(fact, parts.join(t('factJoin')));
|
|
363
|
+
|
|
364
|
+
const hybrid = settings.hybrid === true;
|
|
365
|
+
setHidden(pqPill, !hybrid);
|
|
366
|
+
setHidden(pqCallout, hybrid);
|
|
367
|
+
setHidden(programBanner, !programMissing(state));
|
|
368
|
+
|
|
369
|
+
const lastError = typeof tailcat.lastError === 'string' && tailcat.lastError !== '' ? tailcat.lastError : '';
|
|
370
|
+
setHidden(errorAlert, !(phase === 'error' && lastError !== ''));
|
|
371
|
+
if (lastError !== '') setText(lastErrorText, lastError);
|
|
372
|
+
|
|
373
|
+
const busy = ctx.busy() !== null;
|
|
374
|
+
const running = phase === 'online' || phase === 'starting' || phase === 'restarting' || phase === 'stopping';
|
|
375
|
+
setHidden(runningActions, !running);
|
|
376
|
+
setHidden(idleActions, running);
|
|
377
|
+
runningActions.setAttribute('aria-busy', busy ? 'true' : 'false');
|
|
378
|
+
idleActions.setAttribute('aria-busy', busy ? 'true' : 'false');
|
|
379
|
+
|
|
380
|
+
setDisabled(stopButton, busy);
|
|
381
|
+
setDisabled(restartButton, busy);
|
|
382
|
+
setDisabled(startButton, busy);
|
|
383
|
+
setDisabled(refreshButton, busy);
|
|
384
|
+
setText(stopButton, ctx.busy() === 'stop' ? t('busyStop') : t('heroStop'));
|
|
385
|
+
setText(restartButton, ctx.busy() === 'restart' ? t('busyRestart') : t('heroRestart'));
|
|
386
|
+
setText(startButton, ctx.busy() === 'start' ? t('busyStart') : t('heroStart'));
|
|
387
|
+
|
|
388
|
+
const ephemeral = settings.addressMode === 'ephemeral';
|
|
389
|
+
if (ephemeral) disarmRotate();
|
|
390
|
+
setHidden(rotateNote, !ui.rotateArmed);
|
|
391
|
+
setHidden(rotateCancel, !ui.rotateArmed);
|
|
392
|
+
setDisabled(rotateButton, busy || ephemeral);
|
|
393
|
+
setText(rotateButton, ctx.busy() === 'rotate' ? t('busyRotate') : ui.rotateArmed ? t('heroRotateConfirm') : t('heroRotate'));
|
|
394
|
+
setClass(rotateButton, 'is-armed', ui.rotateArmed);
|
|
395
|
+
const rotateTitle = ephemeral ? t('rotateEphemeral') : '';
|
|
396
|
+
if (rotateButton.title !== rotateTitle) rotateButton.title = rotateTitle;
|
|
397
|
+
|
|
398
|
+
tunnel.update(phase);
|
|
399
|
+
ticket.update(state);
|
|
400
|
+
|
|
401
|
+
const command = pairing && typeof pairing.command === 'string' ? pairing.command : '';
|
|
402
|
+
syncSignature(stepCommandSlot, command || 'empty', () => (command
|
|
403
|
+
? [codeBlock({ text: command, t, testid: 'step-command' })]
|
|
404
|
+
: [h('p', { class: 'code-empty' }, t('commandEmpty'))]));
|
|
405
|
+
const localPort = pairing && Number.isFinite(Number(pairing.localPort)) ? Number(pairing.localPort) : 18_080;
|
|
406
|
+
if (pairing && typeof pairing.address === 'string' && pairing.address !== '') {
|
|
407
|
+
const localUrl = `http://127.0.0.1:${localPort}/`;
|
|
408
|
+
syncSignature(stepLocalSlot, localUrl, () => [codeBlock({ text: localUrl, t, testid: 'step-local-url' })]);
|
|
409
|
+
} else {
|
|
410
|
+
syncSignature(stepLocalSlot, 'empty', () => []);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
update(ctx.state());
|
|
415
|
+
return {
|
|
416
|
+
el,
|
|
417
|
+
update,
|
|
418
|
+
dispose() {
|
|
419
|
+
if (rotateTimer !== null) clearTimeout(rotateTimer);
|
|
420
|
+
rotateTimer = null;
|
|
421
|
+
tunnel.dispose();
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* @param {object | null} state - snapshot.
|
|
428
|
+
* @returns {boolean} whether the interface should point at the installer.
|
|
429
|
+
*/
|
|
430
|
+
function programMissing(state) {
|
|
431
|
+
const installer = installerOf(state);
|
|
432
|
+
if (installer.installed === true) return false;
|
|
433
|
+
const system = installer.system && typeof installer.system === 'object' ? installer.system : {};
|
|
434
|
+
if (system.status === 'found') return false;
|
|
435
|
+
const binary = tailcatOf(state).binary && typeof tailcatOf(state).binary === 'object' ? tailcatOf(state).binary : {};
|
|
436
|
+
if (binary.resolved) return false;
|
|
437
|
+
return system.status === 'missing';
|
|
438
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room: settings.
|
|
3
|
+
*
|
|
4
|
+
* Five independent drawers. Each one keeps its own draft and its own save bar,
|
|
5
|
+
* so a failed save in one drawer never throws away edits in another.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { h } from './components.js';
|
|
9
|
+
import { createTunnelDrawer } from './drawer-tunnel.js';
|
|
10
|
+
import { createRelayDrawer } from './drawer-relay.js';
|
|
11
|
+
import { createAddressDrawer } from './drawer-address.js';
|
|
12
|
+
import { createAccessDrawer } from './drawer-access.js';
|
|
13
|
+
import { createAutomationDrawer } from './drawer-automation.js';
|
|
14
|
+
|
|
15
|
+
const FACTORIES = [
|
|
16
|
+
['tunnel', createTunnelDrawer],
|
|
17
|
+
['relay', createRelayDrawer],
|
|
18
|
+
['address', createAddressDrawer],
|
|
19
|
+
['access', createAccessDrawer],
|
|
20
|
+
['automation', createAutomationDrawer],
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} ctx - shell context.
|
|
25
|
+
* @returns {{ el: HTMLElement, update: (state: object | null) => void, openDrawer: (id: string, options?: { focus?: boolean }) => boolean }} room.
|
|
26
|
+
*/
|
|
27
|
+
export function createSettingsRoom(ctx) {
|
|
28
|
+
const t = ctx.t;
|
|
29
|
+
const drawers = FACTORIES.map(([id, factory]) => ({ id, ...factory(ctx) }));
|
|
30
|
+
const byId = new Map(drawers.map((drawer) => [drawer.id, drawer]));
|
|
31
|
+
|
|
32
|
+
const el = h('section', {
|
|
33
|
+
class: 'room',
|
|
34
|
+
'data-testid': 'room-panel-settings',
|
|
35
|
+
id: 'room-settings',
|
|
36
|
+
role: 'tabpanel',
|
|
37
|
+
'aria-labelledby': 'tab-settings',
|
|
38
|
+
},
|
|
39
|
+
h('header', { class: 'room-head' },
|
|
40
|
+
h('h2', { class: 'room-title' }, t('settingsTitle')),
|
|
41
|
+
h('p', { class: 'room-subtitle' }, t('settingsSubtitle'))),
|
|
42
|
+
h('div', { class: 'drawers' }, drawers.map((drawer) => drawer.el)));
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} id - drawer id (tunnel/relay/address/access/automation).
|
|
46
|
+
* @param {{ focus?: boolean }} [options] - whether to move focus inside.
|
|
47
|
+
* @returns {boolean} whether the drawer exists.
|
|
48
|
+
*/
|
|
49
|
+
function openDrawer(id, options = {}) {
|
|
50
|
+
const drawer = byId.get(id);
|
|
51
|
+
if (!drawer) return false;
|
|
52
|
+
drawer.shell.setOpen(true, false);
|
|
53
|
+
if (options.focus !== false) {
|
|
54
|
+
// The room may have just become visible; focus after layout so the
|
|
55
|
+
// control scrolls into view instead of being scrolled past.
|
|
56
|
+
requestAnimationFrame(() => drawer.shell.focus(options.select));
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
el,
|
|
63
|
+
/**
|
|
64
|
+
* @param {object | null} state - latest snapshot.
|
|
65
|
+
*/
|
|
66
|
+
update(state) {
|
|
67
|
+
for (const drawer of drawers) drawer.update(state);
|
|
68
|
+
},
|
|
69
|
+
openDrawer,
|
|
70
|
+
};
|
|
71
|
+
}
|
package/web/store.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polls the local snapshot and owns every write.
|
|
3
|
+
*
|
|
4
|
+
* One store instance holds the polling state, the in-flight action, and the
|
|
5
|
+
* page-level notice. It notifies a single listener on every change; the shell
|
|
6
|
+
* decides how much DOM to update, so a 2.5s poll never rebuilds inputs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const POLL_MS = 2_500;
|
|
10
|
+
const NOTICE_MS = 5_000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Error & { code?: string }} error - action failure.
|
|
14
|
+
* @returns {Error} the same error.
|
|
15
|
+
*/
|
|
16
|
+
function markBusy(error) {
|
|
17
|
+
const busy = new Error('busy');
|
|
18
|
+
busy.code = 'busy';
|
|
19
|
+
busy.cause = error;
|
|
20
|
+
return busy;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {{ api: ReturnType<import('./api.js').createApi>, onChange: () => void, intervalMs?: number }} options - wiring.
|
|
25
|
+
* @returns {object} store with live fields plus start/stop/refresh/act/notice helpers.
|
|
26
|
+
*/
|
|
27
|
+
export function createStore({ api, onChange, intervalMs = POLL_MS }) {
|
|
28
|
+
const pollMs = Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : POLL_MS;
|
|
29
|
+
const store = {
|
|
30
|
+
/** @type {object | null} latest snapshot */
|
|
31
|
+
snapshot: null,
|
|
32
|
+
/** @type {Error | null} last read failure while a snapshot is already known */
|
|
33
|
+
error: null,
|
|
34
|
+
/** @type {string | null} action currently running */
|
|
35
|
+
busy: null,
|
|
36
|
+
/** @type {{ id: number, kind: 'ok' | 'error' | 'info', text: string } | null} page notice */
|
|
37
|
+
notice: null,
|
|
38
|
+
/** @type {number} when the last successful write landed */
|
|
39
|
+
lastMutationAt: 0,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let disposed = false;
|
|
43
|
+
let timer = null;
|
|
44
|
+
let noticeTimer = null;
|
|
45
|
+
let reading = false;
|
|
46
|
+
let noticeId = 0;
|
|
47
|
+
|
|
48
|
+
function emit() {
|
|
49
|
+
if (!disposed) onChange();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function clearNoticeTimer() {
|
|
53
|
+
if (noticeTimer !== null) {
|
|
54
|
+
clearTimeout(noticeTimer);
|
|
55
|
+
noticeTimer = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function dismissNotice() {
|
|
60
|
+
if (store.notice === null) return;
|
|
61
|
+
store.notice = null;
|
|
62
|
+
clearNoticeTimer();
|
|
63
|
+
emit();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Show one page-level notice; a newer notice replaces the previous one.
|
|
68
|
+
* @param {'ok' | 'error' | 'info'} kind - tone.
|
|
69
|
+
* @param {string} text - already translated copy.
|
|
70
|
+
*/
|
|
71
|
+
function setNotice(kind, text) {
|
|
72
|
+
noticeId += 1;
|
|
73
|
+
store.notice = { id: noticeId, kind, text };
|
|
74
|
+
clearNoticeTimer();
|
|
75
|
+
noticeTimer = setTimeout(() => {
|
|
76
|
+
noticeTimer = null;
|
|
77
|
+
if (store.notice && store.notice.id === noticeId) dismissNotice();
|
|
78
|
+
}, NOTICE_MS);
|
|
79
|
+
emit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** @returns {Promise<object | null>} the new snapshot, or null on failure. */
|
|
83
|
+
async function refresh() {
|
|
84
|
+
if (disposed || reading) return null;
|
|
85
|
+
reading = true;
|
|
86
|
+
const startedAt = Date.now();
|
|
87
|
+
try {
|
|
88
|
+
const snapshot = await api.state();
|
|
89
|
+
// A write that settled after this read started owns the newer truth.
|
|
90
|
+
if (startedAt < store.lastMutationAt) return store.snapshot;
|
|
91
|
+
store.snapshot = snapshot;
|
|
92
|
+
store.error = null;
|
|
93
|
+
emit();
|
|
94
|
+
return snapshot;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
store.error = error instanceof Error ? error : new Error(String(error));
|
|
97
|
+
emit();
|
|
98
|
+
return null;
|
|
99
|
+
} finally {
|
|
100
|
+
reading = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Run one write. The response is the next full snapshot, so the page updates
|
|
106
|
+
* from it instead of waiting for the next poll.
|
|
107
|
+
* @param {string} action - action name.
|
|
108
|
+
* @param {object} [payload] - action payload.
|
|
109
|
+
* @returns {Promise<{ ok: boolean, error?: Error }>} outcome.
|
|
110
|
+
*/
|
|
111
|
+
async function act(action, payload = {}) {
|
|
112
|
+
if (store.busy !== null) return { ok: false, error: markBusy() };
|
|
113
|
+
store.busy = action;
|
|
114
|
+
emit();
|
|
115
|
+
try {
|
|
116
|
+
const snapshot = await api.action(action, payload);
|
|
117
|
+
store.snapshot = snapshot;
|
|
118
|
+
store.lastMutationAt = Date.now();
|
|
119
|
+
store.error = null;
|
|
120
|
+
return { ok: true };
|
|
121
|
+
} catch (error) {
|
|
122
|
+
return { ok: false, error: error instanceof Error ? error : new Error(String(error)) };
|
|
123
|
+
} finally {
|
|
124
|
+
store.busy = null;
|
|
125
|
+
emit();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function schedule() {
|
|
130
|
+
if (disposed) return;
|
|
131
|
+
if (timer !== null) clearTimeout(timer);
|
|
132
|
+
timer = setTimeout(async () => {
|
|
133
|
+
timer = null;
|
|
134
|
+
if (!disposed && document.visibilityState !== 'hidden') await refresh();
|
|
135
|
+
schedule();
|
|
136
|
+
}, pollMs);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function onVisibility() {
|
|
140
|
+
if (document.visibilityState === 'visible') {
|
|
141
|
+
void refresh();
|
|
142
|
+
schedule();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function start() {
|
|
147
|
+
if (disposed) return;
|
|
148
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
149
|
+
void refresh();
|
|
150
|
+
schedule();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function stop() {
|
|
154
|
+
disposed = true;
|
|
155
|
+
if (timer !== null) clearTimeout(timer);
|
|
156
|
+
timer = null;
|
|
157
|
+
clearNoticeTimer();
|
|
158
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
store.start = start;
|
|
162
|
+
store.stop = stop;
|
|
163
|
+
store.refresh = refresh;
|
|
164
|
+
store.act = act;
|
|
165
|
+
store.setNotice = setNotice;
|
|
166
|
+
store.dismissNotice = dismissNotice;
|
|
167
|
+
return store;
|
|
168
|
+
}
|