Skip to content

Instantly share code, notes, and snippets.

@balloob
Created June 27, 2020 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balloob/3464f55b09442e5f71f72ecf81533ead to your computer and use it in GitHub Desktop.
Save balloob/3464f55b09442e5f71f72ecf81533ead to your computer and use it in GitHub Desktop.
Patch for HA frontend to debug visiblitychange behavior on Android
diff --git a/src/layouts/home-assistant.ts b/src/layouts/home-assistant.ts
index 0dae29df..663d152f 100644
--- a/src/layouts/home-assistant.ts
+++ b/src/layouts/home-assistant.ts
@@ -150,6 +150,7 @@ export class HomeAssistantAppEl extends HassElement {
protected _handleVisibilityChange() {
if (document.hidden) {
+ console.log("home-assistant handle tab hidden");
// If the document is hidden, we will prevent reconnects until we are visible again
this.hass!.connection.suspendReconnectUntil(
new Promise((resolve) => {
@@ -158,6 +159,9 @@ export class HomeAssistantAppEl extends HassElement {
);
// We close the connection to Home Assistant after being hidden for 5 minutes
this._hiddenTimeout = window.setTimeout(() => {
+ console.log("home-assistant setTimeout triggered", {
+ documentHidden: document.hidden,
+ });
this._hiddenTimeout = undefined;
// setTimeout can be delayed in the background and only fire
@@ -173,16 +177,20 @@ export class HomeAssistantAppEl extends HassElement {
this.hass!.connection.suspend();
}, 300000);
} else {
+ console.group("home-assistant handle tab shown");
// Clear timer to close the connection
if (this._hiddenTimeout) {
+ console.log("clearing timeout");
clearTimeout(this._hiddenTimeout);
this._hiddenTimeout = undefined;
}
// Unsuspend the reconnect
if (this._visiblePromiseResolve) {
+ console.log("unsuspend reconnect");
this._visiblePromiseResolve();
this._visiblePromiseResolve = undefined;
}
+ console.groupEnd();
}
}
}
diff --git a/src/layouts/partial-panel-resolver.ts b/src/layouts/partial-panel-resolver.ts
index e441cd02..c0bb5e8c 100644
--- a/src/layouts/partial-panel-resolver.ts
+++ b/src/layouts/partial-panel-resolver.ts
@@ -158,7 +158,11 @@ class PartialPanelResolver extends HassRouterPage {
private _handleVisibilityChange() {
if (document.hidden) {
+ console.log("partial-panel-resolver handle tab hidden");
this._hiddenTimeout = window.setTimeout(() => {
+ console.log("partial-panel-resolver setTimeout triggered", {
+ documentHidden: document.hidden,
+ });
this._hiddenTimeout = undefined;
// setTimeout can be delayed in the background and only fire
// when we switch to the tab or app again (Hey Android!)
@@ -181,14 +185,18 @@ class PartialPanelResolver extends HassRouterPage {
}
}, 300000);
} else {
+ console.group("partial-panel-resolver handle tab shown");
if (this._hiddenTimeout) {
+ console.log("clearing timeout");
clearTimeout(this._hiddenTimeout);
this._hiddenTimeout = undefined;
}
if (this._disconnectedPanel) {
+ console.log("reinstating panel");
this.appendChild(this._disconnectedPanel);
this._disconnectedPanel = undefined;
}
+ console.groupEnd();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment