mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-01 13:37:47 +00:00
Better event handling
This commit is contained in:
parent
4e3fbc1169
commit
5829660894
@ -168,13 +168,6 @@ export class HassioUpdate extends LitElement {
|
||||
homeassistant: true,
|
||||
},
|
||||
updateHandler: async () => this._updateCore(),
|
||||
applyingUpdate: () => {
|
||||
fireEvent(this, "supervisor-applying-update", {
|
||||
type: "core",
|
||||
name: "Home Assistant Core",
|
||||
version: this.supervisor.core.version_latest,
|
||||
});
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import "@material/mwc-button/mwc-button";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { LocalStorage } from "../../../../src/common/decorators/local-storage";
|
||||
import { fireEvent } from "../../../../src/common/dom/fire_event";
|
||||
import "../../../../src/components/ha-circular-progress";
|
||||
import "../../../../src/components/ha-dialog";
|
||||
@ -17,12 +16,16 @@ import { haStyle, haStyleDialog } from "../../../../src/resources/styles";
|
||||
import type { HomeAssistant } from "../../../../src/types";
|
||||
import { SupervisorDialogSupervisorUpdateParams } from "./show-dialog-update";
|
||||
|
||||
const BLOCKING_UPDATES: string[] = ["Home Assistant Core"];
|
||||
|
||||
@customElement("dialog-supervisor-update")
|
||||
class DialogSupervisorUpdate extends LitElement {
|
||||
public hass!: HomeAssistant;
|
||||
|
||||
@state() private _opened = false;
|
||||
|
||||
@state() private _createSnapshot = true;
|
||||
|
||||
@state() private _action: "snapshot" | "update" | null = null;
|
||||
|
||||
@state() private _error?: string;
|
||||
@ -30,21 +33,24 @@ class DialogSupervisorUpdate extends LitElement {
|
||||
@state()
|
||||
private _dialogParams?: SupervisorDialogSupervisorUpdateParams;
|
||||
|
||||
@LocalStorage("snapshotBeforeUpdate", true, {
|
||||
attribute: false,
|
||||
})
|
||||
private _snapshotBeforeUpdate = true;
|
||||
|
||||
public async showDialog(
|
||||
params: SupervisorDialogSupervisorUpdateParams
|
||||
): Promise<void> {
|
||||
this._opened = true;
|
||||
this._dialogParams = params;
|
||||
this.addEventListener("supervisor-applying-update", (ev) => {
|
||||
fireEvent(
|
||||
this._dialogParams!.element,
|
||||
"supervisor-applying-update",
|
||||
ev.detail
|
||||
);
|
||||
});
|
||||
await this.updateComplete;
|
||||
}
|
||||
|
||||
public closeDialog(): void {
|
||||
this._action = null;
|
||||
this._createSnapshot = true;
|
||||
this._error = undefined;
|
||||
this._dialogParams = undefined;
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
@ -98,7 +104,7 @@ class DialogSupervisorUpdate extends LitElement {
|
||||
)}
|
||||
</span>
|
||||
<ha-switch
|
||||
.checked=${this._snapshotBeforeUpdate}
|
||||
.checked=${this._createSnapshot}
|
||||
haptic
|
||||
@click=${this._toggleSnapshot}
|
||||
>
|
||||
@ -137,11 +143,11 @@ class DialogSupervisorUpdate extends LitElement {
|
||||
}
|
||||
|
||||
private _toggleSnapshot() {
|
||||
this._snapshotBeforeUpdate = !this._snapshotBeforeUpdate;
|
||||
this._createSnapshot = !this._createSnapshot;
|
||||
}
|
||||
|
||||
private async _update() {
|
||||
if (this._snapshotBeforeUpdate) {
|
||||
if (this._createSnapshot) {
|
||||
this._action = "snapshot";
|
||||
try {
|
||||
await createHassioPartialSnapshot(
|
||||
@ -165,8 +171,11 @@ class DialogSupervisorUpdate extends LitElement {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this._dialogParams?.applyingUpdate) {
|
||||
this._dialogParams.applyingUpdate();
|
||||
if (BLOCKING_UPDATES.includes(this._dialogParams?.name)) {
|
||||
fireEvent(this, "supervisor-applying-update", {
|
||||
name: this._dialogParams!.name,
|
||||
version: this._dialogParams!.version,
|
||||
});
|
||||
}
|
||||
this.closeDialog();
|
||||
}
|
||||
|
@ -6,14 +6,15 @@ export interface SupervisorDialogSupervisorUpdateParams {
|
||||
name: string;
|
||||
version: string;
|
||||
snapshotParams: any;
|
||||
element: HTMLElement;
|
||||
updateHandler: () => Promise<void>;
|
||||
applyingUpdate?: () => void;
|
||||
}
|
||||
|
||||
export const showDialogSupervisorUpdate = (
|
||||
element: HTMLElement,
|
||||
dialogParams: SupervisorDialogSupervisorUpdateParams
|
||||
dialogParams: Partial<SupervisorDialogSupervisorUpdateParams>
|
||||
): void => {
|
||||
dialogParams.element = element;
|
||||
fireEvent(element, "show-dialog", {
|
||||
dialogTag: "dialog-supervisor-update",
|
||||
dialogImport: () => import("./dialog-supervisor-update"),
|
||||
|
@ -171,13 +171,6 @@ class HassioCoreInfo extends LitElement {
|
||||
homeassistant: true,
|
||||
},
|
||||
updateHandler: async () => this._updateCore(),
|
||||
applyingUpdate: () => {
|
||||
fireEvent(this, "supervisor-applying-update", {
|
||||
type: "core",
|
||||
name: "Home Assistant Core",
|
||||
version: this.supervisor.core.version_latest,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import {
|
||||
import { SupervisorStore } from "./store";
|
||||
|
||||
export interface supervisorApplyUpdateDetails {
|
||||
type: "core" | "supervisor" | "os" | "addon";
|
||||
name: string;
|
||||
version: string;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user