Option to use screensaver instead of turning off screen in fully
This commit is contained in:
1 parent
180fad3ea0
commit
63812d821a
11 files changed
+608
-727
No files matched your search
@@ -2,3 +2,4 @@ node_modules/
|
|||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
.vscode
|
.vscode
|
||||||
.env
|
.env
|
||||||
|
custom_components/hacs/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
(()=>{var e={625:()=>{const e=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(e).then((()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html;e.prototype.css;customElements.get("browser-player-editor")||(customElements.define("browser-player-editor",class extends e{setConfig(e){}render(){return t` <div>Nothing to configure.</div> `}}),window.customCards=window.customCards||[],window.customCards.push({type:"browser-player",name:"Browser Player",preview:!0}))}))},306:e=>{"use strict";e.exports=JSON.parse('{"name":"browser_mod","private":true,"version":"1.3.1","description":"","scripts":{"build":"webpack","watch":"webpack --watch --mode=development","update-card-tools":"npm uninstall card-tools && npm install thomasloven/lovelace-card-tools"},"keywords":[],"author":"Thomas Lovén","license":"MIT","devDependencies":{"webpack":"^5.36.2","webpack-cli":"^4.7.0"},"dependencies":{"card-tools":"github:thomasloven/lovelace-card-tools"}}')}},t={};function o(s){var i=t[s];if(void 0!==i)return i.exports;var a=t[s]={exports:{}};return e[s](a,a.exports,o),a.exports}(()=>{"use strict";const e="lovelace-player-device-id";function t(){if(!localStorage[e]){const t=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[e]=fully.getDeviceId():localStorage[e]=`${t()}${t()}-${t()}${t()}`}return localStorage[e]}let s=t();const i=o=>{null!==o&&("clear"===o?localStorage.removeItem(e):localStorage[e]=o,s=t())},a=new URLSearchParams(window.location.search);function n(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function r(e){return document.querySelector("hc-main")?document.querySelector("hc-main").provideHass(e):document.querySelector("home-assistant")?document.querySelector("home-assistant").provideHass(e):void 0}function l(){var e,t=document.querySelector("hc-main");return t?((e=t._lovelaceConfig).current_view=t._lovelacePath,e):(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))?((e=t.lovelace).current_view=t.___curView,e):null}function c(){var e=document.querySelector("hc-main");return e?(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view"):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=document.querySelector("home-assistant"))&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root"))&&e.shadowRoot)&&e.querySelector("ha-app-layout"))&&e.querySelector("#view"))&&e.firstElementChild}async function d(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");if(e.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const t=document.createElement("ha-panel-lovelace");return t.hass=n(),void 0===t.hass&&(await new Promise((e=>{window.addEventListener("connection-status",(t=>{console.log(t),e()}),{once:!0})})),t.hass=n()),t.panel={config:{mode:null}},t._fetchConfig(),!0}async function h(e,t,o=!1){let s=e;"string"==typeof t&&(t=t.split(/(\$| )/)),""===t[t.length-1]&&t.pop();for(const[e,i]of t.entries())if(i.trim().length){if(!s)return null;s.localName&&s.localName.includes("-")&&await customElements.whenDefined(s.localName),s.updateComplete&&await s.updateComplete,s="$"===i?o&&e==t.length-1?[s.shadowRoot]:s.shadowRoot:o&&e==t.length-1?s.querySelectorAll(i):s.querySelector(i)}return s}async function u(e,t,o=!1,s=1e4){return Promise.race([h(e,t,o),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),s)))]).catch((e=>{if(!e.message||"timeout"!==e.message)throw e;return null}))}function p(e,t,o=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},o)o.dispatchEvent(e);else{var s=c();s&&s.dispatchEvent(e)}}a.get("deviceID")&&i(a.get("deviceID"));let m=window.cardHelpers;async function w(){const e=document.querySelector("home-assistant")||document.querySelector("hc-root");p("hass-more-info",{entityId:"."},e);const t=await u(e,"$ card-tools-popup");t&&t.closeDialog()}async function y(e,t,o=!1,s={},i=!1){if(!customElements.get("card-tools-popup")){const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(cLine truncated
|
const e="lovelace-player-device-id";function t(){if(!localStorage[e]){const t=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[e]=fully.getDeviceId():localStorage[e]=`${t()}${t()}-${t()}${t()}`}return localStorage[e]}let s=t();const o=o=>{null!==o&&("clear"===o?localStorage.removeItem(e):localStorage[e]=o,s=t())},i=new URLSearchParams(window.location.search);function a(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function n(e){return document.querySelector("hc-main")?document.querySelector("hc-main").provideHass(e):document.querySelector("home-assistant")?document.querySelector("home-assistant").provideHass(e):void 0}function r(){var e,t=document.querySelector("hc-main");return t?((e=t._lovelaceConfig).current_view=t._lovelacePath,e):(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))?((e=t.lovelace).current_view=t.___curView,e):null}function l(){var e=document.querySelector("hc-main");return e=e?(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("hc-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-view")||e.querySelector("hui-panel-view"):(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=document.querySelector("home-assistant"))&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root"))&&e.shadowRoot)&&e.querySelector("ha-app-layout"))&&e.querySelector("#view"))&&e.firstElementChild}async function c(){if(customElements.get("hui-view"))return!0;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");if(e.hass={panels:[{url_path:"tmp",component_name:"lovelace"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),!customElements.get("ha-panel-lovelace"))return!1;const t=document.createElement("ha-panel-lovelace");return t.hass=a(),void 0===t.hass&&(await new Promise((e=>{window.addEventListener("connection-status",(t=>{console.log(t),e()}),{once:!0})})),t.hass=a()),t.panel={config:{mode:null}},t._fetchConfig(),!0}async function d(e,t,s=!1){let o=e;"string"==typeof t&&(t=t.split(/(\$| )/)),""===t[t.length-1]&&t.pop();for(const[e,i]of t.entries())if(i.trim().length){if(!o)return null;o.localName&&o.localName.includes("-")&&await customElements.whenDefined(o.localName),o.updateComplete&&await o.updateComplete,o="$"===i?s&&e==t.length-1?[o.shadowRoot]:o.shadowRoot:s&&e==t.length-1?o.querySelectorAll(i):o.querySelector(i)}return o}async function h(e,t,s=!1,o=1e4){return Promise.race([d(e,t,s),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),o)))]).catch((e=>{if(!e.message||"timeout"!==e.message)throw e;return null}))}function u(e,t,s=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},s)s.dispatchEvent(e);else{var o=l();o&&o.dispatchEvent(e)}}i.get("deviceID")&&o(i.get("deviceID"));let m=window.cardHelpers;async function p(){const e=document.querySelector("home-assistant")||document.querySelector("hc-root");u("hass-more-info",{entityId:"."},e);const t=await h(e,"$ card-tools-popup");t&&t.closeDialog()}async function w(e,t,s=!1,o={},i=!1){if(!customElements.get("card-tools-popup")){const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html,s=e.prototype.css;class o extends e{static get properties(){return{open:{},large:{reflect:!0,type:Boolean},hass:{}}}updated(e){e.has("hass")&&this.card&&(this.card.hass=this.hass)}closeDialog(){this.open=!1}async _makeCard(){const e=await window.loadCardHelpers();this.card=await e.createCardElement(this._card),this.card.hass=this.hass,this.requestUpdate()}async _applyStyles(){let e=await h(this,"$ ha-dialog");customElements.whenDefined("card-mod").then((async()=>{if(!e)return;customElements.get("card-mod").applyToElement(e,"more-info",this._style,{config:this._card},[],!1)}))}async showDialog(e,t,s=!1,o={},i=!1){this.title=e,this._card=t,this.large=s,this._style=o,this.fullscreen=!!i,this._makeCard(),await this.updateComplete,this.open=!0,await this._applyStyles()}_enlarge(){this.large=!this.large}render(){return this.open?t`
|
||||||
<ha-dialog
|
<ha-dialog
|
||||||
open
|
open
|
||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
${this.card}
|
${this.card}
|
||||||
</div>
|
</div>
|
||||||
</ha-dialog>
|
</ha-dialog>
|
||||||
`:t``}static get styles(){return o`
|
`:t``}static get styles(){return s`
|
||||||
ha-dialog {
|
ha-dialog {
|
||||||
--mdc-dialog-min-width: 400px;
|
--mdc-dialog-min-width: 400px;
|
||||||
--mdc-dialog-max-width: 600px;
|
--mdc-dialog-max-width: 600px;
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
max-width: calc(90vw - 32px);
|
max-width: calc(90vw - 32px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`}}customElements.define("card-tools-popup",s)}const a=document.querySelector("home-assistant")||document.querySelector("hc-root");if(!a)return;let n=await u(a,"$ card-tools-popup");if(!n){n=document.createElement("card-tools-popup");const e=a.shadowRoot.querySelector("ha-more-info-dialog");e?a.shadowRoot.insertBefore(n,e):a.shadowRoot.appendChild(n),r(n)}if(!window._moreInfoDialogListener){const e=async e=>{if(e.state&&"cardToolsPopup"in e.state)if(e.state.cardToolsPopup){const{title:t,card:o,large:s,style:i,fullscreen:a}=e.state.params;y(t,o,s,i,a)}else n.closeDialog()};window.addEventListener("popstate",e),window._moreInfoDialogListener=!0}history.replaceState({cardToolsPopup:!1},""),history.pushState({cardToolsPopup:!0,params:{title:e,card:t,large:o,style:s,fullscreen:i}},""),n.showDialog(e,t,o,s,i)}async function _(e,t=!1){const o=document.querySelector("hc-main")||document.querySelector("home-assistant");p("hass-more-info",{entityId:e},o);const s=await u(o,"$ ha-more-info-dialog");return s&&(s.large=t),s}new Promise((async(e,t)=>{m&&e();const o=async()=>{m=await window.loadCardHelpers(),window.cardHelpers=m,e()};window.loadCardHelpers?o():window.addEventListener("load",(async()=>{d(),window.loadCardHelpers&&o()}))})),o(625);const v=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(v).then((()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html,o=e.prototype.css;customElements.get("browser-player")||customElements.define("browser-player",class extends e{static get properties(){return{hass:{}}}static getConfigElement(){return document.createElement("browser-player-editor")}static getStubConfig(){return{}}setConfig(e){this._config=e;for(const e of["play","pause","ended","volumechange","canplay","loadeddata"])window.browser_mod.player.addEventListener(e,(()=>this.requestUpdate()))}handleMute(e){window.browser_mod.player_mute()}handleVolumeChange(e){const t=parseFloat(e.target.value);window.browser_mod.player_set_volume(t)}handleMoreInfo(e){_("media_player."+window.browser_mod.entity_id)}handlePlayPause(e){window.browser_mod.player.paused?window.browser_mod.player_play():window.browser_mod.player_pause()}setDeviceID(){const e=prompt("Set deviceID",s);e!==s&&(i(e),this.requestUpdate())}render(){if(!window.browser_mod)return window.setTimeout((()=>this.requestUpdate()),100),t``;const e=window.browser_mod.player;return t`
|
`}}customElements.define("card-tools-popup",o)}const a=document.querySelector("home-assistant")||document.querySelector("hc-root");if(!a)return;let r=await h(a,"$ card-tools-popup");if(!r){r=document.createElement("card-tools-popup");const e=a.shadowRoot.querySelector("ha-more-info-dialog");e?a.shadowRoot.insertBefore(r,e):a.shadowRoot.appendChild(r),n(r)}if(!window._moreInfoDialogListener){const e=async e=>{if(e.state&&"cardToolsPopup"in e.state)if(e.state.cardToolsPopup){const{title:t,card:s,large:o,style:i,fullscreen:a}=e.state.params;w(t,s,o,i,a)}else r.closeDialog()};window.addEventListener("popstate",e),window._moreInfoDialogListener=!0}history.replaceState({cardToolsPopup:!1},""),history.pushState({cardToolsPopup:!0,params:{title:e,card:t,large:s,style:o,fullscreen:i}},""),r.showDialog(e,t,s,o,i)}async function y(e,t=!1){const s=document.querySelector("hc-main")||document.querySelector("home-assistant");u("hass-more-info",{entityId:e},s);const o=await h(s,"$ ha-more-info-dialog");return o&&(o.large=t),o}new Promise((async(e,t)=>{m&&e();const s=async()=>{m=await window.loadCardHelpers(),window.cardHelpers=m,e()};window.loadCardHelpers?s():window.addEventListener("load",(async()=>{c(),window.loadCardHelpers&&s()}))}));const _=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(_).then((()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html;e.prototype.css;class s extends e{setConfig(e){}render(){return t` <div>Nothing to configure.</div> `}}customElements.get("browser-player-editor")||(customElements.define("browser-player-editor",s),window.customCards=window.customCards||[],window.customCards.push({type:"browser-player",name:"Browser Player",preview:!0}))}));const v=[customElements.whenDefined("home-assistant-main"),customElements.whenDefined("hui-view")];Promise.race(v).then((()=>{const e=customElements.get("home-assistant-main")?Object.getPrototypeOf(customElements.get("home-assistant-main")):Object.getPrototypeOf(customElements.get("hui-view")),t=e.prototype.html,i=e.prototype.css;customElements.get("browser-player")||customElements.define("browser-player",class extends e{static get properties(){return{hass:{}}}static getConfigElement(){return document.createElement("browser-player-editor")}static getStubConfig(){return{}}setConfig(e){this._config=e;for(const e of["play","pause","ended","volumechange","canplay","loadeddata"])window.browser_mod.player.addEventListener(e,(()=>this.requestUpdate()))}handleMute(e){window.browser_mod.player_mute()}handleVolumeChange(e){const t=parseFloat(e.target.value);window.browser_mod.player_set_volume(t)}handleMoreInfo(e){y("media_player."+window.browser_mod.entity_id)}handlePlayPause(e){window.browser_mod.player.paused?window.browser_mod.player_play():window.browser_mod.player_pause()}setDeviceID(){const e=prompt("Set deviceID",s);e!==s&&(o(e),this.requestUpdate())}render(){if(!window.browser_mod)return window.setTimeout((()=>this.requestUpdate()),100),t``;const e=window.browser_mod.player;return t`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
|
|
||||||
<div class="device-id" @click=${this.setDeviceID}>${s}</div>
|
<div class="device-id" @click=${this.setDeviceID}>${s}</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`}static get styles(){return o`
|
`}static get styles(){return i`
|
||||||
paper-icon-button[highlight] {
|
paper-icon-button[highlight] {
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
}
|
}
|
||||||
@@ -139,4 +139,4 @@
|
|||||||
-moz-user-select: all;
|
-moz-user-select: all;
|
||||||
-ms-user-select: all;
|
-ms-user-select: all;
|
||||||
}
|
}
|
||||||
`}})}));class g{async connect(){if(null!==document.querySelector("hc-main"))this._connection=n().connection;else{if(!window.hassConnection)return void window.setTimeout((()=>this.connect()),100);this._connection=(await window.hassConnection).conn}this._connection.subscribeMessage((e=>this.msg_callback(e)),{type:"browser_mod/connect",deviceID:s}),this._hass_patched=!1,r(this)}set hass(e){this._hass=e}get connected(){return void 0!==this._connection}msg_callback(e){console.log(e)}sendUpdate(e){this.connected&&this._connection.sendMessage({type:"browser_mod/update",deviceID:s,data:e})}}const f=e=>class extends e{constructor(){super(),this.player=new Audio;for(const e of["play","pause","ended","volumechange"])this.player.addEventListener(e,(()=>this.player_update()));window.addEventListener("click",(()=>this.player.play()),{once:!0})}player_update(e){this.sendUpdate({player:{volume:this.player.volume,muted:this.player.muted,src:this.player.src,state:this.player_state}})}get player_state(){return this.player.src?this.player.ended?"stopped":this.player.paused?"paused":"playing":"stopped"}player_play(e){e&&(this.player.src=e),this.player.play()}player_pause(){this.player.pause()}player_stop(){this.player.pause(),this.player.src=null}player_set_volume(e){void 0!==e&&(this.player.volume=e)}player_mute(e){void 0===e&&(e=!this.player.muted),this.player.muted=Boolean(e)}},b=e=>class extends e{get isFully(){return void 0!==window.fully}constructor(){if(super(),this.isFully){this._fullyMotion=!1,this._motionTimeout=void 0;for(const e of["screenOn","screenOff","pluggedAC","pluggedUSB","onBatteryLevelChanged","unplugged","networkReconnect","onMotion"])window.fully.bind(e,`window.browser_mod.fully_update("${e}");`);this._keepingAlive=!1}}fully_update(e){this.isFully&&("screenOn"===e?(window.clearTimeout(this._keepAliveTimer),this._keepingAlive||this.screen_update()):"screenOff"===e?(this.screen_update(),this._keepingAlive=!1,this.config.force_stay_awake&&(this._keepAliveTimer=window.setTimeout((()=>{this._keepingAlive=!0,window.fully.turnScreenOn(),window.fully.turnScreenOff()}),27e4))):"onMotion"===e&&this.fullyMotionTriggered(),this.sendUpdate({fully:{battery:window.fully.getBatteryLevel(),charging:window.fully.isPlugged(),motion:this._fullyMotion,ip:window.fully.getIp4Address()}}))}fullyMotionTriggered(){this._keepingAlive||(this._fullyMotion=!0,clearTimeout(this._motionTimeout),this._motionTimeout=setTimeout((()=>{this._fullyMotion=!1,this.fully_update()}),5e3),this.fully_update())}},S=e=>class extends e{setup_camera(){console.log("Starting camera"),this._video||(this._video=document.createElement("video"),this._video.autoplay=!0,this._video.playsInline=!0,this._video.style.display="none",this._canvas=document.createElement("canvas"),this._canvas.style.display="none",document.body.appendChild(this._video),document.body.appendChild(this._canvas),navigator.mediaDevices&&(console.log("Starting devices"),navigator.mediaDevices.getUserMedia({video:!0,audio:!1}).then((e=>{this._video.srcObject=e,this._video.play(),this.update_camera()})),this._camera_framerate=2,window.addEventListener("click",(()=>this._video.play()),{once:!0})))}update_camera(){this._canvas.width=this._video.videoWidth,this._canvas.height=this._video.videoHeight,this._canvas.getContext("2d").drawImage(this._video,0,0,this._video.videoWidth,this._video.videoHeight),this.sendUpdate({camera:this._canvas.toDataURL("image/jpeg")}),setTimeout((()=>this.update_camera()),Math.round(1e3/this._camera_framerate))}},k=e=>class extends e{constructor(){super(),this._blackout_panel=document.createElement("div"),this._screenSaver=void 0,this._screenSaverTimer=void 0,this._screenSaverTimeOut=0,this._screenSaver={fn:void 0,clearfn:void 0,timer:void 0,timeout:void 0,listeners:{},active:!1},this._blackout_panel.style.cssText="\n position: fixed;\n left: 0;\n top: 0;\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n background: black;\n display: none;\n ",document.body.appendChild(this._blackout_panel)}screensaver_set(e,t,o){this._ss_clear(),this._screenSaver={fn:e,clearfn:t,timer:void 0,timeout:o,listeners:{},active:!1};const s=()=>this.screensaver_update();for(const e of["mousemove","mousedown","keydown","touchstart"])window.addEventListener(e,s),this._screenSaver.listeners[e]=s;this._screenSaver.timer=window.setTimeout((()=>this._ss_run()),1e3*o)}screensaver_update(){this._screenSaver.active?this.screensaver_stop():(window.clearTimeout(this._screenSaver.timer),this._screenSaver.timer=window.setTimeout((()=>this._ss_run()),1e3*this._screenSaver.timeout))}screensaver_stop(){this._ss_clear(),this._screenSaver.active=!1,this._screenSaver.clearfn&&this._screenSaver.clearfn(),this._screenSaver.timeout&&this.screensaver_set(this._screenSaver.fn,this._screenSaver.clearfn,this._screenSaver.timeout)}_ss_clear(){window.clearTimeout(this._screenSaverTimer);for(const
Line truncated
|
`}})}));class g{async connect(){if(null!==document.querySelector("hc-main"))this._connection=a().connection;else{if(!window.hassConnection)return void window.setTimeout((()=>this.connect()),100);this._connection=(await window.hassConnection).conn}this._connection.subscribeMessage((e=>this.msg_callback(e)),{type:"browser_mod/connect",deviceID:s}),this._hass_patched=!1,n(this)}set hass(e){this._hass=e}get connected(){return void 0!==this._connection}msg_callback(e){console.log(e)}sendUpdate(e){this.connected&&this._connection.sendMessage({type:"browser_mod/update",deviceID:s,data:e})}}const f=e=>class extends e{constructor(){super(),this.player=new Audio;for(const e of["play","pause","ended","volumechange"])this.player.addEventListener(e,(()=>this.player_update()));window.addEventListener("click",(()=>this.player.play()),{once:!0})}player_update(e){this.sendUpdate({player:{volume:this.player.volume,muted:this.player.muted,src:this.player.src,state:this.player_state}})}get player_state(){return this.player.src?this.player.ended?"stopped":this.player.paused?"paused":"playing":"stopped"}player_play(e){e&&(this.player.src=e),this.player.play()}player_pause(){this.player.pause()}player_stop(){this.player.pause(),this.player.src=null}player_set_volume(e){void 0!==e&&(this.player.volume=e)}player_mute(e){void 0===e&&(e=!this.player.muted),this.player.muted=Boolean(e)}},b=e=>class extends e{get isFully(){return void 0!==window.fully}constructor(){if(super(),this.isFully){this._fullyMotion=!1,this._motionTimeout=void 0;for(const e of["screenOn","screenOff","pluggedAC","pluggedUSB","onBatteryLevelChanged","unplugged","networkReconnect","onMotion"])window.fully.bind(e,`window.browser_mod.fully_update("${e}");`);window.fully.bind("onScreensaverStart","window.browser_mod.fully_screensaver = true; window.browser_mod.screen_update();"),window.fully.bind("onScreensaverStop","window.browser_mod.fully_screensaver = false; window.browser_mod.screen_update();"),this._keepingAlive=!1}}fully_update(e){this.isFully&&("screenOn"===e?(window.clearTimeout(this._keepAliveTimer),this._keepingAlive||this.screen_update()):"screenOff"===e?(this.screen_update(),this._keepingAlive=!1,this.config.force_stay_awake&&(this._keepAliveTimer=window.setTimeout((()=>{this._keepingAlive=!0,window.fully.turnScreenOn(),window.fully.turnScreenOff()}),27e4))):"onMotion"===e&&this.fullyMotionTriggered(),this.sendUpdate({fully:{battery:window.fully.getBatteryLevel(),charging:window.fully.isPlugged(),motion:this._fullyMotion,ip:window.fully.getIp4Address()}}))}fullyMotionTriggered(){this._keepingAlive||(this._fullyMotion=!0,clearTimeout(this._motionTimeout),this._motionTimeout=setTimeout((()=>{this._fullyMotion=!1,this.fully_update()}),5e3),this.fully_update())}},S=e=>class extends e{setup_camera(){console.log("Starting camera"),this._video||(this._video=document.createElement("video"),this._video.autoplay=!0,this._video.playsInline=!0,this._video.style.display="none",this._canvas=document.createElement("canvas"),this._canvas.style.display="none",document.body.appendChild(this._video),document.body.appendChild(this._canvas),navigator.mediaDevices&&(console.log("Starting devices"),navigator.mediaDevices.getUserMedia({video:!0,audio:!1}).then((e=>{this._video.srcObject=e,this._video.play(),this.update_camera()})),this._camera_framerate=2,window.addEventListener("click",(()=>this._video.play()),{once:!0})))}update_camera(){this._canvas.width=this._video.videoWidth,this._canvas.height=this._video.videoHeight;this._canvas.getContext("2d").drawImage(this._video,0,0,this._video.videoWidth,this._video.videoHeight),this.sendUpdate({camera:this._canvas.toDataURL("image/jpeg")}),setTimeout((()=>this.update_camera()),Math.round(1e3/this._camera_framerate))}},k=e=>class extends e{constructor(){super(),this._blackout_panel=document.createElement("div"),this._screenSaver=void 0,this._screenSaverTimer=void 0,this._screenSaverTimeOut=0,this._screenSaver={fn:void 0,clearfn:void 0,timer:void 0,timeout:void 0,listeners:{},active:!1},this._blackout_panel.style.cssText="\n position: fixed;\n left: 0;\n top: 0;\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n background: black;\n display: none;\n ",document.body.appendChild(this._blackout_panel)}screensaver_set(e,t,s){this._ss_clear(),this._screenSaver={fn:e,clearfn:t,timer:void 0,timeout:s,listeners:{},active:!1};const o=()=>this.screensaver_update();for(const e of["mousemove","mousedown","keydown","touchstart"])window.addEventListener(e,o),this._screenSaver.listeners[e]=o;this._screenSaver.timer=window.setTimeout((()=>this._ss_run()),1e3*s)}screensaver_update(){this._screenSaver.active?this.screensaver_stop():(window.clearTimeout(this._screenSaver.timer),this._screenSaver.timer=window.setTimeout((()=>this._ss_run()),1e3*this._screenSaver.timeout))}screensaver_stop(){this._ss_clear(),this._screenSaver.active
Line truncated
|
||||||
@@ -37,6 +37,7 @@ export const BrowserModBrowserMixin = (C) =>
|
|||||||
darkMode:
|
darkMode:
|
||||||
this._hass && this._hass.themes && this._hass.themes.darkMode,
|
this._hass && this._hass.themes && this._hass.themes.darkMode,
|
||||||
userData: this._hass && this._hass.user,
|
userData: this._hass && this._hass.user,
|
||||||
|
config: this.config,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ export const FullyKioskMixin = (C) =>
|
|||||||
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
|
window.fully.bind(ev, `window.browser_mod.fully_update("${ev}");`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.fully.bind(
|
||||||
|
"onScreensaverStart",
|
||||||
|
`window.browser_mod.fully_screensaver = true; window.browser_mod.screen_update();`
|
||||||
|
);
|
||||||
|
window.fully.bind(
|
||||||
|
"onScreensaverStop",
|
||||||
|
`window.browser_mod.fully_screensaver = false; window.browser_mod.screen_update();`
|
||||||
|
);
|
||||||
|
|
||||||
this._keepingAlive = false;
|
this._keepingAlive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -11,6 +11,7 @@ import { BrowserModCameraMixin } from "./camera";
|
|||||||
import { BrowserModScreensaverMixin } from "./screensaver";
|
import { BrowserModScreensaverMixin } from "./screensaver";
|
||||||
import { BrowserModPopupsMixin } from "./popups";
|
import { BrowserModPopupsMixin } from "./popups";
|
||||||
import { BrowserModBrowserMixin } from "./browser";
|
import { BrowserModBrowserMixin } from "./browser";
|
||||||
|
import pjson from "../package.json";
|
||||||
|
|
||||||
const ext = (baseClass, mixins) =>
|
const ext = (baseClass, mixins) =>
|
||||||
mixins.reduceRight((base, mixin) => mixin(base), baseClass);
|
mixins.reduceRight((base, mixin) => mixin(base), baseClass);
|
||||||
@@ -35,7 +36,6 @@ class BrowserMod extends ext(BrowserModConnection, [
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const pjson = require("../package.json");
|
|
||||||
console.info(
|
console.info(
|
||||||
`%cBROWSER_MOD ${pjson.version} IS INSTALLED
|
`%cBROWSER_MOD ${pjson.version} IS INSTALLED
|
||||||
%cDeviceID: ${deviceID}`,
|
%cDeviceID: ${deviceID}`,
|
||||||
|
|||||||
+17
-6
@@ -92,15 +92,21 @@ export const BrowserModScreensaverMixin = (C) =>
|
|||||||
do_blackout(timeout) {
|
do_blackout(timeout) {
|
||||||
this.screensaver_set(
|
this.screensaver_set(
|
||||||
() => {
|
() => {
|
||||||
if (this.isFully) window.fully.turnScreenOff(true);
|
if (this.isFully) {
|
||||||
else this._blackout_panel.style.display = "block";
|
if (this.config.screensaver) window.fully.startScreensaver();
|
||||||
|
else window.fully.turnScreenOff(true);
|
||||||
|
} else {
|
||||||
|
this._blackout_panel.style.display = "block";
|
||||||
|
}
|
||||||
this.screen_update();
|
this.screen_update();
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
if ((this._blackout_panel.style.display = "block"))
|
if ((this._blackout_panel.style.display = "block"))
|
||||||
this._blackout_panel.style.display = "none";
|
this._blackout_panel.style.display = "none";
|
||||||
if (this.isFully && !window.fully.getScreenOn())
|
if (this.isFully) {
|
||||||
window.fully.turnScreenOn();
|
if (!window.fully.getScreenOn()) window.fully.turnScreenOn();
|
||||||
|
window.fully.stopScreensaver();
|
||||||
|
}
|
||||||
this.screen_update();
|
this.screen_update();
|
||||||
},
|
},
|
||||||
timeout || 0
|
timeout || 0
|
||||||
@@ -108,7 +114,10 @@ export const BrowserModScreensaverMixin = (C) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
no_blackout() {
|
no_blackout() {
|
||||||
if (this.isFully) window.fully.turnScreenOn();
|
if (this.isFully) {
|
||||||
|
window.fully.turnScreenOn();
|
||||||
|
window.fully.stopScreensaver();
|
||||||
|
}
|
||||||
this.screensaver_stop();
|
this.screensaver_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +125,9 @@ export const BrowserModScreensaverMixin = (C) =>
|
|||||||
this.sendUpdate({
|
this.sendUpdate({
|
||||||
screen: {
|
screen: {
|
||||||
blackout: this.isFully
|
blackout: this.isFully
|
||||||
? !window.fully.getScreenOn()
|
? this.fully_screensaver !== undefined
|
||||||
|
? this.fully_screensaver
|
||||||
|
: !window.fully.getScreenOn()
|
||||||
: Boolean(this._blackout_panel.style.display === "block"),
|
: Boolean(this._blackout_panel.style.display === "block"),
|
||||||
brightness: this.isFully
|
brightness: this.isFully
|
||||||
? window.fully.getScreenBrightness()
|
? window.fully.getScreenBrightness()
|
||||||
|
|||||||
Generated
+537
-700
File diff suppressed because it is too large.
Load diff
+11
-5
@@ -1,19 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "browser_mod",
|
"name": "browser_mod",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack",
|
"build": "rollup -c",
|
||||||
"watch": "webpack --watch --mode=development",
|
"watch": "rollup -c --watch",
|
||||||
"update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools"
|
"update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Thomas Lovén",
|
"author": "Thomas Lovén",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"webpack": "^5.36.2",
|
"@babel/core": "^7.13.1",
|
||||||
"webpack-cli": "^4.7.0"
|
"@rollup/plugin-babel": "^5.3.0",
|
||||||
|
"@rollup/plugin-json": "^4.1.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
||||||
|
"rollup": "^2.39.0",
|
||||||
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
|
"rollup-plugin-typescript2": "^0.30.0",
|
||||||
|
"typescript": "^4.1.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"card-tools": "github:thomasloven/lovelace-card-tools"
|
"card-tools": "github:thomasloven/lovelace-card-tools"
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||||
|
import json from "@rollup/plugin-json";
|
||||||
|
// import typescript from "rollup-plugin-typescript2";
|
||||||
|
import { terser } from "rollup-plugin-terser";
|
||||||
|
import babel from "@rollup/plugin-babel";
|
||||||
|
|
||||||
|
const dev = process.env.ROLLUP_WATCH;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: "js/main.js",
|
||||||
|
output: {
|
||||||
|
file: "custom_components/browser_mod/browser_mod.js",
|
||||||
|
format: "es",
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
nodeResolve(),
|
||||||
|
json(),
|
||||||
|
// typescript(),
|
||||||
|
babel({
|
||||||
|
exclude: "node_modules/**",
|
||||||
|
}),
|
||||||
|
!dev && terser({ format: { comments: false } }),
|
||||||
|
],
|
||||||
|
};
|
||||||
@@ -10,6 +10,8 @@ browser_mod:
|
|||||||
alias: test
|
alias: test
|
||||||
fully:
|
fully:
|
||||||
force_stay_awake: true
|
force_stay_awake: true
|
||||||
|
fully2:
|
||||||
|
screensaver: true
|
||||||
|
|
||||||
lovelace:
|
lovelace:
|
||||||
mode: storage
|
mode: storage
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: './js/main.js',
|
|
||||||
mode: 'production',
|
|
||||||
output: {
|
|
||||||
filename: 'custom_components/browser_mod/browser_mod.js',
|
|
||||||
path: path.resolve(__dirname)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user