From c9cd316c0cab49e9a83520118608157603924226 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 4 Nov 2021 18:12:07 +0100 Subject: [PATCH 1/3] Play dummy media to prevent app from closing (#10531) --- cast/src/receiver/entrypoint.ts | 24 ++++++++++++++++++++++++ cast/src/receiver/layout/hc-main.ts | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/cast/src/receiver/entrypoint.ts b/cast/src/receiver/entrypoint.ts index e5c9791276..19053a23cd 100644 --- a/cast/src/receiver/entrypoint.ts +++ b/cast/src/receiver/entrypoint.ts @@ -28,11 +28,29 @@ const setTouchControlsVisibility = (visible: boolean) => { } }; +const playDummyMedia = () => { + const playerManager = castContext.getPlayerManager(); + const loadRequestData = new cast.framework.messages.LoadRequestData(); + loadRequestData.autoplay = true; + loadRequestData.media = new cast.framework.messages.MediaInformation(); + loadRequestData.media.contentId = + "https://www.home-assistant.io/images/blog/2018-09-thinking-big/social.png"; + loadRequestData.media.contentType = "image/jpeg"; + loadRequestData.media.streamType = cast.framework.messages.StreamType.NONE; + const metadata = new cast.framework.messages.GenericMediaMetadata(); + metadata.title = "Home Assistant Lovelace"; + loadRequestData.media.metadata = metadata; + + loadRequestData.requestId = 0; + playerManager.load(loadRequestData); +}; + const showLovelaceController = () => { mediaPlayer.style.display = "none"; lovelaceController.style.display = "initial"; document.body.setAttribute("style", "overflow-y: auto !important"); setTouchControlsVisibility(false); + playDummyMedia(); }; const showMediaPlayer = () => { @@ -103,6 +121,12 @@ const playerManager = castContext.getPlayerManager(); playerManager.setMessageInterceptor( cast.framework.messages.MessageType.LOAD, (loadRequestData) => { + if ( + loadRequestData.media.contentId === + "https://www.home-assistant.io/images/blog/2018-09-thinking-big/social.png" + ) { + return loadRequestData; + } // We received a play media command, hide Lovelace and show media player showMediaPlayer(); const media = loadRequestData.media; diff --git a/cast/src/receiver/layout/hc-main.ts b/cast/src/receiver/layout/hc-main.ts index 4e47ad61ae..207d46bb4a 100644 --- a/cast/src/receiver/layout/hc-main.ts +++ b/cast/src/receiver/layout/hc-main.ts @@ -107,6 +107,7 @@ export class HcMain extends HassElement { this._sendStatus(); } }); + this.addEventListener("dialog-closed", this._dialogClosed); } private _sendStatus(senderId?: string) { @@ -131,6 +132,10 @@ export class HcMain extends HassElement { } } + private _dialogClosed = () => { + document.body.setAttribute("style", "overflow-y: auto !important"); + }; + private async _handleGetStatusMessage(msg: GetStatusMessage) { this._sendStatus(msg.senderId!); } From 204ccf8b40b3f7f236758802f251b3369d7f052d Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 11 Jan 2022 00:30:21 +0100 Subject: [PATCH 2/3] Wait with navigate until history.back is done (#11152) Co-authored-by: Paulus Schoutsen --- src/common/navigate.ts | 6 ++++ .../automation/dialog-new-automation.ts | 11 +++---- src/state/url-sync-mixin.ts | 32 ++++++++++++++++--- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/common/navigate.ts b/src/common/navigate.ts index e2e0f26dd0..a9d41ab04d 100644 --- a/src/common/navigate.ts +++ b/src/common/navigate.ts @@ -1,3 +1,4 @@ +import { historyPromise } from "../state/url-sync-mixin"; import { fireEvent } from "./dom/fire_event"; import { mainWindow } from "./dom/get_main_window"; @@ -15,6 +16,11 @@ export interface NavigateOptions { export const navigate = (path: string, options?: NavigateOptions) => { const replace = options?.replace || false; + if (historyPromise) { + historyPromise.then(() => navigate(path, options)); + return; + } + if (__DEMO__) { if (replace) { mainWindow.history.replaceState( diff --git a/src/panels/config/automation/dialog-new-automation.ts b/src/panels/config/automation/dialog-new-automation.ts index 3f00995b05..4c3b6723eb 100644 --- a/src/panels/config/automation/dialog-new-automation.ts +++ b/src/panels/config/automation/dialog-new-automation.ts @@ -2,7 +2,6 @@ import "@material/mwc-button"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../common/dom/fire_event"; -import { nextRender } from "../../../common/util/render-status"; import "../../../components/ha-blueprint-picker"; import "../../../components/ha-card"; import "../../../components/ha-circular-progress"; @@ -26,8 +25,10 @@ class DialogNewAutomation extends LitElement implements HassDialog { } public closeDialog(): void { + if (this._opened) { + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } this._opened = false; - fireEvent(this, "dialog-closed", { dialog: this.localName }); } protected render(): TemplateResult { @@ -66,8 +67,8 @@ class DialogNewAutomation extends LitElement implements HassDialog { "ui.panel.config.automation.dialog_new.start_empty_description" )} - + + `; @@ -75,7 +76,6 @@ class DialogNewAutomation extends LitElement implements HassDialog { private async _blueprintPicked(ev: CustomEvent) { this.closeDialog(); - await nextRender(); showAutomationEditor({ use_blueprint: { path: ev.detail.value } }); } @@ -85,7 +85,6 @@ class DialogNewAutomation extends LitElement implements HassDialog { private async _blank() { this.closeDialog(); - await nextRender(); showAutomationEditor(); } diff --git a/src/state/url-sync-mixin.ts b/src/state/url-sync-mixin.ts index 684f9a79dc..d8cc554b75 100644 --- a/src/state/url-sync-mixin.ts +++ b/src/state/url-sync-mixin.ts @@ -13,6 +13,11 @@ import { Constructor } from "../types"; const DEBUG = false; +// eslint-disable-next-line import/no-mutable-exports +export let historyPromise: Promise | undefined; + +let historyResolve: undefined | (() => void); + export const urlSyncMixin = < T extends Constructor >( @@ -62,16 +67,26 @@ export const urlSyncMixin = < if (DEBUG) { console.log("remove state", ev.detail.dialog); } - this._ignoreNextPopState = true; - mainWindow.history.back(); + if (history.length) { + this._ignoreNextPopState = true; + historyPromise = new Promise((resolve) => { + historyResolve = () => { + resolve(); + historyResolve = undefined; + historyPromise = undefined; + }; + mainWindow.history.back(); + }); + } } }; private _popstateChangeListener = (ev: PopStateEvent) => { if (this._ignoreNextPopState) { if ( - ev.state?.oldState?.replaced || - ev.state?.oldState?.dialogParams === null + history.length && + (ev.state?.oldState?.replaced || + ev.state?.oldState?.dialogParams === null) ) { // if the previous dialog was replaced, or we could not copy the params, and the current dialog is closed, we should also remove the previous dialog from history if (DEBUG) { @@ -80,7 +95,13 @@ export const urlSyncMixin = < mainWindow.history.back(); return; } + if (DEBUG) { + console.log("ignore popstate"); + } this._ignoreNextPopState = false; + if (historyResolve) { + historyResolve(); + } return; } if (ev.state && "dialog" in ev.state) { @@ -89,6 +110,9 @@ export const urlSyncMixin = < } this._handleDialogStateChange(ev.state); } + if (historyResolve) { + historyResolve(); + } }; private async _handleDialogStateChange(state: DialogState) { From 069f08b55ea91ae08f1fa611bfbedad91e52a301 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 10 Jan 2022 15:30:53 -0800 Subject: [PATCH 3/3] Bumped version to 20211229.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b646c1a20e..6dcaec0b37 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="home-assistant-frontend", - version="20211229.0", + version="20211229.1", description="The Home Assistant frontend", url="https://github.com/home-assistant/frontend", author="The Home Assistant Authors",