diff --git a/ext/src/ui/options/index.tsx b/ext/src/ui/options/index.tsx index a938375..07a438f 100644 --- a/ext/src/ui/options/index.tsx +++ b/ext/src/ui/options/index.tsx @@ -14,28 +14,24 @@ import logger from "../../lib/logger"; import options, { Options } from "../../lib/options"; import { REMOTE_MATCH_PATTERN_REGEX } from "../../lib/matchPattern"; - const _ = browser.i18n.getMessage; - // macOS styles -browser.runtime.getPlatformInfo() - .then(platformInfo => { - const link = document.createElement("link"); - link.rel = "stylesheet"; +browser.runtime.getPlatformInfo().then(platformInfo => { + const link = document.createElement("link"); + link.rel = "stylesheet"; - switch (platformInfo.os) { - case "mac": { - link.href = "styles/mac.css"; - break; - } + switch (platformInfo.os) { + case "mac": { + link.href = "styles/mac.css"; + break; } + } - if (link.href) { - document.head.appendChild(link); - } - }); - + if (link.href) { + document.head.appendChild(link); + } +}); function getInputValue(input: HTMLInputElement) { switch (input.type) { @@ -62,17 +58,15 @@ interface OptionsAppState { platform?: string; } -class OptionsApp extends Component< - OptionsAppProps, OptionsAppState> { - - private form: (HTMLFormElement | null) = null; +class OptionsApp extends Component { + private form: HTMLFormElement | null = null; state: OptionsAppState = { - hasLoaded: false - , bridgeLoading: true - , bridgeLoadingTimedOut: false - , isFormValid: true - , hasSaved: false + hasLoaded: false, + bridgeLoading: true, + bridgeLoadingTimedOut: false, + isFormValid: true, + hasSaved: false }; constructor(props: OptionsAppProps) { @@ -85,16 +79,16 @@ class OptionsApp extends Component< this.handleWhitelistChange = this.handleWhitelistChange.bind(this); this.getWhitelistItemPatternError = - this.getWhitelistItemPatternError.bind(this); + this.getWhitelistItemPatternError.bind(this); } public async componentDidMount() { this.setState({ - hasLoaded: true - , options: await options.getAll() - , platform: (await browser.runtime.getPlatformInfo()).os + hasLoaded: true, + options: await options.getAll(), + platform: (await browser.runtime.getPlatformInfo()).os }); - + // Update options data if changed whilst page is open options.addEventListener("changed", async () => { this.setState({ @@ -106,16 +100,16 @@ class OptionsApp extends Component< const bridgeInfo = await bridge.getInfo(); this.setState({ - bridgeInfo - , bridgeLoading: false + bridgeInfo, + bridgeLoading: false }); } catch (err) { logger.error("Failed to fetch bridge/platform info."); if (err instanceof BridgeTimedOutError) { this.setState({ - bridgeLoading: false - , bridgeLoadingTimedOut: true + bridgeLoading: false, + bridgeLoadingTimedOut: true }); } else { this.setState({ @@ -132,60 +126,76 @@ class OptionsApp extends Component< return (
-
{ this.form = form; }} - onSubmit={ this.handleFormSubmit } - onChange={ this.handleFormChange }> - - + { + this.form = form; + }} + onSubmit={this.handleFormSubmit} + onChange={this.handleFormChange} + > +
-

{ _("optionsMediaCategoryName") }

+

{_("optionsMediaCategoryName")}

- { _("optionsMediaCategoryDescription") } + {_("optionsMediaCategoryDescription")}

@@ -193,67 +203,81 @@ class OptionsApp extends Component<
-

{ _("optionsMirroringCategoryName") }

+

{_("optionsMirroringCategoryName")}

- { _("optionsMirroringCategoryDescription") } + {_("optionsMirroringCategoryDescription")}

@@ -261,108 +285,145 @@ class OptionsApp extends Component<
-

{ _("optionsReceiverSelectorCategoryName") }

+

{_("optionsReceiverSelectorCategoryName")}

- { _("optionsReceiverSelectorCategoryDescription") } + {_("optionsReceiverSelectorCategoryDescription")}

-

{ _("optionsUserAgentWhitelistCategoryName") }

+

+ {_("optionsUserAgentWhitelistCategoryName")} +

- { _("optionsUserAgentWhitelistCategoryDescription") } + {_("optionsUserAgentWhitelistCategoryDescription")}

- { _("optionsUserAgentWhitelistContent") } + {_("optionsUserAgentWhitelistContent")}
- { this.state.options?.userAgentWhitelist && - } + {this.state.options?.userAgentWhitelist && ( + + )}
- { this.state.hasSaved && _("optionsSaved") } + {this.state.hasSaved && _("optionsSaved")}
- -
@@ -370,7 +431,6 @@ class OptionsApp extends Component< ); } - private handleReset() { this.setState({ options: { ...defaultOptions } @@ -386,15 +446,18 @@ class OptionsApp extends Component< if (this.state.options) { await options.setAll(this.state.options); - this.setState({ - hasSaved: true - }, () => { - window.setTimeout(() => { - this.setState({ - hasSaved: false - }); - }, 1000); - }); + this.setState( + { + hasSaved: true + }, + () => { + window.setTimeout(() => { + this.setState({ + hasSaved: false + }); + }, 1000); + } + ); } } catch (err) { logger.error("Failed to save options");