Skip to content

Commit

Permalink
Move order of restore around
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Dec 23, 2024
1 parent faf3bb2 commit 66e11bb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/panels/config/backup/dialogs/dialog-restore-backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
this._error = undefined;
this._stage = undefined;
this._step = undefined;
if (this._unsub) {
this._unsub.then((unsub) => unsub());
this._unsub = undefined;
}
window.removeEventListener("connection-status", this._connectionStatus);
this._unsubscribe();
fireEvent(this, "dialog-closed", { dialog: this.localName });
}

Expand Down Expand Up @@ -189,15 +185,16 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
}

private async _restoreBackup() {
this._unsubscribe();
try {
this._step = "progress";
window.addEventListener("connection-status", this._connectionStatus);
this._subscribeBackupEvents();
await this._doRestoreBackup(
this._userPassword || this._backupEncryptionKey
);
this._subscribeBackupEvents();
} catch (e: any) {
window.removeEventListener("connection-status", this._connectionStatus);
this._unsubscribe();
if (e.code === "password_incorrect") {
this._step = "encryption";
} else {
Expand Down Expand Up @@ -229,6 +226,14 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
});
}

private _unsubscribe() {
window.removeEventListener("connection-status", this._connectionStatus);
if (this._unsub) {
this._unsub.then((unsub) => unsub());
this._unsub = undefined;
}
}

private _restoreState() {
switch (this._stage) {
case "addon_repositories":
Expand Down

0 comments on commit 66e11bb

Please sign in to comment.