diff --git a/hassio/src/components/supervisor-snapshot-content.ts b/hassio/src/components/supervisor-snapshot-content.ts index d1095179ca..b420f00959 100644 --- a/hassio/src/components/supervisor-snapshot-content.ts +++ b/hassio/src/components/supervisor-snapshot-content.ts @@ -5,6 +5,7 @@ import { customElement, property } from "lit/decorators"; import { atLeastVersion } from "../../../src/common/config/version"; import { formatDate } from "../../../src/common/datetime/format_date"; import { formatDateTime } from "../../../src/common/datetime/format_date_time"; +import { LocalizeFunc } from "../../../src/common/translations/localize"; import "../../../src/components/ha-checkbox"; import "../../../src/components/ha-formfield"; import "../../../src/components/ha-radio"; @@ -67,6 +68,8 @@ const _computeAddons = (addons): AddonCheckboxItem[] => export class SupervisorSnapshotContent extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; + @property() public localize?: LocalizeFunc; + @property({ attribute: false }) public supervisor?: Supervisor; @property({ attribute: false }) public snapshot?: HassioSnapshotDetail; @@ -81,6 +84,8 @@ export class SupervisorSnapshotContent extends LitElement { @property({ type: Boolean }) public snapshotHasPassword = false; + @property({ type: Boolean }) public onboarding = false; + @property() public snapshotName = ""; @property() public snapshotPassword = ""; @@ -106,8 +111,12 @@ export class SupervisorSnapshotContent extends LitElement { } } + private _localize = (string: string) => + this.supervisor?.localize(`snapshot.${string}`) || + this.localize!(`ui.panel.page-onboarding.restore.${string}`); + protected render(): TemplateResult { - if (!this.supervisor) { + if (!this.onboarding && !this.supervisor) { return html``; } const foldersSection = @@ -119,14 +128,16 @@ export class SupervisorSnapshotContent extends LitElement { ${this.snapshot ? html`
${this.snapshot.type === "full" - ? this.supervisor.localize("snapshot.full_snapshot") - : this.supervisor.localize("snapshot.partial_snapshot")} + ? this._localize("full_snapshot") + : this._localize("partial_snapshot")} (${Math.ceil(this.snapshot.size * 10) / 10 + " MB"})
- ${formatDateTime(new Date(this.snapshot.date), this.hass.locale)} + ${this.hass + ? formatDateTime(new Date(this.snapshot.date), this.hass.locale) + : this.snapshot.date}
` : html` @@ -134,13 +145,11 @@ export class SupervisorSnapshotContent extends LitElement { ${!this.snapshot || this.snapshot.type === "full" ? html`
${!this.snapshot - ? this.supervisor.localize("snapshot.type") - : this.supervisor.localize("snapshot.select_type")} + ? this._localize("type") + : this._localize("select_type")}
- + - + `} @@ -208,7 +215,7 @@ export class SupervisorSnapshotContent extends LitElement { ? html` `} @@ -233,7 +240,7 @@ export class SupervisorSnapshotContent extends LitElement { ${!this.snapshot ? html` ${!this.snapshot ? html` [item.slug, item]) + this.supervisor?.addon.addons.map((item) => [item.slug, item]) ) : undefined; let checkedItems = 0; @@ -367,6 +372,7 @@ export class SupervisorSnapshotContent extends LitElement { .label=${item.name} .iconPath=${section === "addons" ? mdiPuzzle : mdiFolder} .imageUrl=${section === "addons" && + !this.onboarding && atLeastVersion(this.hass.config.version, 0, 105) && addons?.get(item.slug)?.icon ? `/api/hassio/addons/${item.slug}/icon` diff --git a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts index e7afcdbad1..93938903c9 100755 --- a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts +++ b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts @@ -1,13 +1,13 @@ import { ActionDetail } from "@material/mwc-list"; import "@material/mwc-list/mwc-list-item"; -import { mdiDotsVertical } from "@mdi/js"; +import { mdiClose, mdiDotsVertical } from "@mdi/js"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { fireEvent } from "../../../../src/common/dom/fire_event"; import { slugify } from "../../../../src/common/string/slugify"; import "../../../../src/components/buttons/ha-progress-button"; import "../../../../src/components/ha-button-menu"; -import { createCloseHeading } from "../../../../src/components/ha-dialog"; +import "../../../../src/components/ha-header-bar"; import "../../../../src/components/ha-svg-icon"; import { getSignedPath } from "../../../../src/data/auth"; import { extractApiErrorMessage } from "../../../../src/data/hassio/common"; @@ -67,14 +67,24 @@ class HassioSnapshotDialog open scrimClickAction @closed=${this.closeDialog} - .heading=${createCloseHeading(this.hass, this._computeName)} + .heading=${true} > +
+ + ${this._snapshot.name} + + + + +
${this._restoringSnapshot ? html` ` : html` `} ${this._error ? html`

Error: ${this._error}

` : ""} @@ -87,18 +97,20 @@ class HassioSnapshotDialog Restore - ev.stopPropagation()} - > - - - - Download Snapshot - Delete Snapshot - + ${!this._dialogParams.onboarding + ? html` ev.stopPropagation()} + > + + + + Download Snapshot + Delete Snapshot + ` + : ""} `; } @@ -115,6 +127,12 @@ class HassioSnapshotDialog display: block; text-align: center; } + ha-header-bar { + --mdc-theme-on-primary: var(--primary-text-color); + --mdc-theme-primary: var(--mdc-theme-surface); + flex-shrink: 0; + display: block; + } `, ]; } diff --git a/hassio/src/dialogs/snapshot/show-dialog-hassio-snapshot.ts b/hassio/src/dialogs/snapshot/show-dialog-hassio-snapshot.ts index 8c7bcd2be7..fd74e90ea7 100644 --- a/hassio/src/dialogs/snapshot/show-dialog-hassio-snapshot.ts +++ b/hassio/src/dialogs/snapshot/show-dialog-hassio-snapshot.ts @@ -1,4 +1,5 @@ import { fireEvent } from "../../../../src/common/dom/fire_event"; +import { LocalizeFunc } from "../../../../src/common/translations/localize"; import { Supervisor } from "../../../../src/data/supervisor/supervisor"; export interface HassioSnapshotDialogParams { @@ -6,6 +7,7 @@ export interface HassioSnapshotDialogParams { onDelete?: () => void; onboarding?: boolean; supervisor?: Supervisor; + localize?: LocalizeFunc; } export const showHassioSnapshotDialog = ( diff --git a/src/onboarding/ha-onboarding.ts b/src/onboarding/ha-onboarding.ts index 2a7c66bd9f..cea41caaa6 100644 --- a/src/onboarding/ha-onboarding.ts +++ b/src/onboarding/ha-onboarding.ts @@ -12,7 +12,10 @@ import { HASSDomEvent } from "../common/dom/fire_event"; import { extractSearchParamsObject } from "../common/url/search-params"; import { subscribeOne } from "../common/util/subscribe-one"; import { AuthUrlSearchParams, hassUrl } from "../data/auth"; -import { fetchDiscoveryInformation } from "../data/discovery"; +import { + DiscoveryInformation, + fetchDiscoveryInformation, +} from "../data/discovery"; import { fetchOnboardingOverview, OnboardingResponses, @@ -68,6 +71,8 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) { @state() private _steps?: OnboardingStep[]; + @state() private _discoveryInformation?: DiscoveryInformation; + protected render(): TemplateResult { const step = this._curStep()!; @@ -87,6 +92,7 @@ class HaOnboarding extends litLocalizeLiteMixin(HassElement) { ? html` ` diff --git a/src/onboarding/onboarding-restore-snapshot.ts b/src/onboarding/onboarding-restore-snapshot.ts index 32d604c7ac..ca1afc56eb 100644 --- a/src/onboarding/onboarding-restore-snapshot.ts +++ b/src/onboarding/onboarding-restore-snapshot.ts @@ -4,9 +4,12 @@ import { customElement, property } from "lit/decorators"; import "../../hassio/src/components/hassio-ansi-to-html"; import { showHassioSnapshotDialog } from "../../hassio/src/dialogs/snapshot/show-dialog-hassio-snapshot"; import { showSnapshotUploadDialog } from "../../hassio/src/dialogs/snapshot/show-dialog-snapshot-upload"; -import { navigate } from "../common/navigate"; import type { LocalizeFunc } from "../common/translations/localize"; import "../components/ha-card"; +import { + DiscoveryInformation, + fetchDiscoveryInformation, +} from "../data/discovery"; import { makeDialogManager } from "../dialogs/make-dialog-manager"; import { ProvideHassLitMixin } from "../mixins/provide-hass-lit-mixin"; import { haStyle } from "../resources/styles"; @@ -26,6 +29,9 @@ class OnboardingRestoreSnapshot extends ProvideHassLitMixin(LitElement) { @property({ type: Boolean }) public restoring = false; + @property({ attribute: false }) + public discoveryInformation?: DiscoveryInformation; + protected render(): TemplateResult { return this.restoring ? html` { if (this.restoring) { try { - const response = await fetch("/api/hassio/supervisor/info", { - method: "GET", - }); - if (response.status === 401) { - // If we get a unauthorized response, the restore is done - navigate("/", { replace: true }); - location.reload(); + const response = await fetchDiscoveryInformation(); + + if ( + !this.discoveryInformation || + this.discoveryInformation.uuid !== response.uuid + ) { + // When the UUID changes, the restore is complete + window.location.replace("/"); } } catch (err) { // We fully expected issues with fetching info untill restore is complete. @@ -76,6 +83,7 @@ class OnboardingRestoreSnapshot extends ProvideHassLitMixin(LitElement) { showHassioSnapshotDialog(this, { slug, onboarding: true, + localize: this.localize, }); } diff --git a/src/translations/en.json b/src/translations/en.json index 0a9ab32f6d..9977b10956 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3569,7 +3569,16 @@ "description": "Alternatively you can restore from a previous snapshot.", "in_progress": "Restore in progress", "show_log": "Show full log", - "hide_log": "Hide full log" + "hide_log": "Hide full log", + "full_snapshot": "[%key:supervisor::snapshot::full_snapshot%]", + "partial_snapshot": "[%key:supervisor::snapshot::partial_snapshot%]", + "type": "[%key:supervisor::snapshot::type%]", + "select_type": "[%key:supervisor::snapshot::select_type%]", + "folders": "[%key:supervisor::snapshot::folders%]", + "addons": "[%key:supervisor::snapshot::addons%]", + "password_protection": "[%key:supervisor::snapshot::password_protection%]", + "password": "[%key:supervisor::snapshot::password%]", + "confirm_password": "[%key:supervisor::snapshot::confirm_password%]" } }, "custom": {