import { LitElement, html, css } from "lit"; import { property } from "lit/decorators.js"; import { loadDevTools } from "./helpers"; 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() ); } 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.
` : ""}
${Object.keys(window.browser_mod.browsers).map( (d) => html` ${d} Last connected: ` )}
User sidebar Save sidebar as default for current user (${this.hass.user.name}) Save Global sidebar Save sidebar as default for all users Save
`; } 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); });