diff --git a/custom_components/browser_mod/browser_mod.js b/custom_components/browser_mod/browser_mod.js index c364afa..fdb081e 100644 --- a/custom_components/browser_mod/browser_mod.js +++ b/custom_components/browser_mod/browser_mod.js @@ -1863,8 +1863,15 @@ const AutoSettingsMixin = (SuperClass) => { return class AutoSettingsMixinClass extends SuperClass { constructor() { super(); + this.__currentTitle = undefined; this._auto_settings_setup(); this.addEventListener("browser-mod-config-update", () => this._auto_settings_setup()); + window.addEventListener("location-changed", () => { + this._updateTitle(); + setTimeout(() => this._updateTitle(), 500); + setTimeout(() => this._updateTitle(), 1000); + setTimeout(() => this._updateTitle(), 5000); + }); } async _auto_settings_setup() { await this.connectionPromise; @@ -1908,7 +1915,20 @@ const AutoSettingsMixin = (SuperClass) => { })(); } // Title template - if (settings.titleTemplate !== undefined) ; + if (settings.titleTemplate !== undefined) { + (async () => { + if (this._titleTemplateSubscription) { + this._titleTemplateSubscription(); + } + this._titleTemplateSubscription = undefined; + this._titleTemplateSubscription = + await this.connection.subscribeMessage(this._updateTitle.bind(this), { + type: "render_template", + template: settings.titleTemplate, + variables: {}, + }); + })(); + } } get _currentFavicon() { const link = document.head.querySelector("link[rel~='icon']"); @@ -1927,6 +1947,16 @@ const AutoSettingsMixin = (SuperClass) => { link.href = result; window.browser_mod.fireEvent("browser-mod-favicon-update"); } + get _currentTitle() { + return this.__currentTitle; + } + _updateTitle(data = undefined) { + if (data) + this.__currentTitle = data.result; + if (this.__currentTitle) + document.title = this.__currentTitle; + window.browser_mod.fireEvent("browser-mod-favicon-update"); + } }; }; @@ -1967,12 +1997,13 @@ const AutoSettingsMixin = (SuperClass) => { X Framework x Save sidebar x Kiosk mode - - Default panel? + - Default panel - Screensaver? x Favicon templates - - Title templates + x Title templates - Tweaks - Quickbar tweaks (ctrl+enter)? + - Card-mod preload - Video player? - Media_seek - Screensavers diff --git a/custom_components/browser_mod/browser_mod_panel.js b/custom_components/browser_mod/browser_mod_panel.js index d45c6c6..7b487f1 100644 --- a/custom_components/browser_mod/browser_mod_panel.js +++ b/custom_components/browser_mod/browser_mod_panel.js @@ -119,8 +119,9 @@ class BrowserModSettingsCard extends s { return $ `
+

- Please note: Those settings severely change the way the Home + Please note: The settings in this section severely change the way the Home Assistant frontend works and looks. It is very easy to forget that you made a setting here when you switch devices or user.

@@ -130,6 +131,7 @@ class BrowserModSettingsCard extends s { caches. Failure to do so means you risk wasting a lot of peoples time, and you will be severly and rightfully ridiculed.

+

Global settings are applied for all users and browsers.
User settings are applied to the current user and overrides any Global settings.
@@ -189,10 +191,32 @@ class BrowserModSettingsCard extends s {

+ + Title template + ${OVERRIDDEN("titleTemplate")} + + { + const tpl = ev.detail.value || undefined; + window.browser_mod.set_setting("titleTemplate", tpl, level); + }} + > + + window.browser_mod.set_setting("titleTemplate", undefined, level)} + > + Clear + + + +
+ Hide Sidebar Hide the sidebar and hamburger menu - Currenty: ${DESC_BOOLEAN(current.hideSidebar)} + Currently: ${DESC_BOOLEAN(current.hideSidebar)} ${OVERRIDDEN("hideSidebar")} @@ -218,7 +242,7 @@ class BrowserModSettingsCard extends s { Hide Header Hide the header on all pages - Currenty: ${DESC_BOOLEAN(current.hideHeader)} + Currently: ${DESC_BOOLEAN(current.hideHeader)} ${OVERRIDDEN("hideHeader")} @@ -246,7 +270,7 @@ class BrowserModSettingsCard extends s { Order and visibility of sidebar buttons - Currenty: ${DESC_SET_UNSET(current.sidebarPanelOrder)} + Currently: ${DESC_SET_UNSET(current.sidebarPanelOrder)} ${OVERRIDDEN("sidebarPanelOrder")} diff --git a/js/config_panel/settings-card.ts b/js/config_panel/settings-card.ts index 400088b..b8fe323 100644 --- a/js/config_panel/settings-card.ts +++ b/js/config_panel/settings-card.ts @@ -27,8 +27,9 @@ class BrowserModSettingsCard extends LitElement { return html`
+

- Please note: Those settings severely change the way the Home + Please note: The settings in this section severely change the way the Home Assistant frontend works and looks. It is very easy to forget that you made a setting here when you switch devices or user.

@@ -38,6 +39,7 @@ class BrowserModSettingsCard extends LitElement { caches. Failure to do so means you risk wasting a lot of peoples time, and you will be severly and rightfully ridiculed.

+

Global settings are applied for all users and browsers.
User settings are applied to the current user and overrides any Global settings.
@@ -106,10 +108,33 @@ class BrowserModSettingsCard extends LitElement {

+ + Title template + ${OVERRIDDEN("titleTemplate")} + + { + const tpl = ev.detail.value || undefined; + window.browser_mod.set_setting("titleTemplate", tpl, level); + }} + > + + + window.browser_mod.set_setting("titleTemplate", undefined, level)} + > + Clear + + + +
+ Hide Sidebar Hide the sidebar and hamburger menu - Currenty: ${DESC_BOOLEAN(current.hideSidebar)} + Currently: ${DESC_BOOLEAN(current.hideSidebar)} ${OVERRIDDEN("hideSidebar")} @@ -138,7 +163,7 @@ class BrowserModSettingsCard extends LitElement { Hide Header Hide the header on all pages - Currenty: ${DESC_BOOLEAN(current.hideHeader)} + Currently: ${DESC_BOOLEAN(current.hideHeader)} ${OVERRIDDEN("hideHeader")} @@ -169,7 +194,7 @@ class BrowserModSettingsCard extends LitElement { Order and visibility of sidebar buttons - Currenty: ${DESC_SET_UNSET(current.sidebarPanelOrder)} + Currently: ${DESC_SET_UNSET(current.sidebarPanelOrder)} ${OVERRIDDEN("sidebarPanelOrder")} diff --git a/js/plugin/auto-settings.ts b/js/plugin/auto-settings.ts index fa2ac06..976fa11 100644 --- a/js/plugin/auto-settings.ts +++ b/js/plugin/auto-settings.ts @@ -4,6 +4,7 @@ export const AutoSettingsMixin = (SuperClass) => { return class AutoSettingsMixinClass extends SuperClass { _faviconTemplateSubscription; _titleTemplateSubscription; + __currentTitle = undefined; constructor() { super(); @@ -12,6 +13,13 @@ export const AutoSettingsMixin = (SuperClass) => { this.addEventListener("browser-mod-config-update", () => this._auto_settings_setup() ); + + window.addEventListener("location-changed", () => { + this._updateTitle(); + setTimeout(() => this._updateTitle(), 500); + setTimeout(() => this._updateTitle(), 1000); + setTimeout(() => this._updateTitle(), 5000); + }); } async _auto_settings_setup() { @@ -72,6 +80,21 @@ export const AutoSettingsMixin = (SuperClass) => { // Title template if (settings.titleTemplate !== undefined) { + (async () => { + if (this._titleTemplateSubscription) { + this._titleTemplateSubscription(); + } + this._titleTemplateSubscription = undefined; + this._titleTemplateSubscription = + await this.connection.subscribeMessage( + this._updateTitle.bind(this), + { + type: "render_template", + template: settings.titleTemplate, + variables: {}, + } + ); + })(); } } @@ -93,5 +116,15 @@ export const AutoSettingsMixin = (SuperClass) => { link.href = result; window.browser_mod.fireEvent("browser-mod-favicon-update"); } + + get _currentTitle() { + return this.__currentTitle; + } + + _updateTitle(data = undefined) { + if (data) this.__currentTitle = data.result; + if (this.__currentTitle) document.title = this.__currentTitle; + window.browser_mod.fireEvent("browser-mod-favicon-update"); + } }; }; diff --git a/js/plugin/main.ts b/js/plugin/main.ts index 5dffd97..34426a2 100644 --- a/js/plugin/main.ts +++ b/js/plugin/main.ts @@ -53,12 +53,13 @@ import { AutoSettingsMixin } from "./auto-settings"; X Framework x Save sidebar x Kiosk mode - - Default panel? + - Default panel - Screensaver? x Favicon templates - - Title templates + x Title templates - Tweaks - Quickbar tweaks (ctrl+enter)? + - Card-mod preload - Video player? - Media_seek - Screensavers