custom_components/bahmcloud_store/panel/panel.js aktualisiert

This commit is contained in:
2026-01-15 08:12:10 +00:00
parent 93ace71a12
commit 9ff89d18f3

View File

@@ -42,25 +42,34 @@ class BahmcloudStorePanel extends HTMLElement {
// --- Mobile navigation helpers --- // --- Mobile navigation helpers ---
_isDesktop() {
// If the viewport is wide enough, HA typically shows the sidebar permanently.
// We treat this as "desktop" and hide/disable the menu toggle.
return window.matchMedia && window.matchMedia("(min-width: 1024px)").matches;
}
_toggleMenu() { _toggleMenu() {
// Primary: dispatch the standard HA event from THIS element so it bubbles // On desktop the sidebar is usually always visible; do nothing.
// through the HA DOM tree (this is how many custom cards do it). if (this._isDesktop()) return;
// Primary: dispatch the standard HA event from THIS element so it bubbles.
try { try {
const ev = new Event("hass-toggle-menu", { bubbles: true, composed: true }); const ev = new Event("hass-toggle-menu", { bubbles: true, composed: true });
this.dispatchEvent(ev); this.dispatchEvent(ev);
return; // often enough on mobile
} catch (_) {} } catch (_) {}
// Secondary: try again via host/root (some environments proxy events) // Secondary: try again via host/root
try { try {
const host = this.shadowRoot?.host; const host = this.shadowRoot?.host;
if (host) { if (host) {
const ev2 = new Event("hass-toggle-menu", { bubbles: true, composed: true }); const ev2 = new Event("hass-toggle-menu", { bubbles: true, composed: true });
host.dispatchEvent(ev2); host.dispatchEvent(ev2);
return;
} }
} catch (_) {} } catch (_) {}
// Fallback: try common drawer implementations (best-effort). // Fallback DOM attempts
// HA frontend has changed over time (app-drawer-layout -> mwc-drawer etc.).
try { try {
const ha = document.querySelector("home-assistant"); const ha = document.querySelector("home-assistant");
const haRoot = ha?.shadowRoot; const haRoot = ha?.shadowRoot;
@@ -71,26 +80,22 @@ class BahmcloudStorePanel extends HTMLElement {
const mainRoot = main?.shadowRoot; const mainRoot = main?.shadowRoot;
// Try mwc-drawer / ha-drawer / app-drawer-layout variants
const drawer = const drawer =
mainRoot?.querySelector("mwc-drawer") || mainRoot?.querySelector("mwc-drawer") ||
mainRoot?.querySelector("ha-drawer") || mainRoot?.querySelector("ha-drawer") ||
mainRoot?.querySelector("app-drawer-layout"); mainRoot?.querySelector("app-drawer-layout");
if (drawer) { if (drawer) {
// mwc-drawer has .open boolean
if ("open" in drawer) { if ("open" in drawer) {
drawer.open = true; drawer.open = true;
return; return;
} }
// app-drawer-layout had toggleDrawer()
if (typeof drawer.toggleDrawer === "function") { if (typeof drawer.toggleDrawer === "function") {
drawer.toggleDrawer(); drawer.toggleDrawer();
return; return;
} }
} }
// Last attempt: HA layout container sometimes exposes a method
const layout = const layout =
mainRoot?.querySelector("ha-panel-lovelace") || mainRoot?.querySelector("ha-panel-lovelace") ||
mainRoot?.querySelector("ha-panel"); mainRoot?.querySelector("ha-panel");
@@ -101,7 +106,7 @@ class BahmcloudStorePanel extends HTMLElement {
} }
} catch (_) {} } catch (_) {}
// If we get here, we couldn't open it programmatically in this client. // Only show an error on mobile if everything failed.
this._error = "Unable to open the sidebar on this client. Use the back button."; this._error = "Unable to open the sidebar on this client. Use the back button.";
this._update(); this._update();
} }
@@ -169,7 +174,7 @@ class BahmcloudStorePanel extends HTMLElement {
display: block; display: block;
height: auto; height: auto;
min-height: 100%; min-height: 100%;
--bcs-accent: #1E88E5; /* Bahmcloud Blue */ --bcs-accent: #1E88E5;
} }
.mobilebar { .mobilebar {
@@ -181,7 +186,6 @@ class BahmcloudStorePanel extends HTMLElement {
justify-content: space-between; justify-content: space-between;
gap: 8px; gap: 8px;
padding: 10px 12px; padding: 10px 12px;
background: var(--app-header-background-color, var(--card-background-color)); background: var(--app-header-background-color, var(--card-background-color));
color: var(--app-header-text-color, var(--primary-text-color)); color: var(--app-header-text-color, var(--primary-text-color));
border-bottom: 1px solid var(--divider-color); border-bottom: 1px solid var(--divider-color);
@@ -211,6 +215,13 @@ class BahmcloudStorePanel extends HTMLElement {
line-height: 1; line-height: 1;
} }
/* Hide the menu button on desktop where the sidebar is already visible */
@media (min-width: 1024px) {
.iconbtn.menu {
display: none;
}
}
.brandtitle { .brandtitle {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -346,7 +357,7 @@ class BahmcloudStorePanel extends HTMLElement {
<div class="mobilebar"> <div class="mobilebar">
<div class="left"> <div class="left">
<div class="iconbtn" id="menuBtn" title="Menu">☰</div> <div class="iconbtn menu" id="menuBtn" title="Menu">☰</div>
<div class="iconbtn" id="backBtn" title="Back">←</div> <div class="iconbtn" id="backBtn" title="Back">←</div>
<div class="brandtitle"> <div class="brandtitle">
<div class="t">Bahmcloud Store</div> <div class="t">Bahmcloud Store</div>