diff options
| author | Li Zhineng <[email protected]> | 2025-07-11 21:59:49 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-07-11 21:59:49 +0800 |
| commit | 6f15fb63da85f2d9d651c02f16dabd7fea33935c (patch) | |
| tree | cd6248cb4b4d2201b2205085eecc5f585a3e32fc /main.mjs | |
| parent | 0c115430faf3574ca431d318f139dbf3d48cff6c (diff) | |
| download | setup-6f15fb63da85f2d9d651c02f16dabd7fea33935c.tar.gz setup-6f15fb63da85f2d9d651c02f16dabd7fea33935c.zip | |
retry option
Diffstat (limited to 'main.mjs')
| -rw-r--r-- | main.mjs | 43 |
1 files changed, 41 insertions, 2 deletions
@@ -306,12 +306,31 @@ class CommunicationForm extends Form { #failureForm = null #wifiCredentials = null + #retryMessage = null + #retryMessageClassName = 'retry-message' + #retryMessageShownClassName = 'retry-message--shown' + + #retryLink = null + #retryLinkClassName = `retry-link` + constructor(id, device) { super(id) this.#device = device + this.#retryMessage = this.form.querySelector(`.${this.#retryMessageClassName}`) + if (this.#retryMessage) { + this.#retryLink = this.form.querySelector(`.${this.#retryLinkClassName}`) + this.#retryLink.addEventListener('click', () => { + this.hideRetryOption() + this.startPairing() + }) + } } - async onDisplay() { + onDisplay() { + this.startPairing() + } + + async startPairing() { if (this.#device === null) { return } @@ -320,7 +339,11 @@ class CommunicationForm extends Form { return } - await this.connect(this.#device, this.wifiCredentials) + try { + await this.connect(this.#device, this.wifiCredentials) + } catch { + this.showRetryOption() + } } async connect() { @@ -353,6 +376,22 @@ class CommunicationForm extends Form { console.log(`Received data from device: ${receivedBytes.join(' ')}`) } + showRetryOption() { + if (this.#retryMessage === null) { + return + } + + this.#retryMessage.classList.add(this.#retryMessageShownClassName) + } + + hideRetryOption() { + if (this.#retryMessage === null) { + return + } + + this.#retryMessage.classList.remove(this.#retryMessageShownClassName) + } + succeedTo(form) { this.#successForm = form return this |
