diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-02-19 12:59:39 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-02-19 12:59:39 +0100 |
| commit | 88957fdee24db8273fc76dec59445031099e560c (patch) | |
| tree | 39243d5a5b442b9544dc3c5043bb0a4a50a4feb3 /gui/src | |
| parent | 24cc696a68bd60ce0b33f218369313ef522fff4b (diff) | |
| parent | fc08f0b88c205877ec0b20f6bcae7810d9b4dde5 (diff) | |
| download | mullvadvpn-88957fdee24db8273fc76dec59445031099e560c.tar.xz mullvadvpn-88957fdee24db8273fc76dec59445031099e560c.zip | |
Merge branch 'migrate-to-eslint'
Diffstat (limited to 'gui/src')
25 files changed, 103 insertions, 120 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts index 24f9c0453a..7ef103fe92 100644 --- a/gui/src/main/account-data-cache.ts +++ b/gui/src/main/account-data-cache.ts @@ -101,7 +101,6 @@ export default class AccountDataCache { private scheduleRetry(accountToken: AccountToken) { this.fetchAttempt += 1; - // tslint:disable-next-line const delay = Math.min(2048, 1 << (this.fetchAttempt + 2)) * 1000; log.warn(`Failed to fetch account data. Retrying in ${delay} ms`); diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 32620c3574..6d146eb418 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1221,6 +1221,7 @@ class ApplicationMain { } private async installDevTools() { + // eslint-disable-next-line @typescript-eslint/no-var-requires const installer = require('electron-devtools-installer'); const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']; const forceDownload = !!process.env.UPGRADE_EXTENSIONS; @@ -1401,9 +1402,9 @@ class ApplicationMain { // setup NSEvent monitor to fix inconsistent window.blur on macOS // see https://github.com/electron/electron/issues/8689 private installMacOsMenubarAppWindowHandlers(tray: Tray, windowController: WindowController) { + // eslint-disable-next-line @typescript-eslint/no-var-requires const { NSEventMonitor, NSEventMask } = require('nseventmonitor'); const macEventMonitor = new NSEventMonitor(); - // tslint:disable-next-line const eventMask = NSEventMask.leftMouseDown | NSEventMask.rightMouseDown; const window = windowController.window; diff --git a/gui/src/main/jsonrpc-client.ts b/gui/src/main/jsonrpc-client.ts index 357d085a14..3b33f8f566 100644 --- a/gui/src/main/jsonrpc-client.ts +++ b/gui/src/main/jsonrpc-client.ts @@ -275,7 +275,7 @@ export default class JsonRpcClient<T> extends EventEmitter { if (message.type === 'notification') { this.onNotification(message as IJsonRpcNotification); } else { - this.onReply(message as (IJsonRpcErrorResponse | IJsonRpcSuccess)); + this.onReply(message as IJsonRpcErrorResponse | IJsonRpcSuccess); } } diff --git a/gui/src/main/keyframe-animation.ts b/gui/src/main/keyframe-animation.ts index 1a95e1a106..f4ecb34743 100644 --- a/gui/src/main/keyframe-animation.ts +++ b/gui/src/main/keyframe-animation.ts @@ -8,16 +8,16 @@ export interface IKeyframeAnimationOptions { export type KeyframeAnimationRange = [number, number]; export default class KeyframeAnimation { - private speedValue: number = 200; // ms + private speedValue = 200; // ms private onFrameValue?: OnFrameFn; private onFinishValue?: OnFinishFn; - private currentFrameValue: number = 0; - private targetFrame: number = 0; + private currentFrameValue = 0; + private targetFrame = 0; - private isRunningValue: boolean = false; - private isFinishedValue: boolean = false; + private isRunningValue = false; + private isFinishedValue = false; private timeout?: NodeJS.Timeout; diff --git a/gui/src/main/window-controller.ts b/gui/src/main/window-controller.ts index e681b2a595..bed0774b5e 100644 --- a/gui/src/main/window-controller.ts +++ b/gui/src/main/window-controller.ts @@ -157,7 +157,7 @@ export default class WindowController { this.installWindowReadyHandlers(); } - public show(whenReady: boolean = true) { + public show(whenReady = true) { if (whenReady) { this.executeWhenWindowIsReady(() => this.showImmediately()); } else { diff --git a/gui/src/renderer/.eslintrc.js b/gui/src/renderer/.eslintrc.js new file mode 100644 index 0000000000..c38aa97590 --- /dev/null +++ b/gui/src/renderer/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + browser: true, + }, +}; diff --git a/gui/src/renderer/components/Modal.tsx b/gui/src/renderer/components/Modal.tsx index b0a972955d..31eb8eec24 100644 --- a/gui/src/renderer/components/Modal.tsx +++ b/gui/src/renderer/components/Modal.tsx @@ -32,7 +32,11 @@ const styles = { }), }; -export const ModalContent: React.FC = ({ children }) => { +interface IModalContentProps { + children?: React.ReactNode; +} + +export const ModalContent: React.FC = (props: IModalContentProps) => { return ( <div style={{ @@ -45,12 +49,16 @@ export const ModalContent: React.FC = ({ children }) => { right: 0, bottom: 0, }}> - {children} + {props.children} </div> ); }; -const ModalBackground: React.FC = ({ children }) => { +interface IModalBackgroundProps { + children?: React.ReactNode; +} + +const ModalBackground: React.FC = (props: IModalBackgroundProps) => { return ( <div style={{ @@ -64,13 +72,17 @@ const ModalBackground: React.FC = ({ children }) => { right: 0, bottom: 0, }}> - {children} + {props.children} </div> ); }; -export const ModalContainer: React.FC = ({ children }) => { - return <div style={{ position: 'relative', flex: 1 }}>{children}</div>; +interface IModalContainerProps { + children?: React.ReactNode; +} + +export const ModalContainer: React.FC = (props: IModalContainerProps) => { + return <div style={{ position: 'relative', flex: 1 }}>{props.children}</div>; }; export enum ModalAlertType { diff --git a/gui/src/renderer/components/NavigationBar.tsx b/gui/src/renderer/components/NavigationBar.tsx index cba9df0786..37f47816a9 100644 --- a/gui/src/renderer/components/NavigationBar.tsx +++ b/gui/src/renderer/components/NavigationBar.tsx @@ -124,12 +124,16 @@ interface INavigationScrollContextValue { showsBarSeparator: boolean; } +interface INavigationContainerProps { + children?: React.ReactNode; +} + const NavigationScrollContext = React.createContext<INavigationScrollContextValue>({ showsBarTitle: false, showsBarSeparator: false, }); -export class NavigationContainer extends Component { +export class NavigationContainer extends Component<INavigationContainerProps> { public state = { navigationContainer: this, showsBarTitle: false, diff --git a/gui/src/renderer/components/NotificationArea.tsx b/gui/src/renderer/components/NotificationArea.tsx index 243b406518..3876793ff8 100644 --- a/gui/src/renderer/components/NotificationArea.tsx +++ b/gui/src/renderer/components/NotificationArea.tsx @@ -54,7 +54,6 @@ function getTunnelParameterMessage(err: TunnelParameterError): string { 'in-app-notifications', 'WireGuard key not published to our servers. You can manage your key in Advanced settings.', ); - break; case 'custom_tunnel_host_resultion_error': return messages.pgettext( 'in-app-notifications', @@ -72,7 +71,7 @@ function getErrorCauseMessage(blockReason: ErrorStateCause): string { 'in-app-notifications', 'Could not configure IPv6, please enable it on your system or disable it in the app', ); - case 'set_firewall_policy_error': + case 'set_firewall_policy_error': { let extraMessage = null; switch (process.platform) { case 'linux': @@ -89,6 +88,7 @@ function getErrorCauseMessage(blockReason: ErrorStateCause): string { 'in-app-notifications', 'Failed to apply firewall rules. The device might currently be unsecured', )}${extraMessage ? '. ' + extraMessage : ''}`; + } case 'set_dns_error': return messages.pgettext('in-app-notifications', 'Failed to set system DNS server'); case 'start_tunnel_error': diff --git a/gui/src/renderer/components/NotificationBanner.tsx b/gui/src/renderer/components/NotificationBanner.tsx index b8f935f3c0..ba626c07f4 100644 --- a/gui/src/renderer/components/NotificationBanner.tsx +++ b/gui/src/renderer/components/NotificationBanner.tsx @@ -70,13 +70,21 @@ const styles = { }), }; -export class NotificationTitle extends Component { +interface INotificationTitleProps { + children?: React.ReactNode; +} + +export class NotificationTitle extends Component<INotificationTitleProps> { public render() { return <Text style={styles.title}>{this.props.children}</Text>; } } -export class NotificationSubtitle extends Component { +interface INotificationSubtitleProps { + children?: React.ReactNode; +} + +export class NotificationSubtitle extends Component<INotificationSubtitleProps> { public render() { return React.Children.count(this.props.children) > 0 ? ( <Text style={styles.subtitle}>{this.props.children}</Text> @@ -84,7 +92,12 @@ export class NotificationSubtitle extends Component { } } -export class NotificationOpenLinkAction extends Component<{ onPress: () => Promise<void> }> { +interface INotifcationOpenLinkActionProps { + onPress: () => Promise<void>; + children?: React.ReactNode; +} + +export class NotificationOpenLinkAction extends Component<INotifcationOpenLinkActionProps> { public state = { hovered: false, }; @@ -116,19 +129,32 @@ export class NotificationOpenLinkAction extends Component<{ onPress: () => Promi }; } -export class NotificationContent extends Component { +interface INotificationContentProps { + children?: React.ReactNode; +} + +export class NotificationContent extends Component<INotificationContentProps> { public render() { return <View style={styles.textContainer}>{this.props.children}</View>; } } -export class NotificationActions extends Component { +interface INotificationActionsProps { + children?: React.ReactNode; +} + +export class NotificationActions extends Component<INotificationActionsProps> { public render() { return <View style={styles.actionContainer}>{this.props.children}</View>; } } -export class NotificationIndicator extends Component<{ type: 'success' | 'warning' | 'error' }> { +interface INotificationIndicatorProps { + type: 'success' | 'warning' | 'error'; + children?: React.ReactNode; +} + +export class NotificationIndicator extends Component<INotificationIndicatorProps> { public render() { return <View style={[styles.indicator.base, styles.indicator[this.props.type]]} />; } diff --git a/gui/src/renderer/components/Support.tsx b/gui/src/renderer/components/Support.tsx index c7cae9889d..f8617234aa 100644 --- a/gui/src/renderer/components/Support.tsx +++ b/gui/src/renderer/components/Support.tsx @@ -94,25 +94,15 @@ export default class Support extends Component<ISupportProps, ISupportState> { }; public onSend = async (): Promise<void> => { - switch (this.state.sendState) { - case SendState.Initial: - if (this.state.email.length === 0) { - this.setState({ sendState: SendState.Confirm }); - break; - } else { - // fallthrough - } - - case SendState.Confirm: - try { - await this.sendReport(); - } catch (error) { - // No-op - } - break; - - default: - break; + const sendState = this.state.sendState; + if (sendState === SendState.Initial && this.state.email.length === 0) { + this.setState({ sendState: SendState.Confirm }); + } else if (sendState === SendState.Initial || sendState === SendState.Confirm) { + try { + await this.sendReport(); + } catch (error) { + // No-op + } } }; diff --git a/gui/src/renderer/components/WireguardKeys.tsx b/gui/src/renderer/components/WireguardKeys.tsx index dacdfcdc72..0c6f64acde 100644 --- a/gui/src/renderer/components/WireguardKeys.tsx +++ b/gui/src/renderer/components/WireguardKeys.tsx @@ -117,10 +117,11 @@ export default class WireguardKeys extends Component<IProps> { private getOnVerifyKeyCb() { return () => { switch (this.props.keyState.type) { - case 'key-set': + case 'key-set': { const key = this.props.keyState.key; this.props.onVerifyKey(key); break; + } default: log.error(`onVerifyKey called from invalid state - ${this.props.keyState.type}`); } @@ -135,11 +136,12 @@ export default class WireguardKeys extends Component<IProps> { let generateKey = this.props.onGenerateKey; switch (this.props.keyState.type) { - case 'key-set': + case 'key-set': { buttonText = regenerateText; const key = this.props.keyState.key; generateKey = () => this.props.onReplaceKey(key); break; + } case 'being-verified': return this.busyButton(regenerateText); case 'being-replaced': @@ -165,7 +167,7 @@ export default class WireguardKeys extends Component<IProps> { private getKeyText() { switch (this.props.keyState.type) { case 'being-verified': - case 'key-set': + case 'key-set': { // mimicking the truncating of the key from website const publicKey = this.props.keyState.key.publicKey; return ( @@ -175,6 +177,7 @@ export default class WireguardKeys extends Component<IProps> { </Text> </View> ); + } case 'being-replaced': case 'being-generated': return <ImageView source="icon-spinner" height={19} width={19} />; @@ -198,7 +201,7 @@ export default class WireguardKeys extends Component<IProps> { switch (this.props.keyState.type) { case 'being-verified': return <ImageView source="icon-spinner" height={20} width={20} />; - case 'key-set': + case 'key-set': { const key = this.props.keyState.key; if (key.valid === true) { return ( @@ -234,8 +237,10 @@ export default class WireguardKeys extends Component<IProps> { {messages.pgettext('wireguard-key-view', 'Key verification failed')} </Text> ); + } else { + return null; } - + } default: return null; } diff --git a/gui/src/renderer/containers/AccountPage.tsx b/gui/src/renderer/containers/AccountPage.tsx index 0fea11da8b..945512a2f7 100644 --- a/gui/src/renderer/containers/AccountPage.tsx +++ b/gui/src/renderer/containers/AccountPage.tsx @@ -26,9 +26,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(Account), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(Account)); diff --git a/gui/src/renderer/containers/AdvancedSettingsPage.tsx b/gui/src/renderer/containers/AdvancedSettingsPage.tsx index 6cbd991325..b61003bc8f 100644 --- a/gui/src/renderer/containers/AdvancedSettingsPage.tsx +++ b/gui/src/renderer/containers/AdvancedSettingsPage.tsx @@ -149,9 +149,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(AdvancedSettings), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(AdvancedSettings)); diff --git a/gui/src/renderer/containers/ConnectPage.tsx b/gui/src/renderer/containers/ConnectPage.tsx index de691b0db9..97eb499fab 100644 --- a/gui/src/renderer/containers/ConnectPage.tsx +++ b/gui/src/renderer/containers/ConnectPage.tsx @@ -110,9 +110,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(Connect), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(Connect)); diff --git a/gui/src/renderer/containers/ConnectionPanelContainer.tsx b/gui/src/renderer/containers/ConnectionPanelContainer.tsx index 44d3330c78..b3b67e9438 100644 --- a/gui/src/renderer/containers/ConnectionPanelContainer.tsx +++ b/gui/src/renderer/containers/ConnectionPanelContainer.tsx @@ -69,7 +69,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch) => { }; }; -export default connect( - mapStateToProps, - mapDispatchToProps, -)(ConnectionPanel); +export default connect(mapStateToProps, mapDispatchToProps)(ConnectionPanel); diff --git a/gui/src/renderer/containers/LaunchPage.tsx b/gui/src/renderer/containers/LaunchPage.tsx index cc50fae24f..aae7293bb1 100644 --- a/gui/src/renderer/containers/LaunchPage.tsx +++ b/gui/src/renderer/containers/LaunchPage.tsx @@ -14,7 +14,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch) => { }; }; -export default connect( - mapStateToProps, - mapDispatchToProps, -)(Launch); +export default connect(mapStateToProps, mapDispatchToProps)(Launch); diff --git a/gui/src/renderer/containers/LoginPage.tsx b/gui/src/renderer/containers/LoginPage.tsx index da4a6948dc..9b39520881 100644 --- a/gui/src/renderer/containers/LoginPage.tsx +++ b/gui/src/renderer/containers/LoginPage.tsx @@ -35,9 +35,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(Login), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(Login)); diff --git a/gui/src/renderer/containers/NotificationAreaContainer.tsx b/gui/src/renderer/containers/NotificationAreaContainer.tsx index f282c48fab..1eed9f4a17 100644 --- a/gui/src/renderer/containers/NotificationAreaContainer.tsx +++ b/gui/src/renderer/containers/NotificationAreaContainer.tsx @@ -27,9 +27,4 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(NotificationArea), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(NotificationArea)); diff --git a/gui/src/renderer/containers/PreferencesPage.tsx b/gui/src/renderer/containers/PreferencesPage.tsx index e1b674e0dd..068f6f8d1d 100644 --- a/gui/src/renderer/containers/PreferencesPage.tsx +++ b/gui/src/renderer/containers/PreferencesPage.tsx @@ -47,9 +47,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(Preferences), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(Preferences)); diff --git a/gui/src/renderer/containers/SelectLanguagePage.tsx b/gui/src/renderer/containers/SelectLanguagePage.tsx index 4be5e5472a..f72c79d1f2 100644 --- a/gui/src/renderer/containers/SelectLanguagePage.tsx +++ b/gui/src/renderer/containers/SelectLanguagePage.tsx @@ -24,9 +24,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(SelectLanguage), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(SelectLanguage)); diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index defe734aff..c52dd4fd31 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -89,9 +89,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(SelectLocation), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(SelectLocation)); diff --git a/gui/src/renderer/containers/SettingsPage.tsx b/gui/src/renderer/containers/SettingsPage.tsx index a1d65970a8..77394739c3 100644 --- a/gui/src/renderer/containers/SettingsPage.tsx +++ b/gui/src/renderer/containers/SettingsPage.tsx @@ -32,9 +32,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(Settings), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(Settings)); diff --git a/gui/src/renderer/containers/SupportPage.tsx b/gui/src/renderer/containers/SupportPage.tsx index d666afbd55..ceea145b06 100644 --- a/gui/src/renderer/containers/SupportPage.tsx +++ b/gui/src/renderer/containers/SupportPage.tsx @@ -34,7 +34,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch) => { }; }; -export default connect( - mapStateToProps, - mapDispatchToProps, -)(Support); +export default connect(mapStateToProps, mapDispatchToProps)(Support); diff --git a/gui/src/renderer/containers/WireguardKeysPage.tsx b/gui/src/renderer/containers/WireguardKeysPage.tsx index 9f5a4aa8d2..44e7a7d109 100644 --- a/gui/src/renderer/containers/WireguardKeysPage.tsx +++ b/gui/src/renderer/containers/WireguardKeysPage.tsx @@ -23,9 +23,4 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }; }; -export default withAppContext( - connect( - mapStateToProps, - mapDispatchToProps, - )(WireguardKeys), -); +export default withAppContext(connect(mapStateToProps, mapDispatchToProps)(WireguardKeys)); |
