@improv-wifi/serial-sdk 0.0.0-stage → 2.10.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.
@@ -0,0 +1,691 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html, css, nothing, svg, } from "lit";
3
+ import { customElement, query, property, state } from "lit/decorators.js";
4
+ import "@material/web/dialog/dialog.js";
5
+ import "@material/web/iconbutton/filled-tonal-icon-button.js";
6
+ import "@material/web/iconbutton/icon-button.js";
7
+ import "@material/web/textfield/outlined-text-field.js";
8
+ import "@material/web/button/outlined-button.js";
9
+ import "@material/web/button/filled-button.js";
10
+ import "@material/web/progress/circular-progress.js";
11
+ import "@material/web/select/outlined-select.js";
12
+ import "@material/web/select/select-option.js";
13
+ import "@material/web/list/list.js";
14
+ import "@material/web/list/list-item.js";
15
+ import { ImprovSerialCurrentState, } from "./const.js";
16
+ import { ImprovSerial } from "./serial.js";
17
+ import { fireEvent } from "./util/fire-event";
18
+ const ERROR_ICON = "⚠️";
19
+ const OK_ICON = "🎉";
20
+ const infoIcon = svg `
21
+ <svg viewBox="0 -960 960 960" width="24px">
22
+ <path
23
+ fill="currentColor"
24
+ d="M440-280h80v-240h-80v240Zm40-320q17 0 28.5-11.5T520-640q0-17-11.5-28.5T480-680q-17 0-28.5 11.5T440-640q0 17 11.5 28.5T480-600Zm0 520q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"
25
+ />
26
+ </svg>
27
+ `;
28
+ const wifiIcon = svg `
29
+ <svg viewBox="0 -960 960 960">
30
+ <path
31
+ fill="currentColor"
32
+ d="M480-120q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM254-346l-84-86q59-59 138.5-93.5T480-560q92 0 171.5 35T790-430l-84 84q-44-44-102-69t-124-25q-66 0-124 25t-102 69ZM84-516 0-600q92-94 215-147t265-53q142 0 265 53t215 147l-84 84q-77-77-178.5-120.5T480-680q-116 0-217.5 43.5T84-516Z"
33
+ />
34
+ </svg>
35
+ `;
36
+ const networkWifiFull = svg `
37
+ <svg viewBox="0 -960 960 960" width="24px">
38
+ <path
39
+ fill="currentColor"
40
+ d="M480-120 0-600q95-97 219.5-148.5T480-800q137 0 261 51t219 149L480-120ZM174-540q67-48 145-74t161-26q83 0 161 26t145 74l58-58q-79-60-172-91t-192-31q-99 0-192 31t-172 91l58 58Z"
41
+ />
42
+ </svg>
43
+ `;
44
+ const networkWifi3Bar = svg `
45
+ <svg viewBox="0 -960 960 960" width="24px">
46
+ <path
47
+ fill="currentColor"
48
+ d="M480-120 0-600q96-98 220-149t260-51q137 0 261 51t219 149L480-120ZM232-482q53-38 116-59.5T480-563q69 0 132 21.5T728-482l116-116q-78-59-170.5-90.5T480-720q-101 0-193.5 31.5T116-598l116 116Z"
49
+ />
50
+ </svg>
51
+ `;
52
+ const networkWifi2Bar = svg `
53
+ <svg viewBox="0 -960 960 960" width="24px">
54
+ <path
55
+ fill="currentColor"
56
+ d="M480-120 0-600q96-98 220-149t260-51q137 0 261 51t219 149L480-120ZM299-415q38-28 84-43.5t97-15.5q51 0 97 15.5t84 43.5l183-183q-78-59-170.5-90.5T480-720q-101 0-193.5 31.5T116-598l183 183Z"
57
+ />
58
+ </svg>
59
+ `;
60
+ const networkWifi1Bar = svg `
61
+ <svg viewBox="0 -960 960 960" width="24px">
62
+ <path
63
+ fill="currentColor"
64
+ d="M480-120 0-600q96-98 220-149t260-51q137 0 261 51t219 149L480-120ZM361-353q25-18 55.5-28t63.5-10q33 0 63.5 10t55.5 28l245-245q-78-59-170.5-90.5T480-720q-101 0-193.5 31.5T116-598l245 245Z"
65
+ />
66
+ </svg>
67
+ `;
68
+ const lockIcon = svg `
69
+ <svg viewBox="0 -960 960 960" width="24px">
70
+ <path
71
+ fill="currentColor"
72
+ d="M240-80q-33 0-56.5-23.5T160-160v-400q0-33 23.5-56.5T240-640h40v-80q0-83 58.5-141.5T480-920q83 0 141.5 58.5T680-720v80h40q33 0 56.5 23.5T800-560v400q0 33-23.5 56.5T720-80H240Zm0-80h480v-400H240v400Zm240-120q33 0 56.5-23.5T560-360q0-33-23.5-56.5T480-440q-33 0-56.5 23.5T400-360q0 33 23.5 56.5T480-280ZM360-640h240v-80q0-50-35-85t-85-35q-50 0-85 35t-35 85v80ZM240-160v-400 400Z"
73
+ />
74
+ </svg>
75
+ `;
76
+ const lockUnlockedRightIcon = svg `
77
+ <svg viewBox="0 -960 960 960" width="24px">
78
+ <path
79
+ fill="currentColor"
80
+ d="M240-160h480v-400H240v400Zm240-120q33 0 56.5-23.5T560-360q0-33-23.5-56.5T480-440q-33 0-56.5 23.5T400-360q0 33 23.5 56.5T480-280ZM240-160v-400 400Zm0 80q-33 0-56.5-23.5T160-160v-400q0-33 23.5-56.5T240-640h280v-80q0-83 58.5-141.5T720-920q83 0 141.5 58.5T920-720h-80q0-50-35-85t-85-35q-50 0-85 35t-35 85v80h120q33 0 56.5 23.5T800-560v400q0 33-23.5 56.5T720-80H240Z"
81
+ />
82
+ </svg>
83
+ `;
84
+ const visibilityIcon = svg `
85
+ <svg viewBox="0 -960 960 960">
86
+ <path
87
+ fill="currentColor"
88
+ d="M480-320q75 0 127.5-52.5T660-500q0-75-52.5-127.5T480-680q-75 0-127.5 52.5T300-500q0 75 52.5 127.5T480-320Zm0-72q-45 0-76.5-31.5T372-500q0-45 31.5-76.5T480-608q45 0 76.5 31.5T588-500q0 45-31.5 76.5T480-392Zm0 192q-146 0-266-81.5T40-500q54-137 174-218.5T480-800q146 0 266 81.5T920-500q-54 137-174 218.5T480-200Zm0-300Zm0 220q113 0 207.5-59.5T832-500q-50-101-144.5-160.5T480-720q-113 0-207.5 59.5T128-500q50 101 144.5 160.5T480-280Z"
89
+ />
90
+ </svg>
91
+ `;
92
+ const visibilityOffIcon = svg `
93
+ <svg viewBox="0 -960 960 960">
94
+ <path
95
+ fill="currentColor"
96
+ d="m644-428-58-58q9-47-27-88t-93-32l-58-58q17-8 34.5-12t37.5-4q75 0 127.5 52.5T660-500q0 20-4 37.5T644-428Zm128 126-58-56q38-29 67.5-63.5T832-500q-50-101-143.5-160.5T480-720q-29 0-57 4t-55 12l-62-62q41-17 84-25.5t90-8.5q151 0 269 83.5T920-500q-23 59-60.5 109.5T772-302Zm20 246L624-222q-35 11-70.5 16.5T480-200q-151 0-269-83.5T40-500q21-53 53-98.5t73-81.5L56-792l56-56 736 736-56 56ZM222-624q-29 26-53 57t-41 67q50 101 143.5 160.5T480-280q20 0 39-2.5t39-5.5l-36-38q-11 3-21 4.5t-21 1.5q-75 0-127.5-52.5T300-500q0-11 1.5-21t4.5-21l-84-82Zm319 93Zm-151 75Z"
97
+ />
98
+ </svg>
99
+ `;
100
+ /** Name of the network with the strongest signal, null if there are none. */
101
+ function strongestSsid(networks) {
102
+ return networks.length
103
+ ? networks.reduce((best, ssid) => (ssid.rssi > best.rssi ? ssid : best))
104
+ .name
105
+ : null;
106
+ }
107
+ function getWifiIcon(rssi) {
108
+ if (rssi >= -50)
109
+ return networkWifiFull;
110
+ if (rssi >= -60)
111
+ return networkWifi3Bar;
112
+ if (rssi >= -70)
113
+ return networkWifi2Bar;
114
+ return networkWifi1Bar;
115
+ }
116
+ function getSignalStrengthClass(rssi) {
117
+ if (rssi >= -50)
118
+ return "signal-excellent";
119
+ if (rssi >= -60)
120
+ return "signal-good";
121
+ if (rssi >= -70)
122
+ return "signal-fair";
123
+ return "signal-weak";
124
+ }
125
+ let SerialProvisionDialog = class SerialProvisionDialog extends LitElement {
126
+ constructor() {
127
+ super(...arguments);
128
+ this.logger = console;
129
+ this._state = "CONNECTING";
130
+ this._busy = false;
131
+ this._selectedSsid = null;
132
+ this._showPassword = false;
133
+ // Show the configure form while already provisioned, to change the network.
134
+ this._reprovision = false;
135
+ }
136
+ render() {
137
+ var _a, _b, _c;
138
+ var _d;
139
+ if (!this.port) {
140
+ return html ``;
141
+ }
142
+ let heading = html `${(_d = (_b = (_a = this._client) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.name) !== null && _d !== void 0 ? _d : nothing}`;
143
+ let content;
144
+ let actions;
145
+ if (this._state === "CONNECTING" || !this._client) {
146
+ content = this._renderProgress("Connecting");
147
+ }
148
+ else if (this._state === "ERROR") {
149
+ content = this._renderMessage(ERROR_ICON, `An error occurred. ${this._error}`);
150
+ actions = this._renderCloseAction();
151
+ }
152
+ else if (this._client.state === ImprovSerialCurrentState.STOPPED) {
153
+ content = this._renderMessage(ERROR_ICON, "The connected device has Wi-Fi turned off, so it can't be configured right now. Enable the device's Wi-Fi, then try again.");
154
+ actions = this._renderCloseAction();
155
+ }
156
+ else if (this._showConfigureForm) {
157
+ if (this._busy) {
158
+ content = this._renderProgress("Provisioning");
159
+ }
160
+ else {
161
+ heading = html `<md-filled-tonal-icon-button
162
+ >${wifiIcon}</md-filled-tonal-icon-button
163
+ >Configure Wi-Fi`;
164
+ if (this._ssids === undefined) {
165
+ content = this._renderProgress("Searching for networks");
166
+ }
167
+ else {
168
+ content = this._renderImprovReady();
169
+ actions = html `${this._renderCloseAction()}
170
+ <md-filled-button @click=${this._provision}
171
+ >Connect</md-filled-button
172
+ > `;
173
+ }
174
+ }
175
+ }
176
+ else if (this._client.state === ImprovSerialCurrentState.PROVISIONING) {
177
+ content = this._renderProgress("Provisioning");
178
+ }
179
+ else if (this._client.state === ImprovSerialCurrentState.PROVISIONED) {
180
+ content = html `
181
+ ${((_c = this._client) === null || _c === void 0 ? void 0 : _c.info) ? this._renderDeviceInfo() : nothing}
182
+ <div class="center">
183
+ <div class="icon">${OK_ICON}</div>
184
+ Provisioned!
185
+ </div>
186
+ `;
187
+ actions = html `${this._renderCloseAction()}
188
+ <md-outlined-button @click=${this._changeWifi}
189
+ >Change Wi-Fi</md-outlined-button
190
+ >
191
+ ${this._client.nextUrl === undefined
192
+ ? nothing
193
+ : html `<md-filled-button
194
+ href=${this._client.nextUrl}
195
+ form="improv-form"
196
+ >Visit Device</md-filled-button
197
+ >`}`;
198
+ }
199
+ else {
200
+ content = this._renderMessage(ERROR_ICON, `Unexpected state: ${this._state} - ${this._client.state}`);
201
+ actions = this._renderCloseAction();
202
+ }
203
+ return html `
204
+ <md-dialog open @close=${this._handleClose}>
205
+ <div slot="headline">${heading}</div>
206
+ <form slot="content" id="improv-form" method="dialog">${content}</form>
207
+ ${actions ? html `<div slot="actions">${actions}</div>` : nothing}
208
+ </md-dialog>
209
+ `;
210
+ }
211
+ _renderCloseAction() {
212
+ return html `<md-outlined-button
213
+ form="improv-form"
214
+ @click=${this._handleClose}
215
+ >Close</md-outlined-button
216
+ >`;
217
+ }
218
+ _renderProgress(label) {
219
+ return html `
220
+ <div class="center">
221
+ <div>
222
+ <md-circular-progress indeterminate></md-circular-progress>
223
+ </div>
224
+ ${label}
225
+ </div>
226
+ `;
227
+ }
228
+ _renderMessage(icon, label) {
229
+ return html `
230
+ <div class="center">
231
+ <div class="icon">${icon}</div>
232
+ ${label}
233
+ </div>
234
+ `;
235
+ }
236
+ _renderImprovReady() {
237
+ var _a, _b;
238
+ let error;
239
+ switch (this._client.error) {
240
+ case 3 /* ImprovSerialErrorState.UNABLE_TO_CONNECT */:
241
+ error = "Unable to connect";
242
+ break;
243
+ case 0 /* ImprovSerialErrorState.NO_ERROR */:
244
+ break;
245
+ // Happens after scanning for networks if device
246
+ // doesn't support the command.
247
+ case 2 /* ImprovSerialErrorState.UNKNOWN_RPC_COMMAND */:
248
+ if (this._ssids !== null) {
249
+ error = `Unknown RPC command`;
250
+ }
251
+ break;
252
+ case 254 /* ImprovSerialErrorState.TIMEOUT */:
253
+ error = `Timeout`;
254
+ break;
255
+ default:
256
+ error = `Unknown error (${this._client.error})`;
257
+ }
258
+ const selectedSsid = (_a = this._ssids) === null || _a === void 0 ? void 0 : _a.find((info) => info.name === this._selectedSsid);
259
+ return html `
260
+ ${((_b = this._client) === null || _b === void 0 ? void 0 : _b.info) ? this._renderDeviceInfo() : nothing}
261
+ <div>
262
+ Enter credentials of the Wi-Fi network that you want your device to
263
+ connect to.
264
+ </div>
265
+ ${error ? html `<p class="error">${error}</p>` : nothing}
266
+ ${this._ssids !== null
267
+ ? html `
268
+ <md-outlined-select
269
+ name="ssid_select"
270
+ required
271
+ label="Network"
272
+ @change=${(ev) => {
273
+ const index = ev.target.selectedIndex;
274
+ // The "Join Other" item is always the last item.
275
+ this._selectedSsid =
276
+ index === this._ssids.length
277
+ ? null
278
+ : this._ssids[index].name;
279
+ }}
280
+ @closed=${(ev) => ev.stopPropagation()}
281
+ >
282
+ ${this._ssids.map((info, idx) => html `
283
+ <md-select-option
284
+ .selected=${selectedSsid === info}
285
+ value=${idx}
286
+ >
287
+ <span
288
+ slot="start"
289
+ class=${getSignalStrengthClass(info.rssi)}
290
+ >${getWifiIcon(info.rssi)}</span
291
+ >
292
+ <span slot="headline">${info.name}</span>
293
+ <span slot="end" class="network-details">
294
+ <span class="signal-strength">${info.rssi}dB</span>
295
+ <span
296
+ class="lock-icon ${info.secured ? "lock-secured" : "lock-unsecured"}"
297
+ >${info.secured ? lockIcon : lockUnlockedRightIcon}</span
298
+ >
299
+ </span>
300
+ </md-select-option>
301
+ `)}
302
+ <md-select-option .selected=${!selectedSsid} value="-1">
303
+ Join other…
304
+ </md-select-option>
305
+ </md-outlined-select>
306
+ `
307
+ : nothing}
308
+ ${
309
+ // Show input box if no wifi networks found or "Join Other" selected
310
+ this._selectedSsid === null
311
+ ? html `
312
+ <md-outlined-text-field
313
+ required
314
+ label="Network Name"
315
+ name="ssid"
316
+ ></md-outlined-text-field>
317
+ `
318
+ : nothing}
319
+ ${
320
+ // Show password if custom SSID or needs password
321
+ !selectedSsid || selectedSsid.secured
322
+ ? html `
323
+ <md-outlined-text-field
324
+ required
325
+ label="Password"
326
+ name="password"
327
+ type=${this._showPassword ? "text" : "password"}
328
+ @keydown=${(ev) => {
329
+ if (ev.key === "Enter") {
330
+ this._provision();
331
+ }
332
+ }}
333
+ >
334
+ <md-icon-button
335
+ slot="trailing-icon"
336
+ @click=${this._togglePasswordVisibility}
337
+ toggle
338
+ .selected=${this._showPassword}
339
+ >
340
+ ${this._showPassword ? visibilityOffIcon : visibilityIcon}
341
+ </md-icon-button>
342
+ </md-outlined-text-field>
343
+ `
344
+ : nothing}
345
+ `;
346
+ }
347
+ _renderDeviceInfo() {
348
+ return html `<div class="device-info">
349
+ <div>${infoIcon}Device Info</div>
350
+ <div>Name<span>${this._client.info.name}</span></div>
351
+ <div>Firmware<span>${this._client.info.firmware}</span></div>
352
+ <div>Version<span>${this._client.info.version}</span></div>
353
+ <div>Chip<span>${this._client.info.chipFamily}</span></div>
354
+ ${this._client.info.osName
355
+ ? html `<div>OS<span>${this._client.info.osName}</span></div>`
356
+ : nothing}
357
+ ${this._client.info.osVersion
358
+ ? html `<div>
359
+ OS Version<span>${this._client.info.osVersion}</span>
360
+ </div>`
361
+ : nothing}
362
+ </div>`;
363
+ }
364
+ _togglePasswordVisibility(event) {
365
+ event.preventDefault();
366
+ event.stopPropagation();
367
+ this._showPassword = !this._showPassword;
368
+ }
369
+ // Whether the network configuration form is the active view.
370
+ get _showConfigureForm() {
371
+ var _a, _b;
372
+ return (((_a = this._client) === null || _a === void 0 ? void 0 : _a.state) === ImprovSerialCurrentState.READY ||
373
+ (((_b = this._client) === null || _b === void 0 ? void 0 : _b.state) === ImprovSerialCurrentState.PROVISIONED &&
374
+ this._reprovision));
375
+ }
376
+ // Scan while (and only while) the configure form is shown. Driven from
377
+ // `updated()`, so entering the form starts scanning and leaving it stops.
378
+ _syncScanning() {
379
+ const shouldScan = this._state === "IMPROV-STATE" && !this._busy && this._showConfigureForm;
380
+ if (shouldScan === !!this._unsubSSIDs) {
381
+ return;
382
+ }
383
+ if (shouldScan) {
384
+ this._unsubSSIDs = this._client.subscribeSSIDs((networks) => {
385
+ if (networks === null) {
386
+ // Scanning isn't available; fall back to manual network entry.
387
+ this._selectedSsid = null;
388
+ }
389
+ else if (this._ssids == null) {
390
+ // First result: default to the network with the strongest signal.
391
+ this._selectedSsid = strongestSsid(networks);
392
+ }
393
+ else if (this._selectedSsid !== null &&
394
+ !networks.some((s) => s.name === this._selectedSsid)) {
395
+ // A merged scan never drops networks, but the selection persists
396
+ // across scan restarts (after a failed provision, or reopening to
397
+ // change Wi-Fi), and the first fresh scan may not include it yet.
398
+ // Re-default when that happens; keep "Join other" (null) as-is.
399
+ this._selectedSsid = strongestSsid(networks);
400
+ }
401
+ this._ssids = networks;
402
+ });
403
+ }
404
+ else {
405
+ this._stopScanning();
406
+ }
407
+ }
408
+ async _stopScanning() {
409
+ if (!this._unsubSSIDs) {
410
+ return;
411
+ }
412
+ const unsubscribe = this._unsubSSIDs;
413
+ this._unsubSSIDs = undefined;
414
+ await unsubscribe();
415
+ }
416
+ async _provision() {
417
+ var _a;
418
+ // Read the form before setting `_busy`: that swaps the form for a progress
419
+ // view, and the render happens during any await below — after which the
420
+ // fields no longer exist and we'd provision with an empty password.
421
+ const ssid = this._selectedSsid === null ? this._inputSSID.value : this._selectedSsid;
422
+ const password = ((_a = this._inputPassword) === null || _a === void 0 ? void 0 : _a.value) || "";
423
+ this._busy = true;
424
+ // Wait for any in-flight scan to settle before provisioning so we don't
425
+ // have two RPC commands in flight at once. Marking busy above already tells
426
+ // `_syncScanning` to stop, but the provision RPC needs it stopped *now*.
427
+ await this._stopScanning();
428
+ try {
429
+ await this._client.provision(ssid, password,
430
+ // Devices try to connect for ~30s before reporting failure. Our
431
+ // timeout must comfortably exceed that: it's only a safety net, and if
432
+ // it fires first the device's late failure packet rejects the *next*
433
+ // RPC we send (the resumed network scan) instead of this one.
434
+ 45000);
435
+ // Success: leave the change-Wi-Fi form and show the provisioned screen.
436
+ this._reprovision = false;
437
+ }
438
+ catch (err) {
439
+ // No need to do error handling because we listen for `error-changed`
440
+ // events. Clearing busy resumes scanning via `_syncScanning`.
441
+ console.log(err);
442
+ }
443
+ finally {
444
+ this._busy = false;
445
+ }
446
+ }
447
+ _changeWifi() {
448
+ this._reprovision = true;
449
+ }
450
+ updated(changedProps) {
451
+ super.updated(changedProps);
452
+ if (changedProps.has("port") && this.port) {
453
+ this._connect();
454
+ }
455
+ this._syncScanning();
456
+ let toFocus;
457
+ if (changedProps.has("_ssids") &&
458
+ changedProps.get("_ssids") === undefined &&
459
+ this._ssids != null) {
460
+ // Only focus on the first result, not on every background scan update.
461
+ toFocus = this._selectSSID;
462
+ }
463
+ else if (changedProps.has("_selectedSsid") &&
464
+ this._selectedSsid === null) {
465
+ toFocus = this._inputSSID;
466
+ }
467
+ if (toFocus) {
468
+ toFocus.updateComplete.then(() => toFocus.focus());
469
+ }
470
+ }
471
+ async _connect() {
472
+ let client;
473
+ try {
474
+ client = new ImprovSerial(this.port, this.logger);
475
+ }
476
+ catch (err) {
477
+ this._state = "ERROR";
478
+ this._error = err.message || err || "Unknown error";
479
+ return;
480
+ }
481
+ client.addEventListener("state-changed", () => {
482
+ this._state = "IMPROV-STATE";
483
+ this.requestUpdate();
484
+ });
485
+ client.addEventListener("error-changed", () => this.requestUpdate());
486
+ try {
487
+ await client.initialize(10000);
488
+ }
489
+ catch (err) {
490
+ this._state = "ERROR";
491
+ this._error = this.learnMoreUrl
492
+ ? html `
493
+ Unable to detect Improv service on connected device.
494
+ <a href=${this.learnMoreUrl} target="_blank"
495
+ >Learn how to resolve this</a
496
+ >
497
+ `
498
+ : err.message;
499
+ return;
500
+ }
501
+ client.addEventListener("disconnect", () => {
502
+ this._state = "ERROR";
503
+ this._error = "Disconnected";
504
+ });
505
+ if (client.nextUrl) {
506
+ this.requestUpdate();
507
+ }
508
+ this._client = client;
509
+ // Scanning starts from `_syncScanning` once the configure form is shown.
510
+ }
511
+ async _handleClose() {
512
+ const eventData = {
513
+ improv: false,
514
+ provisioned: false,
515
+ };
516
+ if (this._client) {
517
+ eventData.improv = true;
518
+ eventData.provisioned =
519
+ this._client.state === ImprovSerialCurrentState.PROVISIONED;
520
+ await this._client.close();
521
+ this._client = undefined;
522
+ }
523
+ fireEvent(this, "closed", eventData);
524
+ this.parentNode.removeChild(this);
525
+ }
526
+ disconnectedCallback() {
527
+ super.disconnectedCallback();
528
+ // Stop scanning when the dialog goes away. Not awaited: closing the client
529
+ // cancels the reader, which may leave the in-flight scan unsettled.
530
+ this._stopScanning();
531
+ }
532
+ };
533
+ SerialProvisionDialog.styles = css `
534
+ :host {
535
+ --md-dialog-max-width: 390px;
536
+ --md-dialog-container-max-block-size: none !important;
537
+ --md-sys-color-primary: var(--improv-primary-color, #03a9f4);
538
+ --md-sys-color-on-primary: var(--improv-on-primary-color, #fff);
539
+ --md-ref-typeface-brand: system-ui, sans-serif;
540
+ --md-ref-typeface-plain: system-ui, sans-serif;
541
+ font-family: system-ui, sans-serif;
542
+ }
543
+
544
+ md-dialog {
545
+ --md-dialog-container-color: var(--improv-container-color, #fff);
546
+ --md-dialog-container-max-block-size: none !important;
547
+ max-height: 90vh !important;
548
+ }
549
+
550
+ md-dialog [slot="content"],
551
+ form[slot="content"] {
552
+ overflow: visible !important;
553
+ max-height: none !important;
554
+ }
555
+
556
+ md-outlined-text-field,
557
+ md-outlined-select {
558
+ display: block;
559
+ margin-top: 16px;
560
+ }
561
+
562
+ .center {
563
+ text-align: center;
564
+ }
565
+
566
+ md-circular-progress {
567
+ margin-bottom: 16px;
568
+ }
569
+
570
+ a.has-button {
571
+ text-decoration: none;
572
+ }
573
+
574
+ .icon {
575
+ font-size: 50px;
576
+ line-height: 80px;
577
+ color: black;
578
+ }
579
+
580
+ .error {
581
+ color: #db4437;
582
+ }
583
+
584
+ .device-info {
585
+ margin-bottom: 16px;
586
+ padding: 16px;
587
+ background-color: #d6d6d6;
588
+ border-radius: 8px;
589
+ border: 1px solid #676767;
590
+ }
591
+
592
+ .device-info > div:first-child {
593
+ justify-content: flex-start;
594
+ align-items: center;
595
+ gap: 8px;
596
+ }
597
+
598
+ .device-info > div {
599
+ display: flex;
600
+ color: #5f6368;
601
+ justify-content: space-between;
602
+ }
603
+
604
+ .device-info > div > span {
605
+ color: #1f1f1f;
606
+ }
607
+
608
+ md-select-option[value="-1"] {
609
+ border-top: 1px solid #ccc;
610
+ }
611
+ md-outlined-select[name="ssid_select"] {
612
+ width: 100%;
613
+ }
614
+
615
+ .network-details {
616
+ display: flex;
617
+ align-items: center;
618
+ gap: 4px;
619
+ color: #5f6368;
620
+ font-size: 0.85em;
621
+ }
622
+
623
+ .signal-strength {
624
+ min-width: 45px;
625
+ text-align: right;
626
+ }
627
+
628
+ .lock-icon {
629
+ font-size: 18px;
630
+ }
631
+
632
+ .lock-secured {
633
+ color: #34a853;
634
+ }
635
+
636
+ .lock-unsecured {
637
+ color: #ea4335;
638
+ }
639
+
640
+ .signal-excellent,
641
+ .signal-good {
642
+ color: #34a853;
643
+ }
644
+
645
+ .signal-fair {
646
+ color: #fbbc04;
647
+ }
648
+
649
+ .signal-weak {
650
+ color: #ea4335;
651
+ }
652
+ `;
653
+ __decorate([
654
+ property()
655
+ ], SerialProvisionDialog.prototype, "port", void 0);
656
+ __decorate([
657
+ state()
658
+ ], SerialProvisionDialog.prototype, "_state", void 0);
659
+ __decorate([
660
+ state()
661
+ ], SerialProvisionDialog.prototype, "_client", void 0);
662
+ __decorate([
663
+ state()
664
+ ], SerialProvisionDialog.prototype, "_busy", void 0);
665
+ __decorate([
666
+ state()
667
+ ], SerialProvisionDialog.prototype, "_error", void 0);
668
+ __decorate([
669
+ state()
670
+ ], SerialProvisionDialog.prototype, "_selectedSsid", void 0);
671
+ __decorate([
672
+ state()
673
+ ], SerialProvisionDialog.prototype, "_ssids", void 0);
674
+ __decorate([
675
+ state()
676
+ ], SerialProvisionDialog.prototype, "_showPassword", void 0);
677
+ __decorate([
678
+ state()
679
+ ], SerialProvisionDialog.prototype, "_reprovision", void 0);
680
+ __decorate([
681
+ query("md-outlined-select")
682
+ ], SerialProvisionDialog.prototype, "_selectSSID", void 0);
683
+ __decorate([
684
+ query("md-outlined-text-field[name=ssid]")
685
+ ], SerialProvisionDialog.prototype, "_inputSSID", void 0);
686
+ __decorate([
687
+ query("md-outlined-text-field[name=password]")
688
+ ], SerialProvisionDialog.prototype, "_inputPassword", void 0);
689
+ SerialProvisionDialog = __decorate([
690
+ customElement("improv-wifi-serial-provision-dialog")
691
+ ], SerialProvisionDialog);