Easier to use frontend options. Set sidebar title.

This commit is contained in:
thomas committed 2022-09-01 15:38:23 +00:00
1 parent 39f727206f
commit fffb017287
13 files changed
+738 -423

No files matched your search

+25 -25
View File
@@ -1,4 +1,4 @@
function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,i,r):o(t,i))||r);return n>3&&r&&Object.defineProperty(t,i,r),r}const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),s=new WeakMap;class o{constructor(e,t,s){if(this._$cssResult$=!0,s!==i)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const i=this.t;if(t&&void 0===e){const t=void 0!==i&&1===i.length;t&&(e=s.get(i)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),t&&s.set(i,e))}return e}toString(){return this.cssText}}const n=(e,...t)=>{const s=1===e.length?e[0]:t.reduce(((t,i,s)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+e[s+1]),e[0]);return new o(s,e,i)},r=t?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return(e=>new o("string"==typeof e?e:e+"",void 0,i))(t)})(e):e;var a;const d=window.trustedTypes,l=d?d.emptyScript:"",c=window.reactiveElementPolyfillSupport,h={toAttribute(e,t){switch(t){case Boolean:e=e?l:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let i=e;switch(t){case Boolean:i=null!==e;break;case Number:i=null===e?null:Number(e);break;case Object:case Array:try{i=JSON.parse(e)}catch(e){i=null}}return i}},u=(e,t)=>t!==e&&(t==t||e==e),p={attribute:!0,type:String,converter:h,reflect:!1,hasChanged:u};class v extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(e){var t;null!==(t=this.h)&&void 0!==t||(this.h=[]),this.h.push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,i)=>{const s=this._$Ep(i,t);void 0!==s&&(this._$Ev.set(s,i),e.push(s))})),e}static createProperty(e,t=p){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const i="symbol"==typeof e?Symbol():"__"+e,s=this.getPropertyDescriptor(e,i,t);void 0!==s&&Object.defineProperty(this.prototype,e,s)}}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(s){const o=this[e];this[t]=s,this.requestUpdate(e,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||p}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const i of t)this.createProperty(i,e[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const i=new Set(e.flat(1/0).reverse());for(const e of i)t.unshift(r(e))}else void 0!==e&&t.push(r(e));return t}static _$Ep(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}u(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,i;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(i=e.hostConnected)||void 0===i||i.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const i=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,i)=>{t?e.adoptedStyleSheets=i.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):i.forEach((t=>{const i=document.createElement("style"),s=window.litNonce;void 0!==s&&i.setAttribute("nonce",s),i.textContent=t.cssText,e.appendChild(i)}))})(i,this.constructor.elementStyles),i}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,i){thisLine truncated function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,i,r):o(t,i))||r);return n>3&&r&&Object.defineProperty(t,i,r),r}const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),s=new WeakMap;class o{constructor(e,t,s){if(this._$cssResult$=!0,s!==i)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const i=this.t;if(t&&void 0===e){const t=void 0!==i&&1===i.length;t&&(e=s.get(i)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),t&&s.set(i,e))}return e}toString(){return this.cssText}}const n=(e,...t)=>{const s=1===e.length?e[0]:t.reduce(((t,i,s)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+e[s+1]),e[0]);return new o(s,e,i)},r=t?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return(e=>new o("string"==typeof e?e:e+"",void 0,i))(t)})(e):e;var a;const d=window.trustedTypes,l=d?d.emptyScript:"",c=window.reactiveElementPolyfillSupport,h={toAttribute(e,t){switch(t){case Boolean:e=e?l:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let i=e;switch(t){case Boolean:i=null!==e;break;case Number:i=null===e?null:Number(e);break;case Object:case Array:try{i=JSON.parse(e)}catch(e){i=null}}return i}},u=(e,t)=>t!==e&&(t==t||e==e),p={attribute:!0,type:String,converter:h,reflect:!1,hasChanged:u};class v extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(e){var t;null!==(t=this.h)&&void 0!==t||(this.h=[]),this.h.push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,i)=>{const s=this._$Ep(i,t);void 0!==s&&(this._$Ev.set(s,i),e.push(s))})),e}static createProperty(e,t=p){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const i="symbol"==typeof e?Symbol():"__"+e,s=this.getPropertyDescriptor(e,i,t);void 0!==s&&Object.defineProperty(this.prototype,e,s)}}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(s){const o=this[e];this[t]=s,this.requestUpdate(e,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||p}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const i of t)this.createProperty(i,e[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const i=new Set(e.flat(1/0).reverse());for(const e of i)t.unshift(r(e))}else void 0!==e&&t.push(r(e));return t}static _$Ep(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}u(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,i;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(i=e.hostConnected)||void 0===i||i.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const i=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,i)=>{t?e.adoptedStyleSheets=i.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):i.forEach((t=>{const i=document.createElement("style"),s=window.litNonce;void 0!==s&&i.setAttribute("nonce",s),i.textContent=t.cssText,e.appendChild(i)}))})(i,this.constructor.elementStyles),i}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,i){thisLine truncated
<ha-card> <ha-card>
<div class="card-content"> <div class="card-content">
<ha-icon-button @click=${this.handleMute}> <ha-icon-button @click=${this.handleMute}>
@@ -15,7 +15,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
@change=${this.handleVolumeChange} @change=${this.handleVolumeChange}
></ha-slider> ></ha-slider>
${"stopped"===window.browser_mod.player_state?M`<div class="placeholder"></div>`:M` ${"stopped"===window.browser_mod.player_state?I`<div class="placeholder"></div>`:I`
<ha-icon-button @click=${this.handlePlayPause} highlight> <ha-icon-button @click=${this.handlePlayPause} highlight>
<ha-icon <ha-icon
.icon=${!window.browser_mod.player.src||window.browser_mod.player.ended||window.browser_mod.player.paused?"mdi:play":"mdi:pause"} .icon=${!window.browser_mod.player.src||window.browser_mod.player.ended||window.browser_mod.player.paused?"mdi:play":"mdi:pause"}
@@ -29,11 +29,11 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
<div class="browser-id">${window.browser_mod.browserID}</div> <div class="browser-id">${window.browser_mod.browserID}</div>
</ha-card> </ha-card>
`:M` `:I`
<ha-card> <ha-card>
<ha-alert> This browser is not registered to Browser Mod. </ha-alert> <ha-alert> This browser is not registered to Browser Mod. </ha-alert>
</ha-card> </ha-card>
`:(window.setTimeout((()=>this.requestUpdate()),100),M``)}static get styles(){return n` `:(window.setTimeout((()=>this.requestUpdate()),100),I``)}static get styles(){return n`
:host(["hidden"]) { :host(["hidden"]) {
display: none; display: none;
} }
@@ -63,7 +63,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
ha-icon-button ha-icon { ha-icon-button ha-icon {
display: flex; display: flex;
} }
`}}e([ee()],ne.prototype,"hass",void 0),e([ee({attribute:"edit-mode",reflect:!0})],ne.prototype,"editMode",void 0),customElements.get("browser-player")||customElements.define("browser-player",ne);async function re(e){var t;(null===(t=e.localName)||void 0===t?void 0:t.includes("-"))&&await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete}async function ae(e,t,i=!1){let s=[e];for("string"==typeof t&&(t=t.split(/(\$| )/));""===t[t.length-1];)t.pop();for(const[e,i]of t.entries()){const e=s[0];if(!e)return null;i.trim().length&&(re(e),s="$"===i?[e.shadowRoot]:e.querySelectorAll(i))}return i?s:s[0]}async function de(e,t,i=!1,s=1e4){return Promise.race([ae(e,t,i),new Promise(((e,t)=>setTimeout((()=>t(new Error("SELECTTREE-TIMEOUT"))),s)))]).catch((e=>{if(!e.message||"SELECTTREE-TIMEOUT"!==e.message)throw e;return null}))}async function le(){await Promise.race([customElements.whenDefined("home-assistant"),customElements.whenDefined("hc-main")]);const e=customElements.get("home-assistant")?"home-assistant":"hc-main";for(;!document.querySelector(e);)await new Promise((e=>window.setTimeout(e,100)));return document.querySelector(e)}async function ce(e){(await le()).provideHass(e)}const he=async()=>{var e,t,i;if(void 0!==window.loadCardHelpers)return;await customElements.whenDefined("partial-panel-resolver");const s=document.createElement("partial-panel-resolver").getRoutes([{component_name:"lovelace",url_path:"a"}]);await(null===(i=null===(t=null===(e=null==s?void 0:s.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===i?void 0:i.call(t))},ue=async()=>{if(customElements.get("ha-form"))return;await he();const e=await window.loadCardHelpers();if(!e)return;const t=await e.createCardElement({type:"button"});t&&await t.constructor.getConfigElement()};const pe=e=>class extends e{constructor(){super(...arguments),this.connected=!1,this.connectionPromise=new Promise((e=>{this._connectionResolve=e})),this.browserEntities={}}LOG(...e){if(void 0===window.browser_mod_log)return;const t=new Date;console.log(`${t.toLocaleTimeString()}`,...e),this.connection.sendMessage({type:"browser_mod/log",message:e[0]})}fireEvent(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}incoming_message(e){var t;e.command?(this.LOG("Command:",e),this.fireEvent(`command-${e.command}`,e)):e.browserEntities?this.browserEntities=e.browserEntities:e.result&&this.update_config(e.result),null===(t=this._connectionResolve)||void 0===t||t.call(this),this._connectionResolve=void 0}update_config(e){var t;this.LOG("Receive:",e);let i=!1;!this.registered&&(null===(t=e.browsers)||void 0===t?void 0:t[this.browserID])&&(i=!0),this._data=e,this.connected||(this.connected=!0,this.fireEvent("browser-mod-connected")),this.fireEvent("browser-mod-config-update"),i&&this.sendUpdate({})}async connect(){const e=(await async function(){const e=await le();for(;!e.hass;)await new Promise((e=>window.setTimeout(e,100)));return e.hass}()).connection;this.connection=e,e.subscribeMessage((e=>this.incoming_message(e)),{type:"browser_mod/connect",browserID:this.browserID}),e.addEventListener("disconnected",(()=>{this.connected=!1,this.fireEvent("browser-mod-disconnected")})),e.addEventListener("ready",(()=>{this.connected=!0,this.fireEvent("browser-mod-connected"),this.sendUpdate({})})),ce(this)}get config(){var e,t;return null!==(t=null===(e=this._data)||void 0===e?void 0:e.config)&&void 0!==t?t:{}}get browsers(){var e,t;return null!==(t=null===(e=this._data)||void 0===e?void 0:e.browsers)&&void 0!==t?t:[]}get registered(){var e;return void 0!==(null===(e=this.browsers)||void 0===e?void 0:e[this.browserID])}set registered(e){(async()=>{if(e){if(this.registered)return;await this.connection.sendMessage({type:"browser_mod/register",browserID:this.browserID})}else{if(!this.registered)return;await this.connection.sendMessage({type:"browser_mod/unregister",browserID:this.browserID})}})()}async _reregister(e={}){await this.connection.sendMessage({type:"browser_mod/register",browserID:this.browserID,data:Object.assign(Object.assign({},this.browsers[this.browserID]),e)})}get global_settings(){var e,t;const i={},s=null!==(t=null===(e=this._data)||void 0===e?void 0:e.settings)&&void 0!==t?t:{};for(const[e,t]of Object.entries(s))null!==t&&(i[e]=t);return i}get user_settings(){var e,t,i,s,o;const n={},r=null!==(o=null===(t=null===(e=this._data)||void 0===e?void 0:e.user_settings)||void 0===t?void 0:t[null===(s=null===(i=this.hass)||void 0===i?void 0:i.user)||void 0===s?void 0:s.id])&&void 0!==o?o:{};for(const[e,t]of Object.entries(r))null!==t&&(n[e]=t);return n}get browser_settings(){var e,t,i;const s={},o=null!==(i=null===(t=null===(e=this.browsers)||void 0===e?void 0:e[this.browserID])||void 0===t?void 0:t.settings)&&void 0!==i?i:{};for(const[e,t]of Object.entries(o))null!==t&&(s[e]=t);return s}get settings(){return Object.assign(Object.assign(Object.assign({},this.global_settings),this.browser_settings),this.user_settings)}set_setting(e,t Line truncated `}}e([ee()],ne.prototype,"hass",void 0),e([ee({attribute:"edit-mode",reflect:!0})],ne.prototype,"editMode",void 0),customElements.get("browser-player")||customElements.define("browser-player",ne);async function re(e,t=!1){var i;if((null===(i=e.localName)||void 0===i?void 0:i.includes("-"))&&await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete,t&&(e.pageRendered&&await e.pageRendered,e._panelState)){let t=0;for(;"loaded"!==e._panelState&&t++<5;)await new Promise((e=>setTimeout(e,100)))}}async function ae(e,t,i=!1){let s=[e];for("string"==typeof t&&(t=t.split(/(\$| )/));""===t[t.length-1];)t.pop();for(const[e,i]of t.entries()){const e=s[0];if(!e)return null;i.trim().length&&(re(e),s="$"===i?[e.shadowRoot]:e.querySelectorAll(i))}return i?s:s[0]}async function de(e,t,i=!1,s=1e4){return Promise.race([ae(e,t,i),new Promise(((e,t)=>setTimeout((()=>t(new Error("SELECTTREE-TIMEOUT"))),s)))]).catch((e=>{if(!e.message||"SELECTTREE-TIMEOUT"!==e.message)throw e;return null}))}async function le(){await Promise.race([customElements.whenDefined("home-assistant"),customElements.whenDefined("hc-main")]);const e=customElements.get("home-assistant")?"home-assistant":"hc-main";for(;!document.querySelector(e);)await new Promise((e=>window.setTimeout(e,100)));return document.querySelector(e)}async function ce(e){(await le()).provideHass(e)}const he=async()=>{var e,t,i;if(void 0!==window.loadCardHelpers)return;await customElements.whenDefined("partial-panel-resolver");const s=document.createElement("partial-panel-resolver").getRoutes([{component_name:"lovelace",url_path:"a"}]);await(null===(i=null===(t=null===(e=null==s?void 0:s.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===i?void 0:i.call(t))},ue=async()=>{if(customElements.get("ha-form"))return;await he();const e=await window.loadCardHelpers();if(!e)return;const t=await e.createCardElement({type:"button"});t&&await t.constructor.getConfigElement()};function pe(e=!1){return function(t,i,s){const o=s.value;let n;const r=function(...t){if(e&&!1===n&&(n=!0),void 0!==n)return;n=!1;const i=o.bind(this)(...t);return n?(n=void 0,r.bind(this)(...t)):(n=void 0,i)};s.value=r}}const ve=e=>class extends e{constructor(){super(...arguments),this.connected=!1,this.connectionPromise=new Promise((e=>{this._connectionResolve=e})),this.browserEntities={}}LOG(...e){if(void 0===window.browser_mod_log)return;const t=new Date;console.log(`${t.toLocaleTimeString()}`,...e),this.connection.sendMessage({type:"browser_mod/log",message:e[0]})}fireEvent(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0}))}incoming_message(e){var t;e.command?(this.LOG("Command:",e),this.fireEvent(`command-${e.command}`,e)):e.browserEntities?this.browserEntities=e.browserEntities:e.result&&this.update_config(e.result),null===(t=this._connectionResolve)||void 0===t||t.call(this),this._connectionResolve=void 0}update_config(e){var t;this.LOG("Receive:",e);let i=!1;!this.registered&&(null===(t=e.browsers)||void 0===t?void 0:t[this.browserID])&&(i=!0),this._data=e,this.connected||(this.connected=!0,this.fireEvent("browser-mod-connected")),this.fireEvent("browser-mod-config-update"),i&&this.sendUpdate({})}async connect(){const e=(await async function(){const e=await le();for(;!e.hass;)await new Promise((e=>window.setTimeout(e,100)));return e.hass}()).connection;this.connection=e,e.subscribeMessage((e=>this.incoming_message(e)),{type:"browser_mod/connect",browserID:this.browserID}),e.addEventListener("disconnected",(()=>{this.connected=!1,this.fireEvent("browser-mod-disconnected")})),e.addEventListener("ready",(()=>{this.connected=!0,this.fireEvent("browser-mod-connected"),this.sendUpdate({})})),ce(this)}get config(){var e,t;return null!==(t=null===(e=this._data)||void 0===e?void 0:e.config)&&void 0!==t?t:{}}get browsers(){var e,t;return null!==(t=null===(e=this._data)||void 0===e?void 0:e.browsers)&&void 0!==t?t:[]}get registered(){var e;return void 0!==(null===(e=this.browsers)||void 0===e?void 0:e[this.browserID])}set registered(e){(async()=>{if(e){if(this.registered)return;await this.connection.sendMessage({type:"browser_mod/register",browserID:this.browserID})}else{if(!this.registered)return;await this.connection.sendMessage({type:"browser_mod/unregister",browserID:this.browserID})}})()}async _reregister(e={}){await this.connection.sendMessage({type:"browser_mod/register",browserID:this.browserID,data:Object.assign(Object.assign({},this.browsers[this.browserID]),e)})}get global_settings(){var e,t;const i={},s=null!==(t=null===(e=this._data)||void 0===e?void 0:e.settings)&&void 0!==t?t:{};for(const[e,t]of Object.entries(s))null!==t&&(i[e]=t);return i}get user_settings(){var e,t,i,s,o;const n={},r=null!==(o=null===(t=null===(e=this._data)||void 0===e?void 0:e.user_settings)||void 0===t?void 0:t[null===(s=null===(i=this.hass)||void 0===i?void 0:i.user)||void 0===s?void 0:s.id])&&void 0!==o?o:{};for(const[e,t]of Object.entries(r))null!==t&&(n[e]=t);return n}g Line truncated
<ha-dialog <ha-dialog
open open
@closed=${this.closeDialog} @closed=${this.closeDialog}
@@ -73,11 +73,11 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
.scrimClickAction=${this.dismissable?"close":""} .scrimClickAction=${this.dismissable?"close":""}
.escapeKeyAction=${this.dismissable?"close":""} .escapeKeyAction=${this.dismissable?"close":""}
> >
${this.timeout?M` <div slot="heading" class="progress"></div> `:""} ${this.timeout?I` <div slot="heading" class="progress"></div> `:""}
${this.title?M` ${this.title?I`
<div slot="heading"> <div slot="heading">
<ha-header-bar> <ha-header-bar>
${this.dismissable?M` ${this.dismissable?I`
<ha-icon-button <ha-icon-button
dialogAction="cancel" dialogAction="cancel"
slot="navigationIcon" slot="navigationIcon"
@@ -88,11 +88,11 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
<div slot="title" class="main-title">${this.title}</div> <div slot="title" class="main-title">${this.title}</div>
</ha-header-bar> </ha-header-bar>
</div> </div>
`:M``} `:I``}
<div class="content">${this.content}</div> <div class="content">${this.content}</div>
${void 0!==this.right_button?M` ${void 0!==this.right_button?I`
<mwc-button <mwc-button
slot="primaryAction" slot="primaryAction"
.label=${this.right_button} .label=${this.right_button}
@@ -100,7 +100,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
class="action-button" class="action-button"
></mwc-button> ></mwc-button>
`:""} `:""}
${void 0!==this.left_button?M` ${void 0!==this.left_button?I`
<mwc-button <mwc-button
slot="secondaryAction" slot="secondaryAction"
.label=${this.left_button} .label=${this.left_button}
@@ -114,7 +114,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
} }
</style> </style>
</ha-dialog> </ha-dialog>
`:M``}static get styles(){return n` `:I``}static get styles(){return n`
ha-dialog { ha-dialog {
z-index: 10; z-index: 10;
--mdc-dialog-min-width: var(--popup-min-width, 400px); --mdc-dialog-min-width: var(--popup-min-width, 400px);
@@ -218,7 +218,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
--vertial-align-dialog: flex-end; --vertial-align-dialog: flex-end;
} }
} }
`}}e([ee()],xe.prototype,"open",void 0),e([ee()],xe.prototype,"content",void 0),e([ee()],xe.prototype,"title",void 0),e([ee({reflect:!0})],xe.prototype,"actions",void 0),e([ee({reflect:!0})],xe.prototype,"card",void 0),e([ee()],xe.prototype,"right_button",void 0),e([ee()],xe.prototype,"left_button",void 0),e([ee()],xe.prototype,"dismissable",void 0),e([ee({reflect:!0})],xe.prototype,"wide",void 0),e([ee({reflect:!0})],xe.prototype,"fullscreen",void 0),e([ee()],xe.prototype,"_style",void 0),e([ie("ha-dialog")],xe.prototype,"dialog",void 0),customElements.get("browser-mod-popup")||customElements.define("browser-mod-popup",xe);const Se=e=>class extends e{constructor(){super(),he(),this._popupEl=document.createElement("browser-mod-popup"),document.body.append(this._popupEl)}showPopup(...e){this._popupEl.setupDialog(...e).then((()=>this._popupEl.openDialog()))}closePopup(...e){this._popupEl.closeDialog(),this.showMoreInfo("")}async showMoreInfo(e,t=!1,i){const s=await le();if(s.dispatchEvent(new CustomEvent("hass-more-info",{bubbles:!0,composed:!0,cancelable:!1,detail:{entityId:e,ignore_popup_card:i}})),t){await new Promise((e=>setTimeout(e,50)));const e=s.shadowRoot.querySelector("ha-more-info-dialog");e&&(e.large=!0)}}};var Ce="2.0.0b4";const Te=[{name:"entity",label:"Entity",selector:{entity:{}}},{name:"title",label:"Title",selector:{text:{}}},{name:"size",selector:{select:{mode:"dropdown",options:["normal","wide","fullscreen"]}}},{type:"grid",schema:[{name:"right_button",label:"Right button",selector:{text:{}}},{name:"left_button",label:"Left button",selector:{text:{}}}]},{type:"grid",schema:[{name:"right_button_action",label:"Right button action",selector:{object:{}}},{name:"left_button_action",label:"Left button action",selector:{object:{}}}]},{type:"grid",schema:[{name:"dismissable",label:"User dismissable",selector:{boolean:{}}},{name:"timeout",label:"Auto close timeout (ms)",selector:{number:{mode:"box"}}}]},{type:"grid",schema:[{name:"dismiss_action",label:"Dismiss action",selector:{object:{}}},{name:"timeout_action",label:"Timeout action",selector:{object:{}}}]},{name:"style",label:"CSS style",selector:{text:{multiline:!0}}}];class ke extends Q{constructor(){super(...arguments),this._selectedTab=0,this._cardGUIMode=!0,this._cardGUIModeAvailable=!0}setConfig(e){this._config=e}connectedCallback(){super.connectedCallback(),ue()}_handleSwitchTab(e){this._selectedTab=parseInt(e.detail.index,10)}_configChanged(e){e.stopPropagation(),this._config&&(this._config=Object.assign({},e.detail.value),this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}})))}_cardConfigChanged(e){if(e.stopPropagation(),!this._config)return;const t=Object.assign({},e.detail.config);this._config=Object.assign(Object.assign({},this._config),{card:t}),this._cardGUIModeAvailable=e.detail.guiModeAvailable,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}}))}_toggleCardMode(e){var t;null===(t=this._cardEditorEl)||void 0===t||t.toggleMode()}_deleteCard(e){this._config&&(this._config=Object.assign({},this._config),delete this._config.card,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}})))}_cardGUIModeChanged(e){e.stopPropagation(),this._cardGUIMode=e.detail.guiMode,this._cardGUIModeAvailable=e.detail.guiModeAvailable}render(){return this.hass&&this._config?M` `}}e([ee()],xe.prototype,"open",void 0),e([ee()],xe.prototype,"content",void 0),e([ee()],xe.prototype,"title",void 0),e([ee({reflect:!0})],xe.prototype,"actions",void 0),e([ee({reflect:!0})],xe.prototype,"card",void 0),e([ee()],xe.prototype,"right_button",void 0),e([ee()],xe.prototype,"left_button",void 0),e([ee()],xe.prototype,"dismissable",void 0),e([ee({reflect:!0})],xe.prototype,"wide",void 0),e([ee({reflect:!0})],xe.prototype,"fullscreen",void 0),e([ee()],xe.prototype,"_style",void 0),e([ie("ha-dialog")],xe.prototype,"dialog",void 0),customElements.get("browser-mod-popup")||customElements.define("browser-mod-popup",xe);const Ce=e=>class extends e{constructor(){super(),he(),this._popupEl=document.createElement("browser-mod-popup"),document.body.append(this._popupEl)}showPopup(...e){this._popupEl.setupDialog(...e).then((()=>this._popupEl.openDialog()))}closePopup(...e){this._popupEl.closeDialog(),this.showMoreInfo("")}async showMoreInfo(e,t=!1,i){const s=await le();if(s.dispatchEvent(new CustomEvent("hass-more-info",{bubbles:!0,composed:!0,cancelable:!1,detail:{entityId:e,ignore_popup_card:i}})),t){await new Promise((e=>setTimeout(e,50)));const e=s.shadowRoot.querySelector("ha-more-info-dialog");e&&(e.large=!0)}}};var Te="2.0.0b5";const ke=[{name:"entity",label:"Entity",selector:{entity:{}}},{name:"title",label:"Title",selector:{text:{}}},{name:"size",selector:{select:{mode:"dropdown",options:["normal","wide","fullscreen"]}}},{type:"grid",schema:[{name:"right_button",label:"Right button",selector:{text:{}}},{name:"left_button",label:"Left button",selector:{text:{}}}]},{type:"grid",schema:[{name:"right_button_action",label:"Right button action",selector:{object:{}}},{name:"left_button_action",label:"Left button action",selector:{object:{}}}]},{type:"grid",schema:[{name:"dismissable",label:"User dismissable",selector:{boolean:{}}},{name:"timeout",label:"Auto close timeout (ms)",selector:{number:{mode:"box"}}}]},{type:"grid",schema:[{name:"dismiss_action",label:"Dismiss action",selector:{object:{}}},{name:"timeout_action",label:"Timeout action",selector:{object:{}}}]},{name:"style",label:"CSS style",selector:{text:{multiline:!0}}}];class Pe extends Q{constructor(){super(...arguments),this._selectedTab=0,this._cardGUIMode=!0,this._cardGUIModeAvailable=!0}setConfig(e){this._config=e}connectedCallback(){super.connectedCallback(),ue()}_handleSwitchTab(e){this._selectedTab=parseInt(e.detail.index,10)}_configChanged(e){e.stopPropagation(),this._config&&(this._config=Object.assign({},e.detail.value),this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}})))}_cardConfigChanged(e){if(e.stopPropagation(),!this._config)return;const t=Object.assign({},e.detail.config);this._config=Object.assign(Object.assign({},this._config),{card:t}),this._cardGUIModeAvailable=e.detail.guiModeAvailable,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}}))}_toggleCardMode(e){var t;null===(t=this._cardEditorEl)||void 0===t||t.toggleMode()}_deleteCard(e){this._config&&(this._config=Object.assign({},this._config),delete this._config.card,this.dispatchEvent(new CustomEvent("config-changed",{detail:{config:this._config}})))}_cardGUIModeChanged(e){e.stopPropagation(),this._cardGUIMode=e.detail.guiMode,this._cardGUIModeAvailable=e.detail.guiModeAvailable}render(){return this.hass&&this._config?I`
<div class="card-config"> <div class="card-config">
<div class="toolbar"> <div class="toolbar">
<mwc-tab-bar <mwc-tab-bar
@@ -233,17 +233,17 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
${[this._renderSettingsEditor,this._renderCardEditor][this._selectedTab].bind(this)()} ${[this._renderSettingsEditor,this._renderCardEditor][this._selectedTab].bind(this)()}
</div> </div>
</div> </div>
`:M``}_renderSettingsEditor(){return M`<div class="box"> `:I``}_renderSettingsEditor(){return I`<div class="box">
<ha-form <ha-form
.hass=${this.hass} .hass=${this.hass}
.data=${this._config} .data=${this._config}
.schema=${Te} .schema=${ke}
.computeLabel=${e=>{var t;return null!==(t=e.label)&&void 0!==t?t:e.name}} .computeLabel=${e=>{var t;return null!==(t=e.label)&&void 0!==t?t:e.name}}
@value-changed=${this._configChanged} @value-changed=${this._configChanged}
></ha-form> ></ha-form>
</div>`}_renderCardEditor(){return M` </div>`}_renderCardEditor(){return I`
<div class="box cards"> <div class="box cards">
${this._config.card?M` ${this._config.card?I`
<div class="toolbar"> <div class="toolbar">
<mwc-button <mwc-button
@click=${this._toggleCardMode} @click=${this._toggleCardMode}
@@ -266,7 +266,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
@config-changed=${this._cardConfigChanged} @config-changed=${this._cardConfigChanged}
@GUImode-changed=${this._cardGUIModeChanged} @GUImode-changed=${this._cardGUIModeChanged}
></hui-card-element-editor> ></hui-card-element-editor>
`:M` `:I`
<hui-card-picker <hui-card-picker
.hass=${this.hass} .hass=${this.hass}
.lovelace=${this.lovelace} .lovelace=${this.lovelace}
@@ -292,9 +292,9 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
.gui-mode-button { .gui-mode-button {
margin-right: auto; margin-right: auto;
} }
`}}e([te()],ke.prototype,"_config",void 0),e([ee()],ke.prototype,"lovelace",void 0),e([ee()],ke.prototype,"hass",void 0),e([te()],ke.prototype,"_selectedTab",void 0),e([te()],ke.prototype,"_cardGUIMode",void 0),e([te()],ke.prototype,"_cardGUIModeAvailable",void 0),e([ie("hui-card-element-editor")],ke.prototype,"_cardEditorEl",void 0),(async()=>{for(;!window.browser_mod;)await new Promise((e=>setTimeout(e,1e3)));await window.browser_mod.connectionPromise,customElements.get("popup-card-editor")||(customElements.define("popup-card-editor",ke),window.customCards=window.customCards||[],window.customCards.push({type:"popup-card",name:"Popup card",preview:!1,description:"Replace the more-info dialog for a given entity in the view that includes this card. (Browser Mod)"}))})();class Pe extends Q{constructor(){super(),this.popup=this.popup.bind(this)}static getConfigElement(){return document.createElement("popup-card-editor")}static getStubConfig(e,t){return{entity:t[0],title:"Custom popup",dismissable:!0,card:{type:"markdown",content:"This replaces the more-info dialog"}}}setConfig(e){this._config=e,(async()=>{const t=await window.loadCardHelpers();this._element=await t.createCardElement(e.card),this._element.hass=this.hass})()}async connectedCallback(){super.connectedCallback(),window.addEventListener("hass-more-info",this.popup),"hui-card-preview"===this.parentElement.localName?(this.editMode=!0,this.removeAttribute("hidden")):this.setAttribute("hidden","")}async disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hass-more-info",this.popup)}popup(e){var t,i,s;if((null===(t=e.detail)||void 0===t?void 0:t.entityId)===this._config.entity&&!(null===(i=e.detail)||void 0===i?void 0:i.ignore_popup_card)){e.stopPropagation(),e.preventDefault();delete Object.assign({},this._config).card,null===(s=window.browser_mod)||void 0===s||s.service("popup",Object.assign({content:this._config.card},this._config)),setTimeout((()=>this.dispatchEvent(new CustomEvent("hass-more-info",{bubbles:!0,composed:!0,cancelable:!1,detail:{entityId:"."}}))),50)}}updated(e){super.updated(e),e.has("hass")&&this._element&&(this._element.hass=this.hass)}render(){return this.editMode?M` <ha-card> `}}e([te()],Pe.prototype,"_config",void 0),e([ee()],Pe.prototype,"lovelace",void 0),e([ee()],Pe.prototype,"hass",void 0),e([te()],Pe.prototype,"_selectedTab",void 0),e([te()],Pe.prototype,"_cardGUIMode",void 0),e([te()],Pe.prototype,"_cardGUIModeAvailable",void 0),e([ie("hui-card-element-editor")],Pe.prototype,"_cardEditorEl",void 0),(async()=>{for(;!window.browser_mod;)await new Promise((e=>setTimeout(e,1e3)));await window.browser_mod.connectionPromise,customElements.get("popup-card-editor")||(customElements.define("popup-card-editor",Pe),window.customCards=window.customCards||[],window.customCards.push({type:"popup-card",name:"Popup card",preview:!1,description:"Replace the more-info dialog for a given entity in the view that includes this card. (Browser Mod)"}))})();class Oe extends Q{constructor(){super(),this.popup=this.popup.bind(this)}static getConfigElement(){return document.createElement("popup-card-editor")}static getStubConfig(e,t){return{entity:t[0],title:"Custom popup",dismissable:!0,card:{type:"markdown",content:"This replaces the more-info dialog"}}}setConfig(e){this._config=e,(async()=>{const t=await window.loadCardHelpers();this._element=await t.createCardElement(e.card),this._element.hass=this.hass})()}async connectedCallback(){super.connectedCallback(),window.addEventListener("hass-more-info",this.popup),"hui-card-preview"===this.parentElement.localName?(this.editMode=!0,this.removeAttribute("hidden")):this.setAttribute("hidden","")}async disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hass-more-info",this.popup)}popup(e){var t,i,s;if((null===(t=e.detail)||void 0===t?void 0:t.entityId)===this._config.entity&&!(null===(i=e.detail)||void 0===i?void 0:i.ignore_popup_card)){e.stopPropagation(),e.preventDefault();delete Object.assign({},this._config).card,null===(s=window.browser_mod)||void 0===s||s.service("popup",Object.assign({content:this._config.card},this._config)),setTimeout((()=>this.dispatchEvent(new CustomEvent("hass-more-info",{bubbles:!0,composed:!0,cancelable:!1,detail:{entityId:"."}}))),50)}}updated(e){super.updated(e),e.has("hass")&&this._element&&(this._element.hass=this.hass)}render(){return this.editMode?I` <ha-card>
<div class="app-toolbar"> <div class="app-toolbar">
${this._config.dismissable?M` ${this._config.dismissable?I`
<ha-icon-button> <ha-icon-button>
<ha-icon .icon=${"mdi:close"}></ha-icon> <ha-icon .icon=${"mdi:close"}></ha-icon>
</ha-icon-button> </ha-icon-button>
@@ -307,17 +307,17 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
${this._config.style} ${this._config.style}
} }
</style> </style>
${void 0!==this._config.right_button||void 0!==this._config.left_button?M` ${void 0!==this._config.right_button||void 0!==this._config.left_button?I`
<footer class="mdc-dialog__actions"> <footer class="mdc-dialog__actions">
<span> <span>
${void 0!==this._config.left_button?M` ${void 0!==this._config.left_button?I`
<mwc-button <mwc-button
.label=${this._config.left_button} .label=${this._config.left_button}
></mwc-button> ></mwc-button>
`:""} `:""}
</span> </span>
<span> <span>
${void 0!==this._config.right_button?M` ${void 0!==this._config.right_button?I`
<mwc-button <mwc-button
.label=${this._config.right_button} .label=${this._config.right_button}
></mwc-button> ></mwc-button>
@@ -325,7 +325,7 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
</span> </span>
</footer> </footer>
`:""} `:""}
</ha-card>`:M``}static get styles(){return n` </ha-card>`:I``}static get styles(){return n`
:host { :host {
display: none !important; display: none !important;
} }
@@ -372,4 +372,4 @@ function e(e,t,i,s){var o,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPro
padding: 8px; padding: 8px;
border-top: 1px solid transparent; border-top: 1px solid transparent;
} }
`}}e([ee()],Pe.prototype,"hass",void 0),e([te()],Pe.prototype,"_config",void 0),e([ee({attribute:"edit-mode",reflect:!0})],Pe.prototype,"editMode",void 0),e([te()],Pe.prototype,"_element",void 0),(async()=>{for(;!window.browser_mod;)await new Promise((e=>setTimeout(e,1e3)));await window.browser_mod.connectionPromise,customElements.get("popup-card")||customElements.define("popup-card",Pe)})();const Ie=e=>class extends e{constructor(){super(),this.__currentTitle=void 0,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()),1e3),setTimeout((()=>this._updateTitle()),5e3)}))}async _auto_settings_setup(){await this.connectionPromise;const e=this.settings;e.sidebarPanelOrder&&localStorage.setItem("sidebarPanelOrder",e.sidebarPanelOrder),e.sidebarHiddenPanels&&localStorage.setItem("sidebarHiddenPanels",e.sidebarHiddenPanels),e.defaultPanel&&localStorage.setItem("defaultPanel",e.defaultPanel),!0===e.hideSidebar&&(de(document.body,"home-assistant$home-assistant-main$app-drawer-layout").then((e=>{var t;return null===(t=null==e?void 0:e.style)||void 0===t?void 0:t.setProperty("--app-drawer-width","0px")})),de(document.body,"home-assistant$home-assistant-main$app-drawer-layout app-drawer").then((e=>{var t;return null===(t=null==e?void 0:e.remove)||void 0===t?void 0:t.call(e)}))),!0===e.hideHeader&&customElements.whenDefined("app-header-layout").then((()=>{const e=customElements.get("app-header").prototype,t=e.attached;e.attached=function(){t.bind(this)(),this.style.setProperty("display","none")}})),void 0!==e.faviconTemplate&&(async()=>{this._faviconTemplateSubscription&&this._faviconTemplateSubscription(),this._faviconTemplateSubscription=void 0,this._faviconTemplateSubscription=await this.connection.subscribeMessage(this._updateFavicon,{type:"render_template",template:e.faviconTemplate,variables:{}})})(),void 0!==e.titleTemplate&&(async()=>{this._titleTemplateSubscription&&this._titleTemplateSubscription(),this._titleTemplateSubscription=void 0,this._titleTemplateSubscription=await this.connection.subscribeMessage(this._updateTitle.bind(this),{type:"render_template",template:e.titleTemplate,variables:{}})})()}get _currentFavicon(){const e=document.head.querySelector("link[rel~='icon']");return null==e?void 0:e.href}_updateFavicon({result:e}){document.head.querySelector("link[rel~='icon']").href=e,window.browser_mod.fireEvent("browser-mod-favicon-update")}get _currentTitle(){return this.__currentTitle}_updateTitle(e){e&&(this.__currentTitle=e.result),this.__currentTitle&&(document.title=this.__currentTitle),window.browser_mod.fireEvent("browser-mod-favicon-update")}},Me="browser_mod-browser-id",Oe=e=>class extends e{constructor(){if(super(),Storage&&!Storage.prototype.browser_mod_patched){const e=Storage.prototype.clear;Storage.prototype.clear=function(){const t=this.getItem(Me),i=this.getItem("suspendWhenHidden");e.apply(this),this.setItem(Me,t),this.setItem("suspendWhenHidden",i)},Storage.prototype.browser_mod_patched=!0}}async recall_id(){if(!this.connection)return;const e=await this.connection.sendMessagePromise({type:"browser_mod/recall_id"});e&&(localStorage[Me]=e)}get browserID(){return document.querySelector("hc-main")?"CAST":localStorage[Me]?localStorage[Me]:(this.browserID="",this.recall_id(),this.browserID)}set browserID(e){""===e&&(e=function(){var e,t;const i=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);return null!==(t=null===(e=window.fully)||void 0===e?void 0:e.getDeviceId())&&void 0!==t?t:`${i()}${i()}-${i()}${i()}`}());const t=localStorage[Me];localStorage[Me]=e,this.browserIDChanged(t,e)}browserIDChanged(e,t){}};class Le extends(ye(Se(fe(be(_e(me(ve(Ie(we(ge(pe(Oe(EventTarget))))))))))))){constructor(){super(),this.connect(),console.info(`%cBROWSER_MOD ${Ce} IS INSTALLED\n %cBrowserID: ${this.browserID}`,"color: green; font-weight: bold","")}}window.browser_mod||(window.browser_mod=new Le);export{Le as BrowserMod}; `}}e([ee()],Oe.prototype,"hass",void 0),e([te()],Oe.prototype,"_config",void 0),e([ee({attribute:"edit-mode",reflect:!0})],Oe.prototype,"editMode",void 0),e([te()],Oe.prototype,"_element",void 0),(async()=>{for(;!window.browser_mod;)await new Promise((e=>setTimeout(e,1e3)));await window.browser_mod.connectionPromise,customElements.get("popup-card")||customElements.define("popup-card",Oe)})();const Ie=t=>{class i extends t{constructor(){super(),this.__currentTitle=void 0;const e=async()=>{this.runUpdateTitle(),this.runHideHeader()};this._auto_settings_setup(),this.addEventListener("browser-mod-config-update",(()=>{this._auto_settings_setup(),e()})),window.addEventListener("location-changed",e)}async runHideHeader(){for(;!await this._hideHeader();)await new Promise((e=>setTimeout(e,500)))}async runUpdateTitle(){await async function(e,t,i){for(;t--;)e(),await new Promise((e=>setTimeout(e,i)))}((()=>this._updateTitle()),3,500)}async _auto_settings_setup(){await this.connectionPromise;const e=this.settings;e.sidebarPanelOrder&&localStorage.setItem("sidebarPanelOrder",e.sidebarPanelOrder),e.sidebarHiddenPanels&&localStorage.setItem("sidebarHiddenPanels",e.sidebarHiddenPanels),e.defaultPanel&&localStorage.setItem("defaultPanel",`"${e.defaultPanel}"`),!0===e.hideSidebar&&(de(document.body,"home-assistant$home-assistant-main$app-drawer-layout").then((e=>{var t;return null===(t=null==e?void 0:e.style)||void 0===t?void 0:t.setProperty("--app-drawer-width","0px")})),de(document.body,"home-assistant$home-assistant-main$app-drawer-layout app-drawer").then((e=>{var t;return null===(t=null==e?void 0:e.remove)||void 0===t?void 0:t.call(e)}))),e.sidebarTitle&&de(document,"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar $ .title").then((t=>{t&&(t.innerHTML=e.sidebarTitle)})),void 0!==e.faviconTemplate&&(async()=>{this._faviconTemplateSubscription&&this._faviconTemplateSubscription(),this._faviconTemplateSubscription=void 0,this._faviconTemplateSubscription=await this.connection.subscribeMessage(this._updateFavicon,{type:"render_template",template:e.faviconTemplate,variables:{}})})(),void 0!==e.titleTemplate&&(async()=>{this._titleTemplateSubscription&&this._titleTemplateSubscription(),this._titleTemplateSubscription=void 0,this._titleTemplateSubscription=await this.connection.subscribeMessage(this._updateTitle.bind(this),{type:"render_template",template:e.titleTemplate,variables:{}})})()}get _currentFavicon(){const e=document.head.querySelector("link[rel~='icon']");return null==e?void 0:e.href}_updateFavicon({result:e}){document.head.querySelector("link[rel~='icon']").href=e}get _currentTitle(){return this.__currentTitle}_updateTitle(e){e&&(this.__currentTitle=e.result),this.__currentTitle&&(document.title=this.__currentTitle)}async _hideHeader(){var e,t;if(!0!==this.settings.hideHeader)return!0;let i=await de(document,"home-assistant $ home-assistant-main $ app-drawer-layout partial-panel-resolver");if(!i)return!1;let s=0;for(;i&&"ha-app-layout"!==i.localName&&s++<5;){await re(i,!0);const s=null!==(t=null!==(e=i.querySelector("ha-app-layout"))&&void 0!==e?e:i.firstElementChild)&&void 0!==t?t:i.shadowRoot;i=s}return"ha-app-layout"===(null==i?void 0:i.localName)&&(!!i.header&&(i.header.style.setProperty("display","none"),setTimeout((()=>i._updateLayoutStates()),0),!0))}getSetting(e){var t,i,s,o;const n={global:void 0,browser:{},user:{}};n.global=null===(t=this._data.settings)||void 0===t?void 0:t[e];for(const[t,o]of Object.entries(null!==(i=this._data.browsers)&&void 0!==i?i:{}))null!=(null===(s=o.settings)||void 0===s?void 0:s[e])&&(n.browser[t]=o.settings[e]);for(const[t,i]of Object.entries(null!==(o=this._data.user_settings)&&void 0!==o?o:{}))null!=i[e]&&(n.user[t]=i[e]);return n}setSetting(e,t,i){if("global"===e)for(const[e,t]of Object.entries(i))this.connection.sendMessage({type:"browser_mod/settings",key:e,value:t});else if("browser"===e){const e=this._data.browsers[t],s=Object.assign(Object.assign({},e.settings),i);console.log(s),this.connection.sendMessage({type:"browser_mod/register",browserID:t,data:Object.assign(Object.assign({},e),{settings:s})})}else if("user"===e){const e=t;for(const[t,s]of Object.entries(i))this.connection.sendMessage({type:"browser_mod/settings",user:e,key:t,value:s})}}}return e([pe()],i.prototype,"runHideHeader",null),e([pe(!0)],i.prototype,"runUpdateTitle",null),i},Me="browser_mod-browser-id",Le=e=>class extends e{constructor(){if(super(),Storage&&!Storage.prototype.browser_mod_patched){const e=Storage.prototype.clear;Storage.prototype.clear=function(){const t=this.getItem(Me),i=this.getItem("suspendWhenHidden");e.apply(this),this.setItem(Me,t),this.setItem("suspendWhenHidden",i)},Storage.prototype.browser_mod_patched=!0}}async recall_id(){if(!this.connection)return;const e=await this.connection.sendMessagePromise({type:"browser_mod/recall_id"});e&&(localStorage[Me]=e)}get browserID(){return document.querySelector("hc-main")?"CAST":localStorage[Me]?localSto Line truncated
+143 -157
View File
@@ -1,14 +1,14 @@
function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(n=(r<3?o(n):r>3?o(t,i,n):o(t,i))||n);return r>3&&n&&Object.defineProperty(t,i,n),n}const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),s=new WeakMap;class o{constructor(e,t,s){if(this._$cssResult$=!0,s!==i)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const i=this.t;if(t&&void 0===e){const t=void 0!==i&&1===i.length;t&&(e=s.get(i)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),t&&s.set(i,e))}return e}toString(){return this.cssText}}const r=(e,...t)=>{const s=1===e.length?e[0]:t.reduce(((t,i,s)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+e[s+1]),e[0]);return new o(s,e,i)},n=t?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return(e=>new o("string"==typeof e?e:e+"",void 0,i))(t)})(e):e;var a;const l=window.trustedTypes,d=l?l.emptyScript:"",h=window.reactiveElementPolyfillSupport,c={toAttribute(e,t){switch(t){case Boolean:e=e?d:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let i=e;switch(t){case Boolean:i=null!==e;break;case Number:i=null===e?null:Number(e);break;case Object:case Array:try{i=JSON.parse(e)}catch(e){i=null}}return i}},u=(e,t)=>t!==e&&(t==t||e==e),p={attribute:!0,type:String,converter:c,reflect:!1,hasChanged:u};class w extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(e){var t;null!==(t=this.h)&&void 0!==t||(this.h=[]),this.h.push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,i)=>{const s=this._$Ep(i,t);void 0!==s&&(this._$Ev.set(s,i),e.push(s))})),e}static createProperty(e,t=p){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const i="symbol"==typeof e?Symbol():"__"+e,s=this.getPropertyDescriptor(e,i,t);void 0!==s&&Object.defineProperty(this.prototype,e,s)}}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(s){const o=this[e];this[t]=s,this.requestUpdate(e,o,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||p}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const i of t)this.createProperty(i,e[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const i=new Set(e.flat(1/0).reverse());for(const e of i)t.unshift(n(e))}else void 0!==e&&t.push(n(e));return t}static _$Ep(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}u(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,i;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(i=e.hostConnected)||void 0===i||i.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const i=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,i)=>{t?e.adoptedStyleSheets=i.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):i.forEach((t=>{const i=document.createElement("style"),s=window.litNonce;void 0!==s&&i.setAttribute("nonce",s),i.textContent=t.cssText,e.appendChild(i)}))})(i,this.constructor.elementStyles),i}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,i){thisLine truncated function e(e,t,s,i){var o,n=arguments.length,r=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,s,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(r=(n<3?o(r):n>3?o(t,s,r):o(t,s))||r);return n>3&&r&&Object.defineProperty(t,s,r),r}const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),i=new WeakMap;class o{constructor(e,t,i){if(this._$cssResult$=!0,i!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const s=this.t;if(t&&void 0===e){const t=void 0!==s&&1===s.length;t&&(e=i.get(s)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),t&&i.set(s,e))}return e}toString(){return this.cssText}}const n=(e,...t)=>{const i=1===e.length?e[0]:t.reduce(((t,s,i)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+e[i+1]),e[0]);return new o(i,e,s)},r=t?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const s of e.cssRules)t+=s.cssText;return(e=>new o("string"==typeof e?e:e+"",void 0,s))(t)})(e):e;var a;const l=window.trustedTypes,d=l?l.emptyScript:"",h=window.reactiveElementPolyfillSupport,c={toAttribute(e,t){switch(t){case Boolean:e=e?d:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let s=e;switch(t){case Boolean:s=null!==e;break;case Number:s=null===e?null:Number(e);break;case Object:case Array:try{s=JSON.parse(e)}catch(e){s=null}}return s}},u=(e,t)=>t!==e&&(t==t||e==e),p={attribute:!0,type:String,converter:c,reflect:!1,hasChanged:u};class w extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(e){var t;null!==(t=this.h)&&void 0!==t||(this.h=[]),this.h.push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,s)=>{const i=this._$Ep(s,t);void 0!==i&&(this._$Ev.set(i,s),e.push(i))})),e}static createProperty(e,t=p){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const s="symbol"==typeof e?Symbol():"__"+e,i=this.getPropertyDescriptor(e,s,t);void 0!==i&&Object.defineProperty(this.prototype,e,i)}}static getPropertyDescriptor(e,t,s){return{get(){return this[t]},set(i){const o=this[e];this[t]=i,this.requestUpdate(e,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||p}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const s of t)this.createProperty(s,e[s])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const s=new Set(e.flat(1/0).reverse());for(const e of s)t.unshift(r(e))}else void 0!==e&&t.push(r(e));return t}static _$Ep(e,t){const s=t.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof e?e.toLowerCase():void 0}u(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,s;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(s=e.hostConnected)||void 0===s||s.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const s=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,s)=>{t?e.adoptedStyleSheets=s.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):s.forEach((t=>{const s=document.createElement("style"),i=window.litNonce;void 0!==i&&s.setAttribute("nonce",i),s.textContent=t.cssText,e.appendChild(s)}))})(s,this.constructor.elementStyles),s}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,s){thisLine truncated
<ha-card outlined> <ha-card outlined>
<h1 class="card-header"> <h1 class="card-header">
<div class="name">This Browser</div> <div class="name">This Browser</div>
${(null===(e=window.browser_mod)||void 0===e?void 0:e.connected)?H` ${(null===(e=window.browser_mod)||void 0===e?void 0:e.connected)?k`
<ha-icon <ha-icon
class="icon" class="icon"
.icon=${"mdi:check-circle-outline"} .icon=${"mdi:check-circle-outline"}
style="color: var(--success-color, green);" style="color: var(--success-color, green);"
></ha-icon> ></ha-icon>
`:H` `:k`
<ha-icon <ha-icon
class="icon" class="icon"
.icon=${"mdi:circle-outline"} .icon=${"mdi:circle-outline"}
@@ -17,7 +17,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
`} `}
</h1> </h1>
<div class="card-content"> <div class="card-content">
${this.dirty?H` ${this.dirty?k`
<ha-alert alert-type="warning"> <ha-alert alert-type="warning">
It is strongly recommended to refresh your browser window It is strongly recommended to refresh your browser window
after changing any of the settings in this box. after changing any of the settings in this box.
@@ -42,12 +42,12 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
>A unique identifier for this browser-device combination.</span >A unique identifier for this browser-device combination.</span
> >
<ha-textfield <ha-textfield
.value=${null===(i=window.browser_mod)||void 0===i?void 0:i.browserID} .value=${null===(s=window.browser_mod)||void 0===s?void 0:s.browserID}
@change=${this.changeBrowserID} @change=${this.changeBrowserID}
></ha-textfield> ></ha-textfield>
</ha-settings-row> </ha-settings-row>
${(null===(s=window.browser_mod)||void 0===s?void 0:s.registered)?H` ${(null===(i=window.browser_mod)||void 0===i?void 0:i.registered)?k`
${this._renderSuspensionAlert()} ${this._renderSuspensionAlert()}
<ha-settings-row> <ha-settings-row>
<span slot="heading">Enable camera</span> <span slot="heading">Enable camera</span>
@@ -60,7 +60,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
@change=${this.toggleCameraEnabled} @change=${this.toggleCameraEnabled}
></ha-switch> ></ha-switch>
</ha-settings-row> </ha-settings-row>
${(null===(r=window.browser_mod)||void 0===r?void 0:r.cameraError)?H` ${(null===(n=window.browser_mod)||void 0===n?void 0:n.cameraError)?k`
<ha-alert alert-type="error"> <ha-alert alert-type="error">
Setting up the device camera failed. Make sure you have Setting up the device camera failed. Make sure you have
allowed use of the camera in your browser. allowed use of the camera in your browser.
@@ -71,7 +71,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
`:""} `:""}
</div> </div>
</ha-card> </ha-card>
`}_renderSuspensionAlert(){return this.hass.suspendWhenHidden?H` `}_renderSuspensionAlert(){return this.hass.suspendWhenHidden?k`
<ha-alert alert-type="warning" title="Auto closing connection"> <ha-alert alert-type="warning" title="Auto closing connection">
Home Assistant will close the websocket connection to the server Home Assistant will close the websocket connection to the server
automatically after 5 minutes of inactivity.<br /><br /> automatically after 5 minutes of inactivity.<br /><br />
@@ -88,9 +88,9 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
and disabling the option and disabling the option
"${this.hass.localize("ui.panel.profile.suspend.header")||"Automatically close connection"}". "${this.hass.localize("ui.panel.profile.suspend.header")||"Automatically close connection"}".
</ha-alert> </ha-alert>
`:H``}_renderInteractionAlert(){return H` `:k``}_renderInteractionAlert(){return k`
<ha-alert title="Interaction requirement"> <ha-alert title="Interaction requirement">
For security reasons many browsers require the user to interact with a For privacy reasons many browsers require the user to interact with a
webpage before allowing audio playback or video capture. This may affect webpage before allowing audio playback or video capture. This may affect
the the
<code>media_player</code> and <code>camera</code> components of Browser <code>media_player</code> and <code>camera</code> components of Browser
@@ -101,33 +101,33 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
corner of the screen, please tap or click anywhere on the page. This corner of the screen, please tap or click anywhere on the page. This
should allow Browser Mod to work again. should allow Browser Mod to work again.
</ha-alert> </ha-alert>
`}_renderFKBSettingsInfo(){var e,t;return(null===(e=window.browser_mod)||void 0===e?void 0:e.fully)&&this.getFullySettings()?H` `}_renderFKBSettingsInfo(){var e,t;return(null===(e=window.browser_mod)||void 0===e?void 0:e.fully)&&this.getFullySettings()?k`
${(null===(t=window.browser_mod)||void 0===t?void 0:t.fully)&&this.getFullySettings()?H` <ha-alert title="FullyKiosk Browser"> ${(null===(t=window.browser_mod)||void 0===t?void 0:t.fully)&&this.getFullySettings()?k` <ha-alert title="FullyKiosk Browser">
You are using FullyKiosk Browser. It is recommended to enable the You are using FullyKiosk Browser. It is recommended to enable the
following settings: following settings:
<ul> <ul>
${this.getFullySettings()} ${this.getFullySettings()}
</ul> </ul>
</ha-alert>`:""} </ha-alert>`:""}
`:H``}getFullySettings(){if(!window.browser_mod.fully)return null;const e=[],t=[];"true"!==window.fully.getBooleanSetting("autoplayVideos")&&t.push(H`<li>Autoplay Videos</li>`),"true"!==window.fully.getBooleanSetting("autoplayAudio")&&t.push(H`<li>Autoplay Audio</li>`),"true"!==window.fully.getBooleanSetting("webcamAccess")&&t.push(H`<li>Enable Webcam Access (PLUS)</li>`),0!==t.length&&e.push(H`<li>Web Content Settings</li> `:k``}getFullySettings(){if(!window.browser_mod.fully)return null;const e=[],t=[];"true"!==window.fully.getBooleanSetting("autoplayVideos")&&t.push(k`<li>Autoplay Videos</li>`),"true"!==window.fully.getBooleanSetting("autoplayAudio")&&t.push(k`<li>Autoplay Audio</li>`),"true"!==window.fully.getBooleanSetting("webcamAccess")&&t.push(k`<li>Enable Webcam Access (PLUS)</li>`),0!==t.length&&e.push(k`<li>Web Content Settings</li>
<ul> <ul>
${t} ${t}
</ul>`),"true"!==window.fully.getBooleanSetting("websiteIntegration")&&e.push(H`<li>Advanced Web Settings</li> </ul>`),"true"!==window.fully.getBooleanSetting("websiteIntegration")&&e.push(k`<li>Advanced Web Settings</li>
<ul> <ul>
<li>Enable JavaScript Interface (PLUS)</li> <li>Enable JavaScript Interface (PLUS)</li>
</ul>`),"true"!==window.fully.getBooleanSetting("keepScreenOn")&&e.push(H`<li>Device Management</li> </ul>`),"true"!==window.fully.getBooleanSetting("keepScreenOn")&&e.push(k`<li>Device Management</li>
<ul> <ul>
<li>Keep Screen On</li> <li>Keep Screen On</li>
</ul>`),"true"!==window.fully.getBooleanSetting("preventSleepWhileScreenOff")&&e.push(H`<li>Power Settings</li> </ul>`),"true"!==window.fully.getBooleanSetting("preventSleepWhileScreenOff")&&e.push(k`<li>Power Settings</li>
<ul> <ul>
<li>Prevent from Sleep while Screen Off</li> <li>Prevent from Sleep while Screen Off</li>
</ul>`);const i=[];return"true"!==window.fully.getBooleanSetting("motionDetection")&&i.push(H`<li>Enable Visual Motion Detection</li>`),"true"!==window.fully.getBooleanSetting("screenOnOnMotion")&&i.push(H`<li>Turn Screen On on Motion</li>`),"true"!==window.fully.getBooleanSetting("stopScreensaverOnMotion")&&i.push(H`<li>Exit Screensaver on Motion</li>`),0!==i.length&&e.push(H`<li>Motion Detection (PLUS)</li> </ul>`);const s=[];return"true"!==window.fully.getBooleanSetting("motionDetection")&&s.push(k`<li>Enable Visual Motion Detection</li>`),"true"!==window.fully.getBooleanSetting("screenOnOnMotion")&&s.push(k`<li>Turn Screen On on Motion</li>`),"true"!==window.fully.getBooleanSetting("stopScreensaverOnMotion")&&s.push(k`<li>Exit Screensaver on Motion</li>`),0!==s.length&&e.push(k`<li>Motion Detection (PLUS)</li>
<ul> <ul>
${i} ${s}
</ul>`),"true"!==window.fully.getBooleanSetting("remoteAdmin")&&e.push(H`<li>Remote Administration (PLUS)</li> </ul>`),"true"!==window.fully.getBooleanSetting("remoteAdmin")&&e.push(k`<li>Remote Administration (PLUS)</li>
<ul> <ul>
<li>Enable Remote Administration</li> <li>Enable Remote Administration</li>
</ul>`),e.length?e:null}static get styles(){return r` </ul>`),e.length?e:null}static get styles(){return n`
.card-header { .card-header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -137,10 +137,10 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
display: block; display: block;
margin-top: 8px; margin-top: 8px;
} }
`}}e([ee()],ie.prototype,"hass",void 0),e([ee()],ie.prototype,"dirty",void 0),customElements.define("browser-mod-browser-settings-card",ie);class se extends Z{firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.requestUpdate()))}unregister_browser(e){const t=e.currentTarget.browserID;window.browser_mod.showPopup("Unregister browser",`Are you sure you want to unregister Browser ${t}?`,{right_button:"Yes",right_button_action:()=>{t===window.browser_mod.browserID?window.browser_mod.registered=!1:window.browser_mod.connection.sendMessage({type:"browser_mod/unregister",browserID:t})},left_button:"No"})}register_cast(){window.browser_mod.connection.sendMessage({type:"browser_mod/register",browserID:"CAST"})}render(){return H` `}}e([ee()],re.prototype,"hass",void 0),e([ee()],re.prototype,"dirty",void 0),customElements.define("browser-mod-browser-settings-card",re);class ae extends Z{firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.requestUpdate()))}unregister_browser(e){const t=e.currentTarget.browserID;window.browser_mod.showPopup("Unregister browser",`Are you sure you want to unregister Browser ${t}?`,{right_button:"Yes",right_button_action:()=>{t===window.browser_mod.browserID?window.browser_mod.registered=!1:window.browser_mod.connection.sendMessage({type:"browser_mod/unregister",browserID:t})},left_button:"No"})}register_cast(){window.browser_mod.connection.sendMessage({type:"browser_mod/register",browserID:"CAST"})}render(){return k`
<ha-card header="Registered Browsers" outlined> <ha-card header="Registered Browsers" outlined>
<div class="card-content"> <div class="card-content">
${Object.keys(window.browser_mod.browsers).map((e=>H` <ha-settings-row> ${Object.keys(window.browser_mod.browsers).map((e=>k` <ha-settings-row>
<span slot="heading"> ${e} </span> <span slot="heading"> ${e} </span>
<span slot="description"> <span slot="description">
Last connected: Last connected:
@@ -154,7 +154,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
</ha-icon-button> </ha-icon-button>
</ha-settings-row>`))} </ha-settings-row>`))}
</div> </div>
${void 0===window.browser_mod.browsers.CAST?H` ${void 0===window.browser_mod.browsers.CAST?k`
<div class="card-actions"> <div class="card-actions">
<mwc-button @click=${this.register_cast}> <mwc-button @click=${this.register_cast}>
Register CAST Browser Register CAST Browser
@@ -162,19 +162,55 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
</div> </div>
`:""} `:""}
</ha-card> </ha-card>
`}static get styles(){return r` `}static get styles(){return n`
ha-icon-button > * { ha-icon-button > * {
display: flex; display: flex;
} }
`}}e([ee()],se.prototype,"hass",void 0),customElements.define("browser-mod-registered-browsers-card",se),(async()=>{var e,t,i,s,o,r,n;await customElements.whenDefined("partial-panel-resolver"),await customElements.whenDefined("partial-panel-resolver");const a=document.createElement("partial-panel-resolver").getRoutes([{component_name:"developer-tools",url_path:"a"}]);await(null===(i=null===(t=null===(e=null==a?void 0:a.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===i?void 0:i.call(t));const l=document.createElement("developer-tools-router");await(null===(n=null===(r=null===(o=null===(s=null==l?void 0:l.routerOptions)||void 0===s?void 0:s.routes)||void 0===o?void 0:o.template)||void 0===r?void 0:r.load)||void 0===n?void 0:n.call(r)),await customElements.whenDefined("developer-tools-template")})();class oe extends Z{constructor(){super(...arguments),this._selectedTab=0}firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.requestUpdate())),window.browser_mod.addEventListener("browser-mod-favicon-update",(()=>this.requestUpdate()))}_handleSwitchTab(e){this._selectedTab=parseInt(e.detail.index,10)}render(){const e=["user","browser","global"][this._selectedTab];return H` `}}e([ee()],ae.prototype,"hass",void 0),customElements.define("browser-mod-registered-browsers-card",ae);class le extends Z{constructor(){super(...arguments),this.settingSelector={template:{}},this.tableData=[],this._users=void 0}firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.updateTable()))}updated(e){e.has("settingKey")&&this.updateTable(),e.has("hass")&&void 0===e.get("hass")&&this.updateTable()}async fetchUsers(){return void 0===this._users&&(this._users=await this.hass.callWS({type:"config/auth/list"})),this._users}clearSetting(e,t){var s;null===(s=window.browser_mod)||void 0===s||s.showPopup("Are you sure","Do you wish to clear this setting?",{right_button:"Yes",right_button_action:async()=>{if("sidebarPanelOrder"===this.settingKey)return await ne(document,"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar"),window.browser_mod.setSetting(e,t,{sidebarHiddenPanels:"[]",sidebarPanelOrder:"[]"}),void window.browser_mod.setSetting(e,t,{sidebarHiddenPanels:void 0,sidebarPanelOrder:void 0});this.default&&window.browser_mod.setSetting(e,t,{[this.settingKey]:this.default}),window.browser_mod.setSetting(e,t,{[this.settingKey]:void 0})},left_button:"No"})}changeSetting(e,t){var s,i,o,n,r,a;const l=null===(i=null===(s=window.browser_mod)||void 0===s?void 0:s.getSetting)||void 0===i?void 0:i.call(s,this.settingKey),d=null!==(o="global"===e?l.global:l[e][t])&&void 0!==o?o:this.default;null===(n=window.browser_mod)||void 0===n||n.showPopup("Change value",null!==(r=this.settingSelector.plaintext)&&void 0!==r?r:[{name:"value",label:null!==(a=this.settingSelector.label)&&void 0!==a?a:"",default:d,selector:this.settingSelector}],{right_button:"OK",right_button_action:async s=>{if("sidebarPanelOrder"===this.settingKey){const s=await ne(document,"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar");return window.browser_mod.setSetting(e,t,{sidebarHiddenPanels:JSON.stringify(s._hiddenPanels),sidebarPanelOrder:JSON.stringify(s._panelOrder)}),void console.log(s._hiddenPanels,s._panelOrder)}let i=s.value;window.browser_mod.setSetting(e,t,{[this.settingKey]:i})},left_button:"Cancel"})}addBrowserSetting(){var e,t;const s=null===(t=null===(e=window.browser_mod)||void 0===e?void 0:e.getSetting)||void 0===t?void 0:t.call(e,this.settingKey),i=window.browser_mod._data.browsers,o=[];for(const e of Object.keys(i))null==s.browser[e]&&o.push(e);0!==o.length?window.browser_mod.showPopup("Select browser to configure",[{name:"browser",label:"",selector:{select:{options:o}}}],{right_button:"Next",right_button_action:e=>this.changeSetting("browser",e.browser),left_button:"Cancel"}):window.browser_mod.showPopup("No browsers to configure","All registered browsers have already been configured.",{right_button:"OK"})}async addUserSetting(){var e,t;const s=null===(t=null===(e=window.browser_mod)||void 0===e?void 0:e.getSetting)||void 0===t?void 0:t.call(e,this.settingKey),i=await this.fetchUsers(),o=[];for(const e of i)e.username&&null==s.user[e.id]&&o.push({label:e.name,value:e.id});0!==o.length?window.browser_mod.showPopup("Select user to configure",[{name:"user",label:"",selector:{select:{options:o}}}],{right_button:"Next",right_button_action:e=>this.changeSetting("user",e.user),left_button:"Cancel"}):window.browser_mod.showPopup("No users to configure","All users have already been configured.",{right_button:"OK"})}async updateTable(){var e,t;if(void 0===this.hass)return;const s=await this.fetchUsers(),i=null===(t=null===(e=window.browser_mod)||void 0===e?void 0:e.getSetting)||void 0===t?void 0:t.call(e,this.settingKey),o=[];for(const[e,t]of Object.entries(i.user)){const i=s.find((t=>t.id===e));o.push({name:`User: ${i.name}`,value:String(t),controls:k`
<ha-icon-button @click=${()=>this.changeSetting("user",e)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${()=>this.clearSetting("user",e)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`})}o.push({name:"",value:k`
<mwc-button @click=${()=>this.addUserSetting()}>
<ha-icon .icon=${"mdi:plus"}></ha-icon>
Add user setting
</mwc-button>
`});for(const[e,t]of Object.entries(i.browser))o.push({name:`Browser: ${e}`,value:String(t),controls:k`
<ha-icon-button @click=${()=>this.changeSetting("browser",e)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${()=>this.clearSetting("browser",e)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`});o.push({name:"",value:k`
<mwc-button @click=${()=>this.addBrowserSetting()}>
<ha-icon .icon=${"mdi:plus"}></ha-icon>
Add browser setting
</mwc-button>
`}),o.push({name:"GLOBAL",value:null!=i.global?String(i.global):k`<span style="color: var(--warning-color);">DEFAULT</span>`,controls:k`
<ha-icon-button @click=${()=>this.changeSetting("global",null)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${()=>this.clearSetting("global",null)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`}),this.tableData=o}render(){var e,t;null===(t=null===(e=window.browser_mod)||void 0===e?void 0:e.global_settings)||void 0===t||t[this.settingKey];return k`
<ha-data-table .columns=${{name:{title:"Name",grows:!0},value:{title:"Value",grows:!0},controls:{}}} .data=${this.tableData} auto-height>
</ha-data-table>
`}static get styles(){return n`
:host {
display: block;
}
`}}e([ee()],le.prototype,"settingKey",void 0),e([ee()],le.prototype,"settingSelector",void 0),e([ee()],le.prototype,"hass",void 0),e([ee()],le.prototype,"default",void 0),e([ee()],le.prototype,"tableData",void 0),customElements.define("browser-mod-settings-table",le),(async()=>{var e,t,s,i,o,n,r;await customElements.whenDefined("partial-panel-resolver"),await customElements.whenDefined("partial-panel-resolver");const a=document.createElement("partial-panel-resolver").getRoutes([{component_name:"developer-tools",url_path:"a"}]);await(null===(s=null===(t=null===(e=null==a?void 0:a.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===s?void 0:s.call(t));const l=document.createElement("developer-tools-router");await(null===(r=null===(n=null===(o=null===(i=null==l?void 0:l.routerOptions)||void 0===i?void 0:i.routes)||void 0===o?void 0:o.template)||void 0===n?void 0:n.load)||void 0===r?void 0:r.call(n)),await customElements.whenDefined("developer-tools-template")})();class de extends Z{constructor(){super(...arguments),this._dashboards=[],this._editSidebar=!1,this._savedSidebar={panelOrder:[],hiddenPanels:[]}}firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.requestUpdate()))}updated(e){e.has("hass")&&void 0===e.get("hass")&&(async()=>{this._dashboards=await this.hass.callWS({type:"lovelace/dashboards/list"})})()}async toggleEditSidebar(){var e,t;const s=await ne(document,"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar");s.editMode=!s.editMode,this._editSidebar=s.editMode,this._editSidebar?this._savedSidebar={panelOrder:s._panelOrder,hiddenPanels:s._hiddenPanels}:(s._panelOrder=null!==(e=this._savedSidebar.panelOrder)&&void 0!==e?e:[],s._hiddenPanels=null!==(t=this._savedSidebar.hiddenPanels)&&void 0!==t?t:[],this._savedSidebar={panelOrder:[],hiddenPanels:[]})}render(){const e=this._dashboards.map((e=>({value:e.url_path,label:e.title}))),t={select:{options:[{value:"lovelace",label:"lovelace (default)"},...e],custom_value:!0}};return k`
<ha-card header="Frontend Settings" outlined> <ha-card header="Frontend Settings" outlined>
<div class="card-content"> <div class="card-content">
<ha-alert alert-type="warning"> <ha-alert alert-type="warning" title="Please note:">
<p> The settings in this section 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 Assistant frontend works and looks. It is very easy to forget that
you made a setting here when you switch devices or user. you made a setting here when you switch devices or user.
</p>
<p> <p>
Do not report any issues to Home Assistant before clearing Do not report any issues to Home Assistant before clearing
<b>EVERY</b> setting here and thouroghly clearing all your browser <b>EVERY</b> setting here and thouroghly clearing all your browser
@@ -183,175 +219,125 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
</p> </p>
</ha-alert> </ha-alert>
<p> <p>
Global settings are applied for all users and browsers.</br> Settings below are applied by first match. I.e. if a matching User
User settings are applied to the current user and overrides any Global settings.</br> setting exists, it will be applied. Otherwise any matching Browser
Browser settings are applied for the current browser and overrides any User or Global settings. setting and otherwise the GLOBAL setting if that differs from
DEFAULT.
</p> </p>
<mwc-tab-bar
.activeIndex=${this._selectedTab}
@MDCTabBar:activated=${this._handleSwitchTab}
>
<mwc-tab .label=${"User ("+this.hass.user.name+")"}></mwc-tab>
<ha-icon .icon=${"mdi:chevron-double-right"}></ha-icon>
<mwc-tab .label=${"Browser"}></mwc-tab>
<ha-icon .icon=${"mdi:chevron-double-right"}></ha-icon>
<mwc-tab .label=${"Global"}></mwc-tab>
</mwc-tab-bar>
${this._render_settings(e)}
</div>
</ha-card>
`}_render_settings(e){const t=window.browser_mod.global_settings,i=window.browser_mod.browser_settings,s=window.browser_mod.user_settings,o={global:t,browser:i,user:s}[e],r=e=>({true:"Enabled",false:"Disabled",undefined:"Unset"}[String(e)]),n=e=>void 0===e?"Unset":"Set",a=t=>"browser"!==e&&void 0!==i[t]?H`<br />Overridden by browser setting`:"global"===e&&void 0!==s[t]?H`<br />Overridden by user setting`:void 0;return H`
<div class="box">
<ha-settings-row>
<span slot="heading">Favicon template</span>
${a("faviconTemplate")}
<img src="${window.browser_mod._currentFavicon}" class="favicon" />
</ha-settings-row>
<ha-code-editor
.hass=${this.hass}
.value=${o.faviconTemplate}
@value-changed=${t=>{const i=t.detail.value||void 0;window.browser_mod.set_setting("faviconTemplate",i,e)}}
></ha-code-editor>
<ha-settings-row>
<mwc-button
@click=${()=>window.browser_mod.set_setting("faviconTemplate",void 0,e)}
>
Clear
</mwc-button>
</ha-settings-row>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Title template</span> <span slot="heading">Title template</span>
${a("titleTemplate")} <span slot="description">
Jinja template for the browser window/tab title
</span>
</ha-settings-row> </ha-settings-row>
<ha-code-editor <browser-mod-settings-table
.hass=${this.hass} .hass=${this.hass}
.value=${o.titleTemplate} .settingKey=${"titleTemplate"}
@value-changed=${t=>{const i=t.detail.value||void 0;window.browser_mod.set_setting("titleTemplate",i,e)}} ></browser-mod-settings-table>
></ha-code-editor>
<ha-settings-row>
<mwc-button
@click=${()=>window.browser_mod.set_setting("titleTemplate",void 0,e)}
>
Clear
</mwc-button>
</ha-settings-row>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Hide Sidebar</span> <span slot="heading">Favicon template</span>
<span slot="description">Hide the sidebar and hamburger menu</span> <span slot="description">
Currently: ${r(o.hideSidebar)} Jinja template for the browser favicon
${a("hideSidebar")} </span>
</ha-settings-row>
<ha-settings-row>
<mwc-button
@click=${()=>window.browser_mod.set_setting("hideSidebar",!0,e)}
>
Enable
</mwc-button>
<mwc-button
@click=${()=>window.browser_mod.set_setting("hideSidebar",!1,e)}
>
Disable
</mwc-button>
<mwc-button
@click=${()=>window.browser_mod.set_setting("hideSidebar",void 0,e)}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"faviconTemplate"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Hide Header</span> <span slot="heading">Hide sidebar</span>
<span slot="description">Hide the header on all pages</span> <span slot="description">
Currently: ${r(o.hideHeader)} Completely remove the sidebar from all panels
${a("hideHeader")} </span>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"hideSidebar"}
.settingSelector=${{boolean:{},label:"Hide sidebar"}}
></browser-mod-settings-table>
<div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<mwc-button <span slot="heading">Hide header</span>
@click=${()=>window.browser_mod.set_setting("hideHeader",!0,e)} <span slot="description">
> Completely remove the header from all panels
Enable </span>
</mwc-button>
<mwc-button
@click=${()=>window.browser_mod.set_setting("hideHeader",!1,e)}
>
Disable
</mwc-button>
<mwc-button
@click=${()=>window.browser_mod.set_setting("hideHeader",void 0,e)}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"hideHeader"}
.settingSelector=${{boolean:{},label:"Hide header"}}
></browser-mod-settings-table>
<div class="separator"></div>
<ha-settings-row>
<span slot="heading">Default dashboard</span>
<span slot="description">
The dashboard that is showed when navigating to
${location.origin}/
</span>
</ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"defaultPanel"}
.settingSelector=${t}
.default=${"lovelace"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Sidebar order</span> <span slot="heading">Sidebar order</span>
<span slot="description"> <span slot="description">
Order and visibility of sidebar buttons Order and visibility of sidebar items. <br />Click EDIT and set
the sidebar up as you want. Then save the settings and finally
click RESTORE.
</span> </span>
Currently: ${n(o.sidebarPanelOrder)} <mwc-button @click=${()=>this.toggleEditSidebar()}>
${a("sidebarPanelOrder")} ${this._editSidebar?"Restore":"Edit"}
</ha-settings-row>
<ha-settings-row>
<span slot="description">
Clearing this does NOT restore the original default order.
</span>
<mwc-button
@click=${()=>{window.browser_mod.set_setting("sidebarPanelOrder",localStorage.getItem("sidebarPanelOrder"),e),window.browser_mod.set_setting("sidebarHiddenPanels",localStorage.getItem("sidebarHiddenPanels"),e)}}
>
Set
</mwc-button>
<mwc-button
@click=${()=>{window.browser_mod.set_setting("sidebarPanelOrder",void 0,e),window.browser_mod.set_setting("sidebarHiddenPanels",void 0,e)}}
>
Clear
</mwc-button> </mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"sidebarPanelOrder"}
.settingSelector=${{plaintext:"Press OK to store the current sidebar order"}}
.default=${"lovelace"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Default dashboard</span> <span slot="heading">Sidebar title</span>
<span slot="description"
>The dashboard that's displayed by default</span
>
Currently: ${n(o.defaultPanel)}
${a("defaultPanel")}
</ha-settings-row>
<ha-settings-row>
<span slot="description"> <span slot="description">
Clearing this does NOT restore the original default dashboard. The title at the top of the sidebar
</span> </span>
<mwc-button
@click=${()=>{window.browser_mod.set_setting("defaultPanel",localStorage.getItem("defaultPanel"),e)}}
>
Set
</mwc-button>
<mwc-button
@click=${()=>{window.browser_mod.set_setting("defaultPanel",void 0,e)}}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"sidebarTitle"}
.settingSelector=${{text:{}}}
></browser-mod-settings-table>
</div> </div>
`}static get styles(){return r` </ha-card>
`}static get styles(){return n`
.box { .box {
border: 1px solid var(--divider-color); border: 1px solid var(--divider-color);
padding: 8px; padding: 8px;
} }
.separator { .separator {
border-bottom: 1px solid var(--divider-color); border-bottom: 1px solid var(--divider-color);
margin: 0 -8px; margin: 16px -16px 0px;
} }
img.favicon { img.favicon {
width: 64px; width: 64px;
@@ -362,7 +348,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
display: flex; display: flex;
align-items: center; align-items: center;
} }
`}}e([ee()],oe.prototype,"hass",void 0),e([function(e){return ee({...e,state:!0})}()],oe.prototype,"_selectedTab",void 0),customElements.define("browser-mod-frontend-settings-card",oe),(async()=>{var e,t,i,s,o,r,n,a,l,d,h;await customElements.whenDefined("partial-panel-resolver");const c=document.createElement("partial-panel-resolver").getRoutes([{component_name:"config",url_path:"a"}]);await(null===(i=null===(t=null===(e=null==c?void 0:c.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===i?void 0:i.call(t)),await customElements.whenDefined("ha-panel-config");const u=document.createElement("ha-panel-config");await(null===(n=null===(r=null===(o=null===(s=null==u?void 0:u.routerOptions)||void 0===s?void 0:s.routes)||void 0===o?void 0:o.dashboard)||void 0===r?void 0:r.load)||void 0===n?void 0:n.call(r)),await(null===(h=null===(d=null===(l=null===(a=null==u?void 0:u.routerOptions)||void 0===a?void 0:a.routes)||void 0===l?void 0:l.cloud)||void 0===d?void 0:d.load)||void 0===h?void 0:h.call(d)),await customElements.whenDefined("ha-config-dashboard")})().then((()=>{class t extends Z{firstUpdated(){window.browser_mod.addEventListener("browser-mod-config-update",(()=>this.requestUpdate()))}render(){return H` `}}e([ee()],de.prototype,"hass",void 0),e([te()],de.prototype,"_dashboards",void 0),e([te()],de.prototype,"_editSidebar",void 0),customElements.define("browser-mod-frontend-settings-card",de),(async()=>{var e,t,s,i,o,n,r,a,l,d,h,c,u,p,w;await customElements.whenDefined("partial-panel-resolver");const g=document.createElement("partial-panel-resolver").getRoutes([{component_name:"config",url_path:"a"}]);await(null===(s=null===(t=null===(e=null==g?void 0:g.routes)||void 0===e?void 0:e.a)||void 0===t?void 0:t.load)||void 0===s?void 0:s.call(t)),await customElements.whenDefined("ha-panel-config");const v=document.createElement("ha-panel-config");await(null===(r=null===(n=null===(o=null===(i=null==v?void 0:v.routerOptions)||void 0===i?void 0:i.routes)||void 0===o?void 0:o.dashboard)||void 0===n?void 0:n.load)||void 0===r?void 0:r.call(n)),await(null===(h=null===(d=null===(l=null===(a=null==v?void 0:v.routerOptions)||void 0===a?void 0:a.routes)||void 0===l?void 0:l.cloud)||void 0===d?void 0:d.load)||void 0===h?void 0:h.call(d)),await(null===(w=null===(p=null===(u=null===(c=null==v?void 0:v.routerOptions)||void 0===c?void 0:c.routes)||void 0===u?void 0:u.entities)||void 0===p?void 0:p.load)||void 0===w?void 0:w.call(p)),await customElements.whenDefined("ha-config-dashboard")})().then((()=>{class t extends Z{firstUpdated(){window.addEventListener("browser-mod-config-update",(()=>this.requestUpdate()))}render(){return window.browser_mod?k`
<ha-app-layout> <ha-app-layout>
<app-header slot="header" fixed> <app-header slot="header" fixed>
<app-toolbar> <app-toolbar>
@@ -388,7 +374,7 @@ function e(e,t,i,s){var o,r=arguments.length,n=r<3?t:null===s?s=Object.getOwnPro
></browser-mod-frontend-settings-card> ></browser-mod-frontend-settings-card>
</ha-config-section> </ha-config-section>
</ha-app-layout> </ha-app-layout>
`}static get styles(){var e,t;return[...null!==(t=null===(e=customElements.get("ha-config-dashboard"))||void 0===e?void 0:e.styles)&&void 0!==t?t:[],r` `:k``}static get styles(){var e,t;return[...null!==(t=null===(e=customElements.get("ha-config-dashboard"))||void 0===e?void 0:e.styles)&&void 0!==t?t:[],n`
:host { :host {
--app-header-background-color: var(--sidebar-background-color); --app-header-background-color: var(--sidebar-background-color);
--app-header-text-color: var(--sidebar-text-color); --app-header-text-color: var(--sidebar-text-color);
+1 -1
View File
@@ -5,7 +5,7 @@
"dependencies": ["panel_custom", "websocket_api", "http", "frontend", "lovelace"], "dependencies": ["panel_custom", "websocket_api", "http", "frontend", "lovelace"],
"codeowners": [], "codeowners": [],
"requirements": [], "requirements": [],
"version": "2.0.0b4", "version": "2.0.0b5",
"iot_class": "local_push", "iot_class": "local_push",
"config_flow": true "config_flow": true
} }
+1
View File
@@ -16,6 +16,7 @@ class SettingsStoreData:
defaultPanel = attr.ib(type=str, default=None) defaultPanel = attr.ib(type=str, default=None)
sidebarPanelOrder = attr.ib(type=list, default=None) sidebarPanelOrder = attr.ib(type=list, default=None)
sidebarHiddenPanels = attr.ib(type=list, default=None) sidebarHiddenPanels = attr.ib(type=list, default=None)
sidebarTitle = attr.ib(type=str, default=None)
faviconTemplate = attr.ib(type=str, default=None) faviconTemplate = attr.ib(type=str, default=None)
titleTemplate = attr.ib(type=str, default=None) titleTemplate = attr.ib(type=str, default=None)
@@ -0,0 +1,294 @@
import { LitElement, html, css } from "lit";
import { property } from "lit/decorators.js";
import { selectTree } from "../helpers";
class BrowserModSettingsTable extends LitElement {
@property() settingKey;
@property() settingSelector = {
template: {},
};
@property() hass;
@property() default;
@property() tableData = [];
_users = undefined;
firstUpdated() {
window.browser_mod.addEventListener("browser-mod-config-update", () =>
this.updateTable()
);
}
updated(changedProperties) {
if (changedProperties.has("settingKey")) this.updateTable();
if (
changedProperties.has("hass") &&
changedProperties.get("hass") === undefined
)
this.updateTable();
}
async fetchUsers(): Promise<any[]> {
if (this._users === undefined)
this._users = await this.hass.callWS({ type: "config/auth/list" });
return this._users;
}
clearSetting(type, target) {
const clearSettingCallback = async () => {
if (this.settingKey === "sidebarPanelOrder") {
const sideBar: any = await selectTree(
document,
"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar"
);
window.browser_mod.setSetting(type, target, {
sidebarHiddenPanels: "[]",
sidebarPanelOrder: "[]",
});
window.browser_mod.setSetting(type, target, {
sidebarHiddenPanels: undefined,
sidebarPanelOrder: undefined,
});
return;
}
if (this.default)
window.browser_mod.setSetting(type, target, {
[this.settingKey]: this.default,
});
window.browser_mod.setSetting(type, target, {
[this.settingKey]: undefined,
});
};
window.browser_mod?.showPopup(
"Are you sure",
"Do you wish to clear this setting?",
{
right_button: "Yes",
right_button_action: clearSettingCallback,
left_button: "No",
}
);
}
changeSetting(type, target) {
const changeSettingCallback = async (newValue) => {
if (this.settingKey === "sidebarPanelOrder") {
const sideBar: any = await selectTree(
document,
"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar"
);
window.browser_mod.setSetting(type, target, {
sidebarHiddenPanels: JSON.stringify(sideBar._hiddenPanels),
sidebarPanelOrder: JSON.stringify(sideBar._panelOrder),
});
console.log(sideBar._hiddenPanels, sideBar._panelOrder);
return;
}
let value = newValue.value;
window.browser_mod.setSetting(type, target, { [this.settingKey]: value });
};
const settings = window.browser_mod?.getSetting?.(this.settingKey);
const def =
(type === "global" ? settings.global : settings[type][target]) ??
this.default;
window.browser_mod?.showPopup(
"Change value",
(this.settingSelector as any).plaintext ?? [
{
name: "value",
label: (this.settingSelector as any).label ?? "",
default: def,
selector: this.settingSelector,
},
],
{
right_button: "OK",
right_button_action: changeSettingCallback,
left_button: "Cancel",
}
);
}
addBrowserSetting() {
const settings = window.browser_mod?.getSetting?.(this.settingKey);
const allBrowsers = window.browser_mod._data.browsers;
const browsers = [];
for (const target of Object.keys(allBrowsers)) {
if (settings.browser[target] == null) browsers.push(target);
}
if (browsers.length === 0) {
window.browser_mod.showPopup(
"No browsers to configure",
"All registered browsers have already been configured.",
{ right_button: "OK" }
);
return;
}
window.browser_mod.showPopup(
"Select browser to configure",
[
{
name: "browser",
label: "",
selector: {
select: { options: browsers },
},
},
],
{
right_button: "Next",
right_button_action: (value) =>
this.changeSetting("browser", value.browser),
left_button: "Cancel",
}
);
}
async addUserSetting() {
const settings = window.browser_mod?.getSetting?.(this.settingKey);
const allUsers = await this.fetchUsers();
const users = [];
for (const target of allUsers) {
if (target.username && settings.user[target.id] == null)
users.push({ label: target.name, value: target.id });
}
if (users.length === 0) {
window.browser_mod.showPopup(
"No users to configure",
"All users have already been configured.",
{ right_button: "OK" }
);
return;
}
window.browser_mod.showPopup(
"Select user to configure",
[
{
name: "user",
label: "",
selector: {
select: { options: users },
},
},
],
{
right_button: "Next",
right_button_action: (value) => this.changeSetting("user", value.user),
left_button: "Cancel",
}
);
}
async updateTable() {
if (this.hass === undefined) return;
const users = await this.fetchUsers();
const settings = window.browser_mod?.getSetting?.(this.settingKey);
const data = [];
for (const [k, v] of Object.entries(settings.user)) {
const user = users.find((usr) => usr.id === k);
data.push({
name: `User: ${user.name}`,
value: String(v),
controls: html`
<ha-icon-button @click=${() => this.changeSetting("user", k)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${() => this.clearSetting("user", k)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`,
});
}
data.push({
name: "",
value: html`
<mwc-button @click=${() => this.addUserSetting()}>
<ha-icon .icon=${"mdi:plus"}></ha-icon>
Add user setting
</mwc-button>
`,
});
for (const [k, v] of Object.entries(settings.browser)) {
data.push({
name: `Browser: ${k}`,
value: String(v),
controls: html`
<ha-icon-button @click=${() => this.changeSetting("browser", k)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${() => this.clearSetting("browser", k)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`,
});
}
data.push({
name: "",
value: html`
<mwc-button @click=${() => this.addBrowserSetting()}>
<ha-icon .icon=${"mdi:plus"}></ha-icon>
Add browser setting
</mwc-button>
`,
});
data.push({
name: "GLOBAL",
value:
settings.global != null
? String(settings.global)
: html`<span style="color: var(--warning-color);">DEFAULT</span>`,
controls: html`
<ha-icon-button @click=${() => this.changeSetting("global", null)}>
<ha-icon .icon=${"mdi:pencil"} style="display:flex;"></ha-icon>
</ha-icon-button>
<ha-icon-button @click=${() => this.clearSetting("global", null)}>
<ha-icon .icon=${"mdi:delete"} style="display:flex;"></ha-icon>
</ha-icon-button>
`,
});
this.tableData = data;
}
render() {
const global = window.browser_mod?.global_settings?.[this.settingKey];
const columns = {
name: {
title: "Name",
grows: true,
},
value: {
title: "Value",
grows: true,
},
controls: {},
};
return html`
<ha-data-table .columns=${columns} .data=${this.tableData} auto-height>
</ha-data-table>
`;
}
static get styles() {
return css`
:host {
display: block;
}
`;
}
}
customElements.define("browser-mod-settings-table", BrowserModSettingsTable);
+1 -1
View File
@@ -136,7 +136,7 @@ class BrowserModRegisteredBrowsersCard extends LitElement {
private _renderInteractionAlert() { private _renderInteractionAlert() {
return html` return html`
<ha-alert title="Interaction requirement"> <ha-alert title="Interaction requirement">
For security reasons many browsers require the user to interact with a For privacy reasons many browsers require the user to interact with a
webpage before allowing audio playback or video capture. This may affect webpage before allowing audio playback or video capture. This may affect
the the
<code>media_player</code> and <code>camera</code> components of Browser <code>media_player</code> and <code>camera</code> components of Browser
+124 -204
View File
@@ -1,38 +1,73 @@
import { LitElement, html, css } from "lit"; import { LitElement, html, css } from "lit";
import { property, state } from "lit/decorators.js"; import { property, state } from "lit/decorators.js";
import { loadDeveloperToolsTemplate } from "../helpers"; import { loadDeveloperToolsTemplate, selectTree } from "../helpers";
import "./browser-mod-settings-table";
loadDeveloperToolsTemplate(); loadDeveloperToolsTemplate();
class BrowserModFrontendSettingsCard extends LitElement { class BrowserModFrontendSettingsCard extends LitElement {
@property() hass; @property() hass;
@state() _selectedTab = 0; @state() _dashboards = [];
@state() _editSidebar = false;
_savedSidebar = { panelOrder: [], hiddenPanels: [] };
firstUpdated() { firstUpdated() {
window.browser_mod.addEventListener("browser-mod-config-update", () => window.browser_mod.addEventListener("browser-mod-config-update", () =>
this.requestUpdate() this.requestUpdate()
); );
window.browser_mod.addEventListener("browser-mod-favicon-update", () =>
this.requestUpdate()
);
} }
_handleSwitchTab(ev: CustomEvent) { updated(changedProperties) {
this._selectedTab = parseInt(ev.detail.index, 10); if (
changedProperties.has("hass") &&
changedProperties.get("hass") === undefined
) {
(async () =>
(this._dashboards = await this.hass.callWS({
type: "lovelace/dashboards/list",
})))();
}
}
async toggleEditSidebar() {
const sideBar: any = await selectTree(
document,
"home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar"
);
sideBar.editMode = !sideBar.editMode;
this._editSidebar = sideBar.editMode;
if (this._editSidebar) {
this._savedSidebar = {
panelOrder: sideBar._panelOrder,
hiddenPanels: sideBar._hiddenPanels,
};
} else {
sideBar._panelOrder = this._savedSidebar.panelOrder ?? [];
sideBar._hiddenPanels = this._savedSidebar.hiddenPanels ?? [];
this._savedSidebar = { panelOrder: [], hiddenPanels: [] };
}
} }
render() { render() {
const level = ["user", "browser", "global"][this._selectedTab]; const db = this._dashboards.map((d) => {
return { value: d.url_path, label: d.title };
});
const dashboardSelector = {
select: {
options: [{ value: "lovelace", label: "lovelace (default)" }, ...db],
custom_value: true,
},
};
return html` return html`
<ha-card header="Frontend Settings" outlined> <ha-card header="Frontend Settings" outlined>
<div class="card-content"> <div class="card-content">
<ha-alert alert-type="warning"> <ha-alert alert-type="warning" title="Please note:">
<p> The settings in this section 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 Assistant frontend works and looks. It is very easy to forget that
you made a setting here when you switch devices or user. you made a setting here when you switch devices or user.
</p>
<p> <p>
Do not report any issues to Home Assistant before clearing Do not report any issues to Home Assistant before clearing
<b>EVERY</b> setting here and thouroghly clearing all your browser <b>EVERY</b> setting here and thouroghly clearing all your browser
@@ -41,234 +76,119 @@ class BrowserModFrontendSettingsCard extends LitElement {
</p> </p>
</ha-alert> </ha-alert>
<p> <p>
Global settings are applied for all users and browsers.</br> Settings below are applied by first match. I.e. if a matching User
User settings are applied to the current user and overrides any Global settings.</br> setting exists, it will be applied. Otherwise any matching Browser
Browser settings are applied for the current browser and overrides any User or Global settings. setting and otherwise the GLOBAL setting if that differs from
DEFAULT.
</p> </p>
<mwc-tab-bar
.activeIndex=${this._selectedTab}
@MDCTabBar:activated=${this._handleSwitchTab}
>
<mwc-tab .label=${"User (" + this.hass.user.name + ")"}></mwc-tab>
<ha-icon .icon=${"mdi:chevron-double-right"}></ha-icon>
<mwc-tab .label=${"Browser"}></mwc-tab>
<ha-icon .icon=${"mdi:chevron-double-right"}></ha-icon>
<mwc-tab .label=${"Global"}></mwc-tab>
</mwc-tab-bar>
${this._render_settings(level)}
</div>
</ha-card>
`;
}
_render_settings(level) {
const global = window.browser_mod.global_settings;
const browser = window.browser_mod.browser_settings;
const user = window.browser_mod.user_settings;
const current = { global, browser, user }[level];
const DESC_BOOLEAN = (val) =>
({ true: "Enabled", false: "Disabled", undefined: "Unset" }[String(val)]);
const DESC_SET_UNSET = (val) => (val === undefined ? "Unset" : "Set");
const OVERRIDDEN = (key) => {
if (level !== "browser" && browser[key] !== undefined)
return html`<br />Overridden by browser setting`;
if (level === "global" && user[key] !== undefined)
return html`<br />Overridden by user setting`;
};
return html`
<div class="box">
<ha-settings-row>
<span slot="heading">Favicon template</span>
${OVERRIDDEN("faviconTemplate")}
<img src="${window.browser_mod._currentFavicon}" class="favicon" />
</ha-settings-row>
<ha-code-editor
.hass=${this.hass}
.value=${current.faviconTemplate}
@value-changed=${(ev) => {
const tpl = ev.detail.value || undefined;
window.browser_mod.set_setting("faviconTemplate", tpl, level);
}}
></ha-code-editor>
<ha-settings-row>
<mwc-button
@click=${() =>
window.browser_mod.set_setting(
"faviconTemplate",
undefined,
level
)}
>
Clear
</mwc-button>
</ha-settings-row>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Title template</span> <span slot="heading">Title template</span>
${OVERRIDDEN("titleTemplate")} <span slot="description">
Jinja template for the browser window/tab title
</span>
</ha-settings-row> </ha-settings-row>
<ha-code-editor <browser-mod-settings-table
.hass=${this.hass} .hass=${this.hass}
.value=${current.titleTemplate} .settingKey=${"titleTemplate"}
@value-changed=${(ev) => { ></browser-mod-settings-table>
const tpl = ev.detail.value || undefined;
window.browser_mod.set_setting("titleTemplate", tpl, level);
}}
></ha-code-editor>
<ha-settings-row>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("titleTemplate", undefined, level)}
>
Clear
</mwc-button>
</ha-settings-row>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Hide Sidebar</span> <span slot="heading">Favicon template</span>
<span slot="description">Hide the sidebar and hamburger menu</span> <span slot="description">
Currently: ${DESC_BOOLEAN(current.hideSidebar)} Jinja template for the browser favicon
${OVERRIDDEN("hideSidebar")} </span>
</ha-settings-row>
<ha-settings-row>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("hideSidebar", true, level)}
>
Enable
</mwc-button>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("hideSidebar", false, level)}
>
Disable
</mwc-button>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("hideSidebar", undefined, level)}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"faviconTemplate"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Hide Header</span> <span slot="heading">Hide sidebar</span>
<span slot="description">Hide the header on all pages</span> <span slot="description">
Currently: ${DESC_BOOLEAN(current.hideHeader)} Completely remove the sidebar from all panels
${OVERRIDDEN("hideHeader")} </span>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"hideSidebar"}
.settingSelector=${{ boolean: {}, label: "Hide sidebar" }}
></browser-mod-settings-table>
<div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<mwc-button <span slot="heading">Hide header</span>
@click=${() => <span slot="description">
window.browser_mod.set_setting("hideHeader", true, level)} Completely remove the header from all panels
> </span>
Enable
</mwc-button>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("hideHeader", false, level)}
>
Disable
</mwc-button>
<mwc-button
@click=${() =>
window.browser_mod.set_setting("hideHeader", undefined, level)}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"hideHeader"}
.settingSelector=${{ boolean: {}, label: "Hide header" }}
></browser-mod-settings-table>
<div class="separator"></div>
<ha-settings-row>
<span slot="heading">Default dashboard</span>
<span slot="description">
The dashboard that is showed when navigating to
${location.origin}/
</span>
</ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"defaultPanel"}
.settingSelector=${dashboardSelector}
.default=${"lovelace"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Sidebar order</span> <span slot="heading">Sidebar order</span>
<span slot="description"> <span slot="description">
Order and visibility of sidebar buttons Order and visibility of sidebar items. <br />Click EDIT and set
the sidebar up as you want. Then save the settings and finally
click RESTORE.
</span> </span>
Currently: ${DESC_SET_UNSET(current.sidebarPanelOrder)} <mwc-button @click=${() => this.toggleEditSidebar()}>
${OVERRIDDEN("sidebarPanelOrder")} ${this._editSidebar ? "Restore" : "Edit"}
</ha-settings-row>
<ha-settings-row>
<span slot="description">
Clearing this does NOT restore the original default order.
</span>
<mwc-button
@click=${() => {
window.browser_mod.set_setting(
"sidebarPanelOrder",
localStorage.getItem("sidebarPanelOrder"),
level
);
window.browser_mod.set_setting(
"sidebarHiddenPanels",
localStorage.getItem("sidebarHiddenPanels"),
level
);
}}
>
Set
</mwc-button>
<mwc-button
@click=${() => {
window.browser_mod.set_setting(
"sidebarPanelOrder",
undefined,
level
);
window.browser_mod.set_setting(
"sidebarHiddenPanels",
undefined,
level
);
}}
>
Clear
</mwc-button> </mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"sidebarPanelOrder"}
.settingSelector=${{
plaintext: "Press OK to store the current sidebar order",
}}
.default=${"lovelace"}
></browser-mod-settings-table>
<div class="separator"></div> <div class="separator"></div>
<ha-settings-row> <ha-settings-row>
<span slot="heading">Default dashboard</span> <span slot="heading">Sidebar title</span>
<span slot="description"
>The dashboard that's displayed by default</span
>
Currently: ${DESC_SET_UNSET(current.defaultPanel)}
${OVERRIDDEN("defaultPanel")}
</ha-settings-row>
<ha-settings-row>
<span slot="description"> <span slot="description">
Clearing this does NOT restore the original default dashboard. The title at the top of the sidebar
</span> </span>
<mwc-button
@click=${() => {
window.browser_mod.set_setting(
"defaultPanel",
localStorage.getItem("defaultPanel"),
level
);
}}
>
Set
</mwc-button>
<mwc-button
@click=${() => {
window.browser_mod.set_setting("defaultPanel", undefined, level);
}}
>
Clear
</mwc-button>
</ha-settings-row> </ha-settings-row>
<browser-mod-settings-table
.hass=${this.hass}
.settingKey=${"sidebarTitle"}
.settingSelector=${{ text: {} }}
></browser-mod-settings-table>
</div> </div>
</ha-card>
`; `;
} }
@@ -280,7 +200,7 @@ class BrowserModFrontendSettingsCard extends LitElement {
} }
.separator { .separator {
border-bottom: 1px solid var(--divider-color); border-bottom: 1px solid var(--divider-color);
margin: 0 -8px; margin: 16px -16px 0px;
} }
img.favicon { img.favicon {
width: 64px; width: 64px;
+2 -1
View File
@@ -15,12 +15,13 @@ loadConfigDashboard().then(() => {
@property() connection; @property() connection;
firstUpdated() { firstUpdated() {
window.browser_mod.addEventListener("browser-mod-config-update", () => window.addEventListener("browser-mod-config-update", () =>
this.requestUpdate() this.requestUpdate()
); );
} }
render() { render() {
if (!window.browser_mod) return html``;
return html` return html`
<ha-app-layout> <ha-app-layout>
<app-header slot="header" fixed> <app-header slot="header" fixed>
+40 -2
View File
@@ -1,9 +1,17 @@
const TIMEOUT_ERROR = "SELECTTREE-TIMEOUT"; const TIMEOUT_ERROR = "SELECTTREE-TIMEOUT";
async function _await_el(el) { export async function await_element(el, hard = false) {
if (el.localName?.includes("-")) if (el.localName?.includes("-"))
await customElements.whenDefined(el.localName); await customElements.whenDefined(el.localName);
if (el.updateComplete) await el.updateComplete; if (el.updateComplete) await el.updateComplete;
if (hard) {
if (el.pageRendered) await el.pageRendered;
if (el._panelState) {
let rounds = 0;
while (el._panelState !== "loaded" && rounds++ < 5)
await new Promise((r) => setTimeout(r, 100));
}
}
} }
async function _selectTree(root, path, all = false) { async function _selectTree(root, path, all = false) {
@@ -18,7 +26,7 @@ async function _selectTree(root, path, all = false) {
if (!p.trim().length) continue; if (!p.trim().length) continue;
_await_el(e); await_element(e);
el = p === "$" ? [e.shadowRoot] : e.querySelectorAll(p); el = p === "$" ? [e.shadowRoot] : e.querySelectorAll(p);
} }
return all ? el : el[0]; return all ? el : el[0];
@@ -102,6 +110,7 @@ export const loadConfigDashboard = async () => {
const configRouter: any = document.createElement("ha-panel-config"); const configRouter: any = document.createElement("ha-panel-config");
await configRouter?.routerOptions?.routes?.dashboard?.load?.(); // Load ha-config-dashboard await configRouter?.routerOptions?.routes?.dashboard?.load?.(); // Load ha-config-dashboard
await configRouter?.routerOptions?.routes?.cloud?.load?.(); // Load ha-settings-row await configRouter?.routerOptions?.routes?.cloud?.load?.(); // Load ha-settings-row
await configRouter?.routerOptions?.routes?.entities?.load?.(); // Load ha-data-table
await customElements.whenDefined("ha-config-dashboard"); await customElements.whenDefined("ha-config-dashboard");
}; };
@@ -132,3 +141,32 @@ export function throttle(timeout) {
}; };
}; };
} }
export function runOnce(restart = false) {
return function (target, propertyKey, descriptor) {
const fn = descriptor.value;
let running = undefined;
const newfn = function (...rest) {
if (restart && running === false) running = true;
if (running !== undefined) return;
running = false;
const retval = fn.bind(this)(...rest);
if (running) {
running = undefined;
return newfn.bind(this)(...rest);
} else {
running = undefined;
return retval;
}
};
descriptor.value = newfn;
};
}
export async function waitRepeat(fn, times, delay) {
while (times--) {
fn();
await new Promise((r) => setTimeout(r, delay));
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ export const ConnectionMixin = (SuperClass) => {
} }
private fireEvent(event, detail = undefined) { private fireEvent(event, detail = undefined) {
this.dispatchEvent(new CustomEvent(event, { detail })); this.dispatchEvent(new CustomEvent(event, { detail, bubbles: true }));
} }
private incoming_message(msg) { private incoming_message(msg) {
+105 -24
View File
@@ -1,25 +1,37 @@
import { selectTree } from "../helpers"; import { await_element, waitRepeat, runOnce, selectTree } from "../helpers";
export const AutoSettingsMixin = (SuperClass) => { export const AutoSettingsMixin = (SuperClass) => {
return class AutoSettingsMixinClass extends SuperClass { class AutoSettingsMixinClass extends SuperClass {
_faviconTemplateSubscription; _faviconTemplateSubscription;
_titleTemplateSubscription; _titleTemplateSubscription;
__currentTitle = undefined; __currentTitle = undefined;
@runOnce()
async runHideHeader() {
while (!(await this._hideHeader()))
await new Promise((r) => setTimeout(r, 500));
}
@runOnce(true)
async runUpdateTitle() {
await waitRepeat(() => this._updateTitle(), 3, 500);
}
constructor() { constructor() {
super(); super();
this._auto_settings_setup(); const runUpdates = async () => {
this.addEventListener("browser-mod-config-update", () => this.runUpdateTitle();
this._auto_settings_setup() this.runHideHeader();
); };
window.addEventListener("location-changed", () => { this._auto_settings_setup();
this._updateTitle(); this.addEventListener("browser-mod-config-update", () => {
setTimeout(() => this._updateTitle(), 500); this._auto_settings_setup();
setTimeout(() => this._updateTitle(), 1000); runUpdates();
setTimeout(() => this._updateTitle(), 5000);
}); });
window.addEventListener("location-changed", runUpdates);
} }
async _auto_settings_setup() { async _auto_settings_setup() {
@@ -40,7 +52,7 @@ export const AutoSettingsMixin = (SuperClass) => {
// Default panel // Default panel
if (settings.defaultPanel) { if (settings.defaultPanel) {
localStorage.setItem("defaultPanel", settings.defaultPanel); localStorage.setItem("defaultPanel", `"${settings.defaultPanel}"`);
} }
// Hide sidebar // Hide sidebar
@@ -55,18 +67,18 @@ export const AutoSettingsMixin = (SuperClass) => {
).then((el) => el?.remove?.()); ).then((el) => el?.remove?.());
} }
// Hide header // Sidebar title
if (settings.hideHeader === true) { if (settings.sidebarTitle) {
customElements.whenDefined("app-header-layout").then(() => { selectTree(
const appHeader = customElements.get("app-header").prototype; document,
const _attached = appHeader.attached; "home-assistant $ home-assistant-main $ app-drawer-layout app-drawer ha-sidebar $ .title"
appHeader.attached = function () { ).then((el) => {
_attached.bind(this)(); if (el) (el as HTMLElement).innerHTML = settings.sidebarTitle;
this.style.setProperty("display", "none");
};
}); });
} }
// Hide header
// Favicon template // Favicon template
if (settings.faviconTemplate !== undefined) { if (settings.faviconTemplate !== undefined) {
(async () => { (async () => {
@@ -111,7 +123,6 @@ export const AutoSettingsMixin = (SuperClass) => {
_updateFavicon({ result }) { _updateFavicon({ result }) {
const link: any = document.head.querySelector("link[rel~='icon']"); const link: any = document.head.querySelector("link[rel~='icon']");
link.href = result; link.href = result;
window.browser_mod.fireEvent("browser-mod-favicon-update");
} }
get _currentTitle() { get _currentTitle() {
@@ -121,7 +132,77 @@ export const AutoSettingsMixin = (SuperClass) => {
_updateTitle(data = undefined) { _updateTitle(data = undefined) {
if (data) this.__currentTitle = data.result; if (data) this.__currentTitle = data.result;
if (this.__currentTitle) document.title = this.__currentTitle; if (this.__currentTitle) document.title = this.__currentTitle;
window.browser_mod.fireEvent("browser-mod-favicon-update");
} }
};
async _hideHeader() {
if (this.settings.hideHeader !== true) return true;
let el = await selectTree(
document,
"home-assistant $ home-assistant-main $ app-drawer-layout partial-panel-resolver"
);
if (!el) return false;
let steps = 0;
while (el && el.localName !== "ha-app-layout" && steps++ < 5) {
await await_element(el, true);
const next =
el.querySelector("ha-app-layout") ??
el.firstElementChild ??
el.shadowRoot;
el = next;
}
if (el?.localName !== "ha-app-layout") return false;
if (el.header) {
el.header.style.setProperty("display", "none");
setTimeout(() => el._updateLayoutStates(), 0);
return true;
}
return false;
}
getSetting(key) {
const retval = { global: undefined, browser: {}, user: {} };
retval.global = this._data.settings?.[key];
for (const [k, v] of Object.entries(this._data.browsers ?? {})) {
if ((v as any).settings?.[key] != null)
retval.browser[k] = (v as any).settings[key];
}
for (const [k, v] of Object.entries(this._data.user_settings ?? {})) {
if (v[key] != null) retval.user[k] = v[key];
}
return retval;
}
setSetting(type, target, settings) {
if (type === "global") {
for (const [key, value] of Object.entries(settings))
this.connection.sendMessage({
type: "browser_mod/settings",
key,
value,
});
} else if (type === "browser") {
const browser = this._data.browsers[target];
const newsettings = { ...browser.settings, ...settings };
console.log(newsettings);
this.connection.sendMessage({
type: "browser_mod/register",
browserID: target,
data: {
...browser,
settings: newsettings,
},
});
} else if (type === "user") {
const user = target;
for (const [key, value] of Object.entries(settings))
this.connection.sendMessage({
type: "browser_mod/settings",
user,
key,
value,
});
}
}
}
return AutoSettingsMixinClass;
}; };
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "browser_mod", "name": "browser_mod",
"private": true, "private": true,
"version": "2.0.0b4", "version": "2.0.0b5",
"description": "", "description": "",
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
-6
View File
@@ -17,12 +17,6 @@
- platform: state - platform: state
entity_id: light.kitchen_lights entity_id: light.kitchen_lights
action: action:
- service: browser_mod.sequence
data:
sequence:
- service: delay
data:
time: 5000
- service: browser_mod.popup - service: browser_mod.popup
data: data:
title: automation title: automation