/* 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 options, { Options } from "../../lib/options"; import { REMOTE_MATCH_PATTERN_REGEX } from "../../lib/utils"; import { ReceiverSelectorType } from "../../background/receiverSelector"; const _ = browser.i18n.getMessage; // 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; options: Options; bridgeInfo: BridgeInfo; platform: string; bridgeLoading: boolean; isFormValid: boolean; hasSaved: boolean; } class OptionsApp extends Component<{}, OptionsAppState> { private form: HTMLFormElement; constructor (props: {}) { super(props); this.state = { hasLoaded: false , options: null , bridgeInfo: null , platform: null , bridgeLoading: true , 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() }); const bridgeInfo = await bridge.getInfo(); const { os } = await browser.runtime.getPlatformInfo(); this.setState({ bridgeInfo , platform: os , bridgeLoading: false }); } public render () { if (!this.state.hasLoaded) { return; } return (