import { LitElement, html, css } from "lit"; import { property, state } from "lit/decorators.js"; class BrowserModRegisteredBrowsersCard extends LitElement { @property() hass; @property() dirty = false; toggleRegister() { if (!window.browser_mod?.connected) return; window.browser_mod.registered = !window.browser_mod.registered; this.dirty = true; } changeBrowserID(ev) { window.browser_mod.browserID = ev.target.value; this.dirty = true; } toggleCameraEnabled() { window.browser_mod.cameraEnabled = !window.browser_mod.cameraEnabled; this.dirty = true; } firstUpdated() { window.browser_mod.addEventListener("browser-mod-config-update", () => this.requestUpdate() ); } render() { return html`

This Browser
${window.browser_mod?.connected ? html` ` : html` `}

${this.dirty ? html` It is strongly recommended to refresh your browser window after changing any of the settings in this box. ` : ""}
Register Enable this browser as a Device in Home Assistant Browser ID A unique identifier for this browser-device combination. ${window.browser_mod?.registered ? html` ${this._renderSuspensionAlert()} Enable camera Get camera input from this browser (hardware dependent) ${window.browser_mod?.cameraError ? html` Setting up the device camera failed. Make sure you have allowed use of the camera in your browser. ` : ""} ${this._renderInteractionAlert()} ${this._renderFKBSettingsInfo()} ` : ""}
`; } private _renderSuspensionAlert() { if (!this.hass.suspendWhenHidden) return html``; return html` Home Assistant will close the websocket connection to the server automatically after 5 minutes of inactivity.

While decreasing network trafic and memory usage, this may cause problems for browser_mod operation.

If you find that some things stop working for this Browser after a time, try going to your Profile Settings and disabling the option "${this.hass.localize("ui.panel.profile.suspend.header") || "Automatically close connection"}".
`; } private _renderInteractionAlert() { return html` For privacy reasons many browsers require the user to interact with a webpage before allowing audio playback or video capture. This may affect the media_player and camera components of Browser Mod.

If you ever see a symbol at the bottom right corner of the screen, please tap or click anywhere on the page. This should allow Browser Mod to work again.
`; } private _renderFKBSettingsInfo() { if (!window.browser_mod?.fully || !this.getFullySettings()) return html``; return html` ${window.browser_mod?.fully && this.getFullySettings() ? html` You are using FullyKiosk Browser. It is recommended to enable the following settings: ` : ""} `; } private getFullySettings() { if (!window.browser_mod.fully) return null; const retval = []; const wcs = []; // Web Content Settings // Autoplay Videos if (window.fully.getBooleanSetting("autoplayVideos") !== "true") wcs.push(html`
  • Autoplay Videos
  • `); // Autoplay Audio if (window.fully.getBooleanSetting("autoplayAudio") !== "true") wcs.push(html`
  • Autoplay Audio
  • `); // Enable Webcam Access (PLUS) if (window.fully.getBooleanSetting("webcamAccess") !== "true") wcs.push(html`
  • Enable Webcam Access (PLUS)
  • `); if (wcs.length !== 0) { retval.push(html`
  • Web Content Settings
  • `); } // Advanced Web Settings // Enable JavaScript Interface (PLUS) if (window.fully.getBooleanSetting("websiteIntegration") !== "true") retval.push(html`
  • Advanced Web Settings
  • `); // Device Management // Keep Screen On if (window.fully.getBooleanSetting("keepScreenOn") !== "true") retval.push(html`
  • Device Management
  • `); // Power Settings // Prevent from Sleep while Screen Off if (window.fully.getBooleanSetting("preventSleepWhileScreenOff") !== "true") retval.push(html`
  • Power Settings
  • `); const md = []; // Motion Detection (PLUS) // Enable Visual Motion Detection if (window.fully.getBooleanSetting("motionDetection") !== "true") md.push(html`
  • Enable Visual Motion Detection
  • `); // Turn Screen On on Motion if (window.fully.getBooleanSetting("screenOnOnMotion") !== "true") md.push(html`
  • Turn Screen On on Motion
  • `); // Exit Screensaver on Motion if (window.fully.getBooleanSetting("stopScreensaverOnMotion") !== "true") md.push(html`
  • Exit Screensaver on Motion
  • `); if (md.length !== 0) { retval.push(html`
  • Motion Detection (PLUS)
  • `); } // Remote Administration (PLUS) // Enable Remote Administration if (window.fully.getBooleanSetting("remoteAdmin") !== "true") retval.push(html`
  • Remote Administration (PLUS)
  • `); return retval.length ? retval : null; } static get styles() { return css` .card-header { display: flex; justify-content: space-between; } ha-textfield { width: 250px; display: block; margin-top: 8px; } `; } } customElements.define( "browser-mod-browser-settings-card", BrowserModRegisteredBrowsersCard );