mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Disconnect panel after 5 minutes hidden (#6152)
This commit is contained in:
parent
a822c1eb2f
commit
33af3de4a3
@ -91,6 +91,20 @@ class PartialPanelResolver extends HassRouterPage {
|
||||
|
||||
private _waitForStart = false;
|
||||
|
||||
private _disconnectedPanel?: ChildNode;
|
||||
|
||||
private _hiddenTimeout?: number;
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues) {
|
||||
super.firstUpdated(changedProps);
|
||||
|
||||
document.addEventListener(
|
||||
"visibilitychange",
|
||||
() => this._handleVisibilityChange(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
|
||||
@ -141,6 +155,27 @@ class PartialPanelResolver extends HassRouterPage {
|
||||
}
|
||||
}
|
||||
|
||||
private _handleVisibilityChange() {
|
||||
if (document.hidden) {
|
||||
this._hiddenTimeout = window.setTimeout(() => {
|
||||
this._hiddenTimeout = undefined;
|
||||
if (this.lastChild) {
|
||||
this._disconnectedPanel = this.lastChild;
|
||||
this.removeChild(this.lastChild);
|
||||
}
|
||||
}, 300000);
|
||||
} else {
|
||||
if (this._hiddenTimeout) {
|
||||
clearTimeout(this._hiddenTimeout);
|
||||
this._hiddenTimeout = undefined;
|
||||
}
|
||||
if (this._disconnectedPanel) {
|
||||
this.appendChild(this._disconnectedPanel);
|
||||
this._disconnectedPanel = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async _updateRoutes(oldPanels?: HomeAssistant["panels"]) {
|
||||
this.routerOptions = getRoutes(this.hass.panels);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user