Begun framework for frontend settings across devices
This commit is contained in:
1 parent
77554aa86c
commit
c7ce90883b
11 files changed
+592
-87
No files matched your search
@@ -398,13 +398,67 @@ const ConnectionMixin = (SuperClass) => {
|
|||||||
data: Object.assign(Object.assign({}, this.browsers[this.browserID]), newData),
|
data: Object.assign(Object.assign({}, this.browsers[this.browserID]), newData),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get meta() {
|
get global_settings() {
|
||||||
if (!this.registered)
|
var _a;
|
||||||
return null;
|
const settings = {};
|
||||||
return this.browsers[this.browserID].meta;
|
const global = (_a = this._data.settings) !== null && _a !== void 0 ? _a : {};
|
||||||
|
for (const [k, v] of Object.entries(global)) {
|
||||||
|
if (v !== null)
|
||||||
|
settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
get user_settings() {
|
||||||
|
var _a;
|
||||||
|
const settings = {};
|
||||||
|
const user = (_a = this._data.user_settings[this.hass.user.id]) !== null && _a !== void 0 ? _a : {};
|
||||||
|
for (const [k, v] of Object.entries(user)) {
|
||||||
|
if (v !== null)
|
||||||
|
settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
get browser_settings() {
|
||||||
|
var _a, _b;
|
||||||
|
const settings = {};
|
||||||
|
const browser = (_b = (_a = this.browsers[this.browserID]) === null || _a === void 0 ? void 0 : _a.settings) !== null && _b !== void 0 ? _b : {};
|
||||||
|
for (const [k, v] of Object.entries(browser)) {
|
||||||
|
if (v !== null)
|
||||||
|
settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
get settings() {
|
||||||
|
return Object.assign(Object.assign(Object.assign({}, this.global_settings), this.user_settings), this.browser_settings);
|
||||||
|
}
|
||||||
|
set_setting(key, value, level) {
|
||||||
|
var _a;
|
||||||
|
switch (level) {
|
||||||
|
case "global": {
|
||||||
|
this.connection.sendMessage({
|
||||||
|
type: "browser_mod/settings",
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "user": {
|
||||||
|
const user = this.hass.user.id;
|
||||||
|
this.connection.sendMessage({
|
||||||
|
type: "browser_mod/settings",
|
||||||
|
user,
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "browser": {
|
||||||
|
const settings = (_a = this.browsers[this.browserID]) === null || _a === void 0 ? void 0 : _a.settings;
|
||||||
|
settings[key] = value;
|
||||||
|
this._reregister({ settings });
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set meta(value) {
|
|
||||||
this._reregister({ meta: value });
|
|
||||||
}
|
}
|
||||||
get cameraEnabled() {
|
get cameraEnabled() {
|
||||||
if (!this.registered)
|
if (!this.registered)
|
||||||
@@ -1769,6 +1823,25 @@ __decorate([
|
|||||||
customElements.define("popup-card", PopupCard);
|
customElements.define("popup-card", PopupCard);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
const AutoSettingsMixin = (SuperClass) => {
|
||||||
|
return class AutoSettingsMixinClass extends SuperClass {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._auto_settings_setup();
|
||||||
|
}
|
||||||
|
async _auto_settings_setup() {
|
||||||
|
await this.connectionPromise;
|
||||||
|
const settings = this.settings;
|
||||||
|
if (settings.sidebarPanelOrder) {
|
||||||
|
localStorage.setItem("sidebarPanelOrder", settings.sidebarPanelOrder);
|
||||||
|
}
|
||||||
|
if (settings.sidebarHiddenPanels) {
|
||||||
|
localStorage.setItem("sidebarHiddenPanels", settings.sidebarHiddenPanels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
- Fix nomenclature
|
- Fix nomenclature
|
||||||
@@ -1802,11 +1875,13 @@ __decorate([
|
|||||||
x Redesign services to target devices
|
x Redesign services to target devices
|
||||||
- frontend editor for popup cards
|
- frontend editor for popup cards
|
||||||
- also screensavers
|
- also screensavers
|
||||||
- Tweaks
|
- Saved frontend settings
|
||||||
- Save sidebar
|
X Framework
|
||||||
- Save sidebar per user
|
x Save sidebar
|
||||||
- Kiosk mode
|
- Kiosk mode
|
||||||
- Kiosk mode per user
|
- Default panel?
|
||||||
|
- Screensaver?
|
||||||
|
- Tweaks
|
||||||
- Favicon templates
|
- Favicon templates
|
||||||
- Title templates
|
- Title templates
|
||||||
- Quickbar tweaks (ctrl+enter)?
|
- Quickbar tweaks (ctrl+enter)?
|
||||||
@@ -1814,7 +1889,7 @@ __decorate([
|
|||||||
- Media_seek
|
- Media_seek
|
||||||
- Screensavers
|
- Screensavers
|
||||||
*/
|
*/
|
||||||
class BrowserMod extends ServicesMixin(PopupMixin(ActivityMixin(BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))))))))) {
|
class BrowserMod extends ServicesMixin(PopupMixin(ActivityMixin(BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(AutoSettingsMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget))))))))))) {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.connect();
|
this.connect();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function __decorate(decorators, target, key, desc) {
|
|||||||
* Copyright 2019 Google LLC
|
* Copyright 2019 Google LLC
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
const t$1=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e$3=Symbol(),n$4=new Map;class s$3{constructor(t,n){if(this._$cssResult$=!0,n!==e$3)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n$4.get(this.cssText);return t$1&&void 0===e&&(n$4.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o$3=t=>new s$3("string"==typeof t?t:t+"",e$3),r$2=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s$3(o,e$3)},i$2=(e,n)=>{t$1?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S$1=t$1?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o$3(e)})(t):t;
|
const t$2=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e$3=Symbol(),n$4=new Map;class s$3{constructor(t,n){if(this._$cssResult$=!0,n!==e$3)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t;}get styleSheet(){let e=n$4.get(this.cssText);return t$2&&void 0===e&&(n$4.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const o$3=t=>new s$3("string"==typeof t?t:t+"",e$3),r$2=(t,...n)=>{const o=1===t.length?t[0]:n.reduce(((e,n,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[s+1]),t[0]);return new s$3(o,e$3)},i$2=(e,n)=>{t$2?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),s=window.litNonce;void 0!==s&&n.setAttribute("nonce",s),n.textContent=t.cssText,e.appendChild(n);}));},S$1=t$2?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return o$3(e)})(t):t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
@@ -38,7 +38,7 @@ const t$1=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeSh
|
|||||||
* Copyright 2017 Google LLC
|
* Copyright 2017 Google LLC
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
var t;const i$1=globalThis.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$1=`lit$${(Math.random()+"").slice(9)}$`,o$1="?"+e$1,n$2=`<${o$1}>`,l$1=document,h=(t="")=>l$1.createComment(t),r=t=>null===t||"object"!=typeof t&&"function"!=typeof t,d=Array.isArray,u=t=>{var i;return d(t)||"function"==typeof(null===(i=t)||void 0===i?void 0:i[Symbol.iterator])},c=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,a=/>/g,f=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,_=/'/g,m=/"/g,g=/^(?:script|style|textarea|title)$/i,p=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),$=p(1),b=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),T=new WeakMap,x=(t,i,s)=>{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new N(i.insertBefore(h(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l},A=l$1.createTreeWalker(l$1,129,null,!1),C=(t,i)=>{const o=t.length-1,l=[];let h,r=2===i?"<svg>":"",d=c;for(let i=0;i<o;i++){const s=t[i];let o,u,p=-1,$=0;for(;$<s.length&&(d.lastIndex=$,u=d.exec(s),null!==u);)$=d.lastIndex,d===c?"!--"===u[1]?d=v:void 0!==u[1]?d=a:void 0!==u[2]?(g.test(u[2])&&(h=RegExp("</"+u[2],"g")),d=f):void 0!==u[3]&&(d=f):d===f?">"===u[0]?(d=null!=h?h:c,p=-1):void 0===u[1]?p=-2:(p=d.lastIndex-u[2].length,o=u[1],d=void 0===u[3]?f:'"'===u[3]?m:_):d===m||d===_?d=f:d===v||d===a?d=c:(d=f,h=void 0);const y=d===f&&t[i+1].startsWith("/>")?" ":"";r+=d===c?s+n$2:p>=0?(l.push(o),s.slice(0,p)+"$lit$"+s.slice(p)+e$1+y):s+e$1+(-2===p?(l.push(void 0),i):y);}const u=r+(t[o]||"<?>")+(2===i?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==s$1?s$1.createHTML(u):u,l]};class E{constructor({strings:t,_$litType$:s},n){let l;this.parts=[];let r=0,d=0;const u=t.length-1,c=this.parts,[v,a]=C(t,s);if(this.el=E.createElement(v,n),A.currentNode=this.el.content,2===s){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(l=A.nextNode())&&c.length<u;){if(1===l.nodeType){if(l.hasAttributes()){const t=[];for(const i of l.getAttributeNames())if(i.endsWith("$lit$")||i.startsWith(e$1)){const s=a[d++];if(t.push(i),void 0!==s){const t=l.getAttribute(s.toLowerCase()+"$lit$").split(e$1),i=/([.?@])?(.*)/.exec(s);c.push({type:1,index:r,name:i[2],strings:t,ctor:"."===i[1]?M:"?"===i[1]?H:"@"===i[1]?I:S});}else c.push({type:6,index:r});}for(const i of t)l.removeAttribute(i);}if(g.test(l.tagName)){const t=l.textContent.split(e$1),s=t.length-1;if(s>0){l.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)l.append(t[i],h()),A.nextNode(),c.push({type:2,index:++r});l.append(t[s],h());}}}else if(8===l.nodeType)if(l.data===o$1)c.push({type:2,index:r});else {let t=-1;for(;-1!==(t=l.data.indexOf(e$1,t+1));)c.push({type:7,index:r}),t+=e$1.length-1;}r++;}}static createElement(t,i){const s=l$1.createElement("template");return s.innerHTML=t,s}}function P(t,i,s=t,e){var o,n,l,h;if(i===b)return i;let d=void 0!==e?null===(o=s._$Cl)||void 0===o?void 0:o[e]:s._$Cu;const u=r(i)?void 0:i._$litDirective$;return (null==d?void 0:d.constructor)!==u&&(null===(n=null==d?void 0:d._$AO)||void 0===n||n.call(d,!1),void 0===u?d=void 0:(d=new u(t),d._$AT(t,s,e)),void 0!==e?(null!==(l=(h=s)._$Cl)&&void 0!==l?l:h._$Cl=[])[e]=d:s._$Cu=d),void 0!==d&&(i=P(t,d._$AS(t,i.values),d,e)),i}class V{constructor(t,i){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var i;const{el:{content:s},parts:e}=this._$AD,o=(null!==(i=null==t?void 0:t.creationScope)&&void 0!==i?i:l$1).importNode(s,!0);A.currentNode=o;let n=A.nextNode(),h=0,r=0,d=e[0];for(;void 0!==d;){if(h===d.index){let i;2===d.type?i=new N(n,n.nextSibling,this,t):1===d.type?i=new d.ctor(n,d.name,d.strings,this,t):6===d.type&&(i=new L(n,this,t)),this.v.push(i),d=e[++r];}h!==(null==d?void 0:d.index)&&(n=A.nextNode(),h++);}return o}m(t){let i=0;for(const s of this.v)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class N{constructor(t,i,s,e){var o;this.type=2,this._$AH=w,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cg=null===(o=null==e?void 0:e.isConnected)||void 0===o||o;}get _$AU(){var t,i;return null!==(i=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==i?i:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=P(this,t,i),r(t)?t===w||null==t||""===t?(this._$AH!==w&&this._$AR(),this._$AH=w):t!==this._$AH&&t!==b&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):u(t)?this.S(t):this.$(t);}M(t,i=this._$AB){return this._$AA.parentNode.insertBefore(t,i)}k(t){this._$AH!==t&&(this._$AR(),this._$AH=tLine truncated
|
var t$1;const i$1=globalThis.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e$1=`lit$${(Math.random()+"").slice(9)}$`,o$1="?"+e$1,n$2=`<${o$1}>`,l$1=document,h=(t="")=>l$1.createComment(t),r=t=>null===t||"object"!=typeof t&&"function"!=typeof t,d=Array.isArray,u=t=>{var i;return d(t)||"function"==typeof(null===(i=t)||void 0===i?void 0:i[Symbol.iterator])},c=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,a=/>/g,f=/>|[ \n\r](?:([^\s"'>=/]+)([ \n\r]*=[ \n\r]*(?:[^ \n\r"'`<>=]|("|')|))|$)/g,_=/'/g,m=/"/g,g=/^(?:script|style|textarea|title)$/i,p=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),$=p(1),b=Symbol.for("lit-noChange"),w=Symbol.for("lit-nothing"),T=new WeakMap,x=(t,i,s)=>{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new N(i.insertBefore(h(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l},A=l$1.createTreeWalker(l$1,129,null,!1),C=(t,i)=>{const o=t.length-1,l=[];let h,r=2===i?"<svg>":"",d=c;for(let i=0;i<o;i++){const s=t[i];let o,u,p=-1,$=0;for(;$<s.length&&(d.lastIndex=$,u=d.exec(s),null!==u);)$=d.lastIndex,d===c?"!--"===u[1]?d=v:void 0!==u[1]?d=a:void 0!==u[2]?(g.test(u[2])&&(h=RegExp("</"+u[2],"g")),d=f):void 0!==u[3]&&(d=f):d===f?">"===u[0]?(d=null!=h?h:c,p=-1):void 0===u[1]?p=-2:(p=d.lastIndex-u[2].length,o=u[1],d=void 0===u[3]?f:'"'===u[3]?m:_):d===m||d===_?d=f:d===v||d===a?d=c:(d=f,h=void 0);const y=d===f&&t[i+1].startsWith("/>")?" ":"";r+=d===c?s+n$2:p>=0?(l.push(o),s.slice(0,p)+"$lit$"+s.slice(p)+e$1+y):s+e$1+(-2===p?(l.push(void 0),i):y);}const u=r+(t[o]||"<?>")+(2===i?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==s$1?s$1.createHTML(u):u,l]};class E{constructor({strings:t,_$litType$:s},n){let l;this.parts=[];let r=0,d=0;const u=t.length-1,c=this.parts,[v,a]=C(t,s);if(this.el=E.createElement(v,n),A.currentNode=this.el.content,2===s){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(l=A.nextNode())&&c.length<u;){if(1===l.nodeType){if(l.hasAttributes()){const t=[];for(const i of l.getAttributeNames())if(i.endsWith("$lit$")||i.startsWith(e$1)){const s=a[d++];if(t.push(i),void 0!==s){const t=l.getAttribute(s.toLowerCase()+"$lit$").split(e$1),i=/([.?@])?(.*)/.exec(s);c.push({type:1,index:r,name:i[2],strings:t,ctor:"."===i[1]?M:"?"===i[1]?H:"@"===i[1]?I:S});}else c.push({type:6,index:r});}for(const i of t)l.removeAttribute(i);}if(g.test(l.tagName)){const t=l.textContent.split(e$1),s=t.length-1;if(s>0){l.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)l.append(t[i],h()),A.nextNode(),c.push({type:2,index:++r});l.append(t[s],h());}}}else if(8===l.nodeType)if(l.data===o$1)c.push({type:2,index:r});else {let t=-1;for(;-1!==(t=l.data.indexOf(e$1,t+1));)c.push({type:7,index:r}),t+=e$1.length-1;}r++;}}static createElement(t,i){const s=l$1.createElement("template");return s.innerHTML=t,s}}function P(t,i,s=t,e){var o,n,l,h;if(i===b)return i;let d=void 0!==e?null===(o=s._$Cl)||void 0===o?void 0:o[e]:s._$Cu;const u=r(i)?void 0:i._$litDirective$;return (null==d?void 0:d.constructor)!==u&&(null===(n=null==d?void 0:d._$AO)||void 0===n||n.call(d,!1),void 0===u?d=void 0:(d=new u(t),d._$AT(t,s,e)),void 0!==e?(null!==(l=(h=s)._$Cl)&&void 0!==l?l:h._$Cl=[])[e]=d:s._$Cu=d),void 0!==d&&(i=P(t,d._$AS(t,i.values),d,e)),i}class V{constructor(t,i){this.v=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}p(t){var i;const{el:{content:s},parts:e}=this._$AD,o=(null!==(i=null==t?void 0:t.creationScope)&&void 0!==i?i:l$1).importNode(s,!0);A.currentNode=o;let n=A.nextNode(),h=0,r=0,d=e[0];for(;void 0!==d;){if(h===d.index){let i;2===d.type?i=new N(n,n.nextSibling,this,t):1===d.type?i=new d.ctor(n,d.name,d.strings,this,t):6===d.type&&(i=new L(n,this,t)),this.v.push(i),d=e[++r];}h!==(null==d?void 0:d.index)&&(n=A.nextNode(),h++);}return o}m(t){let i=0;for(const s of this.v)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class N{constructor(t,i,s,e){var o;this.type=2,this._$AH=w,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cg=null===(o=null==e?void 0:e.isConnected)||void 0===o||o;}get _$AU(){var t,i;return null!==(i=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==i?i:this._$Cg}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=P(this,t,i),r(t)?t===w||null==t||""===t?(this._$AH!==w&&this._$AR(),this._$AH=w):t!==this._$AH&&t!==b&&this.$(t):void 0!==t._$litType$?this.T(t):void 0!==t.nodeType?this.k(t):u(t)?this.S(t):this.$(t);}M(t,i=this._$AB){return this._$AA.parentNode.insertBefore(t,i)}k(t){this._$AH!==t&&(this._$AR(),this._$AHLine truncated
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
@@ -53,6 +53,12 @@ var t;const i$1=globalThis.trustedTypes,s$1=i$1?i$1.createPolicy("lit-html",{cre
|
|||||||
*/
|
*/
|
||||||
const i=(i,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.createProperty(e.key,i);}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this));},finisher(n){n.createProperty(e.key,i);}};function e(e){return (n,t)=>void 0!==t?((i,e,n)=>{e.constructor.createProperty(n,i);})(e,n,t):i(e,n)}
|
const i=(i,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.createProperty(e.key,i);}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this));},finisher(n){n.createProperty(e.key,i);}};function e(e){return (n,t)=>void 0!==t?((i,e,n)=>{e.constructor.createProperty(n,i);})(e,n,t):i(e,n)}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2017 Google LLC
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/function t(t){return e({...t,state:!0})}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
* Copyright 2021 Google LLC
|
* Copyright 2021 Google LLC
|
||||||
@@ -81,6 +87,142 @@ const loadDevTools = async () => {
|
|||||||
await customElements.whenDefined("ha-config-dashboard");
|
await customElements.whenDefined("ha-config-dashboard");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BrowserModSettingsCard extends s {
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
this._selectedTab = 0;
|
||||||
|
}
|
||||||
|
firstUpdated() {
|
||||||
|
window.browser_mod.addEventListener("browser-mod-config-update", () => this.requestUpdate());
|
||||||
|
}
|
||||||
|
_handleSwitchTab(ev) {
|
||||||
|
this._selectedTab = parseInt(ev.detail.index, 10);
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const level = ["browser", "user", "global"][this._selectedTab];
|
||||||
|
return $ `
|
||||||
|
<ha-card header="Auto settings" outlined>
|
||||||
|
<div class="card-content">
|
||||||
|
<mwc-tab-bar
|
||||||
|
.activeIndex=${this._selectedTab}
|
||||||
|
@MDCTabBar:activated=${this._handleSwitchTab}
|
||||||
|
>
|
||||||
|
<mwc-tab .label=${"Browser"}></mwc-tab>
|
||||||
|
<mwc-tab .label=${"User (" + this.hass.user.name + ")"}></mwc-tab>
|
||||||
|
<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 user = window.browser_mod.user_settings;
|
||||||
|
const browser = window.browser_mod.browser_settings;
|
||||||
|
const current = { global, user, browser }[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 $ `<br />Overridden by browser setting`;
|
||||||
|
if (level === "global" && user[key] !== undefined)
|
||||||
|
return $ `<br />Overridden by user setting`;
|
||||||
|
};
|
||||||
|
return $ `
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: ${DESC_BOOLEAN(current.kiosk)} ${OVERRIDDEN("kiosk")}
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() => window.browser_mod.set_setting("kiosk", true, level)}
|
||||||
|
>
|
||||||
|
Enable
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() => window.browser_mod.set_setting("kiosk", false, level)}
|
||||||
|
>
|
||||||
|
Disable
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() => window.browser_mod.set_setting("kiosk", undefined, level)}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Sidebar order</span>
|
||||||
|
<span slot="description">Order and visibility of sidebar buttons</span>
|
||||||
|
Currenty: ${DESC_SET_UNSET(current.sidebarPanelOrder)}
|
||||||
|
${OVERRIDDEN("sidebarPanelOrder")}
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<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>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
_render_user() {
|
||||||
|
return $ `
|
||||||
|
User
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: Overridden
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Set screensaver</span>
|
||||||
|
<span slot="description"> Set screensaver card </span>
|
||||||
|
<mwc-button>Enable</mwc-button>
|
||||||
|
<mwc-button>Disable</mwc-button>
|
||||||
|
<mwc-button>Clear</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
_render_browser() {
|
||||||
|
return $ `
|
||||||
|
Browser
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: Overridden
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Set screensaver</span>
|
||||||
|
<span slot="description"> Set screensaver card </span>
|
||||||
|
<mwc-button>Enable</mwc-button>
|
||||||
|
<mwc-button>Disable</mwc-button>
|
||||||
|
<mwc-button>Clear</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
__decorate([
|
||||||
|
e()
|
||||||
|
], BrowserModSettingsCard.prototype, "hass", void 0);
|
||||||
|
__decorate([
|
||||||
|
t()
|
||||||
|
], BrowserModSettingsCard.prototype, "_selectedTab", void 0);
|
||||||
|
customElements.define("browser-mod-settings-card", BrowserModSettingsCard);
|
||||||
|
|
||||||
const bmWindow = window;
|
const bmWindow = window;
|
||||||
loadDevTools().then(() => {
|
loadDevTools().then(() => {
|
||||||
class BrowserModPanel extends s {
|
class BrowserModPanel extends s {
|
||||||
@@ -348,25 +490,9 @@ loadDevTools().then(() => {
|
|||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
|
|
||||||
<ha-card outlined header="Tweaks">
|
<browser-mod-settings-card
|
||||||
<div class="card-content">
|
.hass=${this.hass}
|
||||||
<ha-settings-row>
|
></browser-mod-settings-card>
|
||||||
<span slot="heading">User sidebar</span>
|
|
||||||
<span slot="description"
|
|
||||||
>Save sidebar as default for current user
|
|
||||||
(${this.hass.user.name})</span
|
|
||||||
>
|
|
||||||
<mwc-button>Save</mwc-button>
|
|
||||||
</ha-settings-row>
|
|
||||||
<ha-settings-row>
|
|
||||||
<span slot="heading">Global sidebar</span>
|
|
||||||
<span slot="description"
|
|
||||||
>Save sidebar as default for all users</span
|
|
||||||
>
|
|
||||||
<mwc-button>Save</mwc-button>
|
|
||||||
</ha-settings-row>
|
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
</ha-app-layout>
|
</ha-app-layout>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
@@ -130,8 +131,30 @@ async def async_setup_connection(hass):
|
|||||||
dev = getBrowser(hass, browserID)
|
dev = getBrowser(hass, browserID)
|
||||||
dev.update(hass, msg.get("data", {}))
|
dev.update(hass, msg.get("data", {}))
|
||||||
|
|
||||||
|
@websocket_api.websocket_command(
|
||||||
|
{
|
||||||
|
vol.Required("type"): "browser_mod/settings",
|
||||||
|
vol.Required("key"): str,
|
||||||
|
vol.Optional("value"): vol.Any(int, str, bool, list, object, None),
|
||||||
|
vol.Optional("user"): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@websocket_api.async_response
|
||||||
|
async def handle_settings(hass, connection, msg):
|
||||||
|
store = hass.data[DOMAIN]["store"]
|
||||||
|
if "user" in msg:
|
||||||
|
# Set user setting
|
||||||
|
await store.set_user_settings(
|
||||||
|
msg["user"], **{msg["key"]: msg.get("value", None)}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Set global setting
|
||||||
|
await store.set_global_settings(**{msg["key"]: msg.get("value", None)})
|
||||||
|
pass
|
||||||
|
|
||||||
async_register_command(hass, handle_connect)
|
async_register_command(hass, handle_connect)
|
||||||
async_register_command(hass, handle_register)
|
async_register_command(hass, handle_register)
|
||||||
async_register_command(hass, handle_unregister)
|
async_register_command(hass, handle_unregister)
|
||||||
async_register_command(hass, handle_reregister)
|
async_register_command(hass, handle_reregister)
|
||||||
async_register_command(hass, handle_update)
|
async_register_command(hass, handle_update)
|
||||||
|
async_register_command(hass, handle_settings)
|
||||||
@@ -10,11 +10,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class BrowserStoreData:
|
class Settings:
|
||||||
last_seen = attr.ib(type=int, default=0)
|
kiosk = attr.ib(type=bool, default=None)
|
||||||
enabled = attr.ib(type=bool, default=False)
|
defaultPanel = attr.ib(type=str, default=None)
|
||||||
camera = attr.ib(type=bool, default=False)
|
sidebarPanelOrder = attr.ib(type=list, default=None)
|
||||||
meta = attr.ib(type=str, default="default")
|
sidebarHiddenPanels = attr.ib(type=list, default=None)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
@@ -24,21 +24,54 @@ class BrowserStoreData:
|
|||||||
return attr.asdict(self)
|
return attr.asdict(self)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class BrowserStoreData:
|
||||||
|
last_seen = attr.ib(type=int, default=0)
|
||||||
|
enabled = attr.ib(type=bool, default=False)
|
||||||
|
camera = attr.ib(type=bool, default=False)
|
||||||
|
settings = attr.ib(type=Settings, factory=Settings)
|
||||||
|
meta = attr.ib(type=str, default="default")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data):
|
||||||
|
settings = Settings.from_dict(data.get("settings", {}))
|
||||||
|
return cls(
|
||||||
|
**(
|
||||||
|
data
|
||||||
|
| {
|
||||||
|
"settings": settings,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def asdict(self):
|
||||||
|
return attr.asdict(self)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class ConfigStoreData:
|
class ConfigStoreData:
|
||||||
browsers = attr.ib(type=dict[str:BrowserStoreData], factory=dict)
|
browsers = attr.ib(type=dict[str:BrowserStoreData], factory=dict)
|
||||||
version = attr.ib(type=str, default="2.0")
|
version = attr.ib(type=str, default="2.0")
|
||||||
|
settings = attr.ib(type=Settings, factory=Settings)
|
||||||
|
user_settings = attr.ib(type=dict[str:Settings], factory=dict)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data={}):
|
def from_dict(cls, data={}):
|
||||||
browsers = {
|
browsers = {
|
||||||
k: BrowserStoreData.from_dict(v) for k, v in data["browsers"].items()
|
k: BrowserStoreData.from_dict(v)
|
||||||
|
for k, v in data.get("browsers", {}).items()
|
||||||
}
|
}
|
||||||
|
user_settings = {
|
||||||
|
k: Settings.from_dict(v) for k, v in data.get("user_settings", {}).items()
|
||||||
|
}
|
||||||
|
settings = Settings.from_dict(data.get("settings", {}))
|
||||||
return cls(
|
return cls(
|
||||||
**(
|
**(
|
||||||
data
|
data
|
||||||
| {
|
| {
|
||||||
"browsers": browsers,
|
"browsers": browsers,
|
||||||
|
"settings": settings,
|
||||||
|
"user_settings": user_settings,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -97,3 +130,19 @@ class BrowserModStore:
|
|||||||
async def delete_browser(self, browserID):
|
async def delete_browser(self, browserID):
|
||||||
del self.data.browsers[browserID]
|
del self.data.browsers[browserID]
|
||||||
await self.updated()
|
await self.updated()
|
||||||
|
|
||||||
|
def get_user_settings(self, name):
|
||||||
|
return self.data.user_settings.get(name, Settings())
|
||||||
|
|
||||||
|
async def set_user_settings(self, name, **data):
|
||||||
|
settings = self.data.user_settings.get(name, Settings())
|
||||||
|
settings.__dict__.update(data)
|
||||||
|
self.data.user_settings[name] = settings
|
||||||
|
await self.updated()
|
||||||
|
|
||||||
|
def get_global_settings(self):
|
||||||
|
return self.data.settings
|
||||||
|
|
||||||
|
async def set_global_settings(self, **data):
|
||||||
|
self.data.settings.__dict__.update(data)
|
||||||
|
await self.updated()
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
// Loads in ha-config-dashboard which is used to copy styling
|
|
||||||
// Also provides ha-settings-row
|
|
||||||
export const loadDevTools = async () => {
|
|
||||||
if (customElements.get("ha-config-dashboard")) return;
|
|
||||||
|
|
||||||
await customElements.whenDefined("partial-panel-resolver");
|
|
||||||
const ppResolver = document.createElement("partial-panel-resolver");
|
|
||||||
const routes = (ppResolver as any).getRoutes([
|
|
||||||
{
|
|
||||||
component_name: "config",
|
|
||||||
url_path: "a",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
await routes?.routes?.a?.load?.();
|
|
||||||
await customElements.whenDefined("ha-panel-config");
|
|
||||||
const configRouter = document.createElement("ha-panel-config");
|
|
||||||
await (configRouter as any)?.routerOptions?.routes?.dashboard?.load?.(); // Load ha-config-dashboard
|
|
||||||
await (configRouter as any)?.routerOptions?.routes?.cloud?.load?.(); // Load ha-settings-row
|
|
||||||
await customElements.whenDefined("ha-config-dashboard");
|
|
||||||
};
|
|
||||||
+7
-20
@@ -1,6 +1,9 @@
|
|||||||
import { LitElement, html, css } from "lit";
|
import { LitElement, html, css } from "lit";
|
||||||
import { property } from "lit/decorators.js";
|
import { property } from "lit/decorators.js";
|
||||||
import { loadDevTools } from "./helpers";
|
import { loadDevTools } from "../helpers";
|
||||||
|
import { loadHaForm } from "../helpers";
|
||||||
|
|
||||||
|
import "./settings-card";
|
||||||
|
|
||||||
const bmWindow = window as any;
|
const bmWindow = window as any;
|
||||||
|
|
||||||
@@ -292,25 +295,9 @@ loadDevTools().then(() => {
|
|||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
|
|
||||||
<ha-card outlined header="Tweaks">
|
<browser-mod-settings-card
|
||||||
<div class="card-content">
|
.hass=${this.hass}
|
||||||
<ha-settings-row>
|
></browser-mod-settings-card>
|
||||||
<span slot="heading">User sidebar</span>
|
|
||||||
<span slot="description"
|
|
||||||
>Save sidebar as default for current user
|
|
||||||
(${this.hass.user.name})</span
|
|
||||||
>
|
|
||||||
<mwc-button>Save</mwc-button>
|
|
||||||
</ha-settings-row>
|
|
||||||
<ha-settings-row>
|
|
||||||
<span slot="heading">Global sidebar</span>
|
|
||||||
<span slot="description"
|
|
||||||
>Save sidebar as default for all users</span
|
|
||||||
>
|
|
||||||
<mwc-button>Save</mwc-button>
|
|
||||||
</ha-settings-row>
|
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
</ha-app-layout>
|
</ha-app-layout>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import { LitElement, html, css } from "lit";
|
||||||
|
import { property, state } from "lit/decorators.js";
|
||||||
|
|
||||||
|
class BrowserModSettingsCard extends LitElement {
|
||||||
|
@property() hass;
|
||||||
|
|
||||||
|
@state() _selectedTab = 0;
|
||||||
|
|
||||||
|
firstUpdated() {
|
||||||
|
window.browser_mod.addEventListener("browser-mod-config-update", () =>
|
||||||
|
this.requestUpdate()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleSwitchTab(ev: CustomEvent) {
|
||||||
|
this._selectedTab = parseInt(ev.detail.index, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const level = ["browser", "user", "global"][this._selectedTab];
|
||||||
|
return html`
|
||||||
|
<ha-card header="Auto settings" outlined>
|
||||||
|
<div class="card-content">
|
||||||
|
<mwc-tab-bar
|
||||||
|
.activeIndex=${this._selectedTab}
|
||||||
|
@MDCTabBar:activated=${this._handleSwitchTab}
|
||||||
|
>
|
||||||
|
<mwc-tab .label=${"Browser"}></mwc-tab>
|
||||||
|
<mwc-tab .label=${"User (" + this.hass.user.name + ")"}></mwc-tab>
|
||||||
|
<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 user = window.browser_mod.user_settings;
|
||||||
|
const browser = window.browser_mod.browser_settings;
|
||||||
|
const current = { global, user, browser }[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`
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: ${DESC_BOOLEAN(current.kiosk)} ${OVERRIDDEN("kiosk")}
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() => window.browser_mod.set_setting("kiosk", true, level)}
|
||||||
|
>
|
||||||
|
Enable
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() => window.browser_mod.set_setting("kiosk", false, level)}
|
||||||
|
>
|
||||||
|
Disable
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button
|
||||||
|
@click=${() =>
|
||||||
|
window.browser_mod.set_setting("kiosk", undefined, level)}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Sidebar order</span>
|
||||||
|
<span slot="description">Order and visibility of sidebar buttons</span>
|
||||||
|
Currenty: ${DESC_SET_UNSET(current.sidebarPanelOrder)}
|
||||||
|
${OVERRIDDEN("sidebarPanelOrder")}
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<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>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
_render_user() {
|
||||||
|
return html`
|
||||||
|
User
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: Overridden
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Set screensaver</span>
|
||||||
|
<span slot="description"> Set screensaver card </span>
|
||||||
|
<mwc-button>Enable</mwc-button>
|
||||||
|
<mwc-button>Disable</mwc-button>
|
||||||
|
<mwc-button>Clear</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
_render_browser() {
|
||||||
|
return html`
|
||||||
|
Browser
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Kiosk mode</span>
|
||||||
|
<span slot="description"> Hide sidebar and header </span>
|
||||||
|
Currenty: Overridden
|
||||||
|
</ha-settings-row>
|
||||||
|
<ha-settings-row>
|
||||||
|
<span slot="heading">Set screensaver</span>
|
||||||
|
<span slot="description"> Set screensaver card </span>
|
||||||
|
<mwc-button>Enable</mwc-button>
|
||||||
|
<mwc-button>Disable</mwc-button>
|
||||||
|
<mwc-button>Clear</mwc-button>
|
||||||
|
</ha-settings-row>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define("browser-mod-settings-card", BrowserModSettingsCard);
|
||||||
@@ -85,3 +85,24 @@ export const loadHaForm = async () => {
|
|||||||
if (!card) return;
|
if (!card) return;
|
||||||
await card.getConfigElement();
|
await card.getConfigElement();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Loads in ha-config-dashboard which is used to copy styling
|
||||||
|
// Also provides ha-settings-row
|
||||||
|
export const loadDevTools = async () => {
|
||||||
|
if (customElements.get("ha-config-dashboard")) return;
|
||||||
|
|
||||||
|
await customElements.whenDefined("partial-panel-resolver");
|
||||||
|
const ppResolver = document.createElement("partial-panel-resolver");
|
||||||
|
const routes = (ppResolver as any).getRoutes([
|
||||||
|
{
|
||||||
|
component_name: "config",
|
||||||
|
url_path: "a",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await routes?.routes?.a?.load?.();
|
||||||
|
await customElements.whenDefined("ha-panel-config");
|
||||||
|
const configRouter = document.createElement("ha-panel-config");
|
||||||
|
await (configRouter as any)?.routerOptions?.routes?.dashboard?.load?.(); // Load ha-config-dashboard
|
||||||
|
await (configRouter as any)?.routerOptions?.routes?.cloud?.load?.(); // Load ha-settings-row
|
||||||
|
await customElements.whenDefined("ha-config-dashboard");
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
export const AutoSettingsMixin = (SuperClass) => {
|
||||||
|
return class AutoSettingsMixinClass extends SuperClass {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this._auto_settings_setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
async _auto_settings_setup() {
|
||||||
|
await this.connectionPromise;
|
||||||
|
|
||||||
|
const settings = this.settings;
|
||||||
|
|
||||||
|
if (settings.sidebarPanelOrder) {
|
||||||
|
localStorage.setItem("sidebarPanelOrder", settings.sidebarPanelOrder);
|
||||||
|
}
|
||||||
|
if (settings.sidebarHiddenPanels) {
|
||||||
|
localStorage.setItem(
|
||||||
|
"sidebarHiddenPanels",
|
||||||
|
settings.sidebarHiddenPanels
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
+59
-5
@@ -119,12 +119,66 @@ export const ConnectionMixin = (SuperClass) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get meta() {
|
get global_settings() {
|
||||||
if (!this.registered) return null;
|
const settings = {};
|
||||||
return this.browsers[this.browserID].meta;
|
const global = this._data.settings ?? {};
|
||||||
|
for (const [k, v] of Object.entries(global)) {
|
||||||
|
if (v !== null) settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
get user_settings() {
|
||||||
|
const settings = {};
|
||||||
|
const user = this._data.user_settings[this.hass.user.id] ?? {};
|
||||||
|
for (const [k, v] of Object.entries(user)) {
|
||||||
|
if (v !== null) settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
get browser_settings() {
|
||||||
|
const settings = {};
|
||||||
|
const browser = this.browsers[this.browserID]?.settings ?? {};
|
||||||
|
for (const [k, v] of Object.entries(browser)) {
|
||||||
|
if (v !== null) settings[k] = v;
|
||||||
|
}
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
get settings() {
|
||||||
|
return {
|
||||||
|
...this.global_settings,
|
||||||
|
...this.user_settings,
|
||||||
|
...this.browser_settings,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
set_setting(key, value, level) {
|
||||||
|
switch (level) {
|
||||||
|
case "global": {
|
||||||
|
this.connection.sendMessage({
|
||||||
|
type: "browser_mod/settings",
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "user": {
|
||||||
|
const user = this.hass.user.id;
|
||||||
|
this.connection.sendMessage({
|
||||||
|
type: "browser_mod/settings",
|
||||||
|
user,
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "browser": {
|
||||||
|
const settings = this.browsers[this.browserID]?.settings;
|
||||||
|
settings[key] = value;
|
||||||
|
this._reregister({ settings });
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set meta(value) {
|
|
||||||
this._reregister({ meta: value });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get cameraEnabled() {
|
get cameraEnabled() {
|
||||||
|
|||||||
+9
-4
@@ -14,6 +14,7 @@ import "./popups";
|
|||||||
import { PopupMixin } from "./popups";
|
import { PopupMixin } from "./popups";
|
||||||
import pjson from "../../package.json";
|
import pjson from "../../package.json";
|
||||||
import "./popup-card";
|
import "./popup-card";
|
||||||
|
import { AutoSettingsMixin } from "./auto-settings";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@@ -48,11 +49,13 @@ import "./popup-card";
|
|||||||
x Redesign services to target devices
|
x Redesign services to target devices
|
||||||
- frontend editor for popup cards
|
- frontend editor for popup cards
|
||||||
- also screensavers
|
- also screensavers
|
||||||
- Tweaks
|
- Saved frontend settings
|
||||||
- Save sidebar
|
X Framework
|
||||||
- Save sidebar per user
|
x Save sidebar
|
||||||
- Kiosk mode
|
- Kiosk mode
|
||||||
- Kiosk mode per user
|
- Default panel?
|
||||||
|
- Screensaver?
|
||||||
|
- Tweaks
|
||||||
- Favicon templates
|
- Favicon templates
|
||||||
- Title templates
|
- Title templates
|
||||||
- Quickbar tweaks (ctrl+enter)?
|
- Quickbar tweaks (ctrl+enter)?
|
||||||
@@ -67,6 +70,7 @@ export class BrowserMod extends ServicesMixin(
|
|||||||
CameraMixin(
|
CameraMixin(
|
||||||
MediaPlayerMixin(
|
MediaPlayerMixin(
|
||||||
ScreenSaverMixin(
|
ScreenSaverMixin(
|
||||||
|
AutoSettingsMixin(
|
||||||
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
|
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -74,6 +78,7 @@ export class BrowserMod extends ServicesMixin(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
Reference in new issue
Block a user