/* tslint:disable:max-line-length */ "use strict"; import React, { Component } from "react"; import ReactDOM from "react-dom"; import defaultOptions from "../../defaultOptions"; import Bridge from "./Bridge"; import EditableList from "./EditableList"; import bridge, { BridgeInfo } from "../../lib/bridge"; import logger from "../../lib/logger"; import options, { Options } from "../../lib/options"; import { REMOTE_MATCH_PATTERN_REGEX } from "../../lib/utils"; import { ReceiverSelectorType } from "../../background/receiverSelector"; const _ = browser.i18n.getMessage; const LICENSE = `Copyright (c) 2018 Matt Hensman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`; // macOS styles browser.runtime.getPlatformInfo() .then(platformInfo => { const link = document.createElement("link"); link.rel = "stylesheet"; switch (platformInfo.os) { case "mac": { link.href = "styles/mac.css"; break; } // Fix issue with input[type="number"] height case "linux": { link.href = "styles/linux.css"; const input = document.createElement("input"); const inputWrapper = document.createElement("div"); inputWrapper.append(input); document.documentElement.append(inputWrapper); input.type = "text"; const textInputHeight = window.getComputedStyle(input).height; input.type = "number"; const numberInputHeight = window.getComputedStyle(input).height; inputWrapper.remove(); if (numberInputHeight !== textInputHeight) { const style = document.createElement("style"); style.textContent = ` input[type="number"] { height: ${textInputHeight}; } `; document.body.append(style); } break; } } if (link.href) { document.head.appendChild(link); } }); function getInputValue (input: HTMLInputElement) { switch (input.type) { case "checkbox": return input.checked; case "number": return parseFloat(input.value); default: return input.value; } } interface OptionsAppState { hasLoaded: boolean; bridgeLoading: boolean; bridgeLoadingTimedOut: boolean; isFormValid: boolean; hasSaved: boolean; options?: Options; bridgeInfo?: BridgeInfo; platform?: string; } class OptionsApp extends Component<{}, OptionsAppState> { private form: (HTMLFormElement | null) = null; constructor (props: {}) { super(props); this.state = { hasLoaded: false , bridgeLoading: true , bridgeLoadingTimedOut: false , isFormValid: true , hasSaved: false }; this.handleReset = this.handleReset.bind(this); this.handleFormSubmit = this.handleFormSubmit.bind(this); this.handleFormChange = this.handleFormChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this); this.handleWhitelistChange = this.handleWhitelistChange.bind(this); this.handleReceiverSelectorTypeChange = this.handleReceiverSelectorTypeChange.bind(this); this.getWhitelistItemPatternError = this.getWhitelistItemPatternError.bind(this); } public async componentDidMount () { this.setState({ hasLoaded: true , options: await options.getAll() , platform: (await browser.runtime.getPlatformInfo()).os }); const bridgeTimeoutId = setTimeout(() => { this.setState({ bridgeLoading: false , bridgeLoadingTimedOut: true }); }, 500); try { const bridgeInfo = await bridge.getInfo(); this.setState({ bridgeInfo , bridgeLoading: false }); } catch { logger.error("Failed to fetch bridge/platform info."); this.setState({ bridgeLoading: false }); } clearTimeout(bridgeTimeoutId); } public render () { if (!this.state.hasLoaded) { return; } return (
{ this.form = form; }} onSubmit={ this.handleFormSubmit } onChange={ this.handleFormChange }>

{ _("optionsMediaCategoryName") }

{ _("optionsMediaCategoryDescription") }


{ _("optionsMirroringCategoryName") }

{ _("optionsMirroringCategoryDescription") }

{ _("optionsReceiverSelectorCategoryName") }

{ _("optionsReceiverSelectorCategoryDescription") }

{ this.state.platform === "mac" && }

{ _("optionsUserAgentWhitelistCategoryName") }

{ _("optionsUserAgentWhitelistCategoryDescription") }

{ _("optionsUserAgentWhitelistContent") }
{ this.state.options?.userAgentWhitelist && }
{ this.state.hasSaved && _("optionsSaved") }

ABOUT

GitHub

: @hensm/fx_cast

LICENSE

{ LICENSE.replace(/(\S)\n(\S)/g, "$1 $2") }

TRANSLATORS

  • @RAVMN
    es
  • @rimrul
    de
  • @ThaDaVos
    nl
  • @Vistaus
    nl
); } private handleReset () { this.setState({ options: { ...defaultOptions } }); } private async handleFormSubmit (ev: React.FormEvent) { ev.preventDefault(); this.form?.reportValidity(); try { if (this.state.options) { await options.setAll(this.state.options); this.setState({ hasSaved: true }, () => { window.setTimeout(() => { this.setState({ hasSaved: false }); }, 1000); }); } } catch (err) { logger.error("Failed to save options"); } } private handleFormChange (ev: React.FormEvent) { ev.preventDefault(); const isFormValid = this.form?.checkValidity(); if (isFormValid !== undefined) { this.setState({ isFormValid }); } } private handleInputChange (ev: React.ChangeEvent) { this.setState(currentState => { if (currentState.options) { currentState.options[ev.target.name] = getInputValue(ev.target); } return currentState; }); } private handleReceiverSelectorTypeChange ( ev: React.ChangeEvent) { this.setState(currentState => { if (currentState.options) { currentState.options[ev.target.name] = parseInt(ev.target.value); } return currentState; }); } private handleWhitelistChange (whitelist: string[]) { this.setState(currentState => { if (currentState.options) { currentState.options.userAgentWhitelist = whitelist; } return currentState; }); } private getWhitelistItemPatternError (info: string): string { return _("optionsUserAgentWhitelistInvalidMatchPattern", info); } } ReactDOM.render( , document.querySelector("#root"));