import { LitElement, html, css } from "lit"; import { property } from "lit/decorators.js"; import { loadDevTools } from "../helpers"; import { loadHaForm } from "../helpers"; import "./settings-card"; const bmWindow = window as any; loadDevTools().then(() => { class BrowserModPanel extends LitElement { @property() hass; @property() narrow; @property() connection; @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; } unregister_browser(ev) { const browserID = ev.currentTarget.browserID; const unregisterCallback = () => { console.log(browserID, window.browser_mod.browserID); if (browserID === window.browser_mod.browserID) { console.log("Unregister self"); window.browser_mod.registered = false; } else { window.browser_mod.connection.sendMessage({ type: "browser_mod/unregister", browserID, }); } }; window.browser_mod.showPopup( "Unregister browser", `Are you sure you want to unregister browser ${browserID}?`, { right_button: "Yes", right_button_action: unregisterCallback, left_button: "No", } ); } firstUpdated() { window.browser_mod.addEventListener("browser-mod-config-update", () => this.requestUpdate() ); } 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; } render() { return html`
    Browser Mod Settings

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

    Settings that apply to this browser.

    ${this.dirty ? html` It is strongly recommended to refresh your browser window after changing any of the settings in this box. ` : ""}
    Enable Enable this browser as a Device in Home Assistant BrowserID A unique identifier for this browser-device combination. ${window.browser_mod?.registered ? html` ${this.hass.suspendWhenHidden ? 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"}".
    ` : ""} Enable camera Get camera input from this browser (hardware dependent) For security 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.
    ${window.browser_mod?.fully && this.getFullySettings() ? html` You are using FullyKiosk Browser. It is recommended to enable the following settings:
      ${this.getFullySettings()}
    ` : ""} ` : ""}
    ${Object.keys(window.browser_mod.browsers).map( (d) => html` ${d} Last connected: ` )}
    `; } static get styles() { return [ ...((customElements.get("ha-config-dashboard") as any)?.styles ?? []), css` :host { --app-header-background-color: var(--sidebar-background-color); --app-header-text-color: var(--sidebar-text-color); --app-header-border-bottom: 1px solid var(--divider-color); --ha-card-border-radius: var(--ha-config-card-border-radius, 8px); } .card-header { display: flex; justify-content: space-between; } .card-actions { display: flex; } .spacer { flex-grow: 1; } ha-textfield { width: 250px; display: block; margin-top: 8px; } .option { display: flex; margin-top: 16px; } .option h3 { flex-grow: 1; margin: 0; } .option ha-switch { margin-top: 0.25em; margin-right: 7px; margin-left: 0.5em; } ha-icon-button > * { display: flex; } `, ]; } } customElements.define("browser-mod-panel", BrowserModPanel); });