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