From 6e2976c22993af7debd8ed3aec1192224254542d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 10 Nov 2021 20:35:15 -0800 Subject: [PATCH] Allow resetting data when firmware and version are the same (#103) --- src/install-dialog.ts | 71 ++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/src/install-dialog.ts b/src/install-dialog.ts index c759e1c3..4970e0e1 100644 --- a/src/install-dialog.ts +++ b/src/install-dialog.ts @@ -157,15 +157,23 @@ class EwtInstallDialog extends LitElement { let hideActions = true; let allowClosing = true; - const isSameFirmware = this._info!.firmware === this._manifest!.name; - const isSameVersion = - isSameFirmware && this._info!.version === this._manifest!.version; - content = html`
${this._info!.firmware} ${this._info!.version}
+ ${!this._isSameVersion + ? html` +
+ this._startInstall(!this._isSameFirmware)} + > +
+ ` + : ""} ${this._client!.nextUrl === undefined ? "" : html` @@ -208,17 +216,6 @@ class EwtInstallDialog extends LitElement { }} >
-
- this._startInstall(!isSameFirmware)} - .disabled=${isSameVersion} - > -
+ ${this._isSameVersion + ? html` +
+ this._startInstall(true)} + > +
+ ` + : ""} `; @@ -362,9 +370,21 @@ class EwtInstallDialog extends LitElement { let hideActions = false; let allowClosing = false; - const isUpdate = !this._installErase && this._isUpdate; + const isUpdate = !this._installErase && this._isSameFirmware; - if (!this._installConfirmed) { + if (!this._installConfirmed && this._isSameVersion) { + heading = "Reset data"; + content = html` + Do you want to reset your device and erase all existing data from your + device? + + `; + } else if (!this._installConfirmed) { const action = isUpdate ? "update to" : "install"; content = html` ${isUpdate @@ -657,10 +677,22 @@ class EwtInstallDialog extends LitElement { this.parentNode!.removeChild(this); } - private get _isUpdate() { + /** + * Return if the device runs same firmware as manifest. + */ + private get _isSameFirmware() { return this._info?.firmware === this._manifest!.name; } + /** + * Return if the device runs same firmware and version as manifest. + */ + private get _isSameVersion() { + return ( + this._isSameFirmware && this._info!.version === this._manifest!.version + ); + } + private async _closeClientWithoutEvents(client: ImprovSerial) { client.removeEventListener("disconnect", this._handleDisconnect); await client.close(); @@ -714,6 +746,9 @@ class EwtInstallDialog extends LitElement { .error { color: #db4437; } + .danger { + --mdc-theme-primary: #db4437; + } button.link { background: none; color: inherit;