diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-07-23 13:39:34 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-07-23 13:39:34 +0200 |
| commit | c2acb4aff58b7b7f60a13ab05104910f70741e3c (patch) | |
| tree | bc8bcac2c7386aa2522c89223aba4471cfb27820 /gui/src | |
| parent | d0951f1f9ae8d0c6be9c4aa961a257c97ddbf4f5 (diff) | |
| parent | f5f870074496283521d6adcc80537a54e2168c8e (diff) | |
| download | mullvadvpn-c2acb4aff58b7b7f60a13ab05104910f70741e3c.tar.xz mullvadvpn-c2acb4aff58b7b7f60a13ab05104910f70741e3c.zip | |
Merge branch 'fix-linter-warnings'
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/account-data-cache.ts | 5 | ||||
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 17 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 52 | ||||
| -rw-r--r-- | gui/src/main/notification-controller.ts | 3 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/components/AdvancedSettings.tsx | 19 | ||||
| -rw-r--r-- | gui/src/renderer/components/Login.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/components/SplitTunnelingSettings.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/components/SvgMap.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/containers/AccountPage.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/containers/LoginPage.tsx | 5 | ||||
| -rw-r--r-- | gui/src/renderer/containers/PreferencesPage.tsx | 5 | ||||
| -rw-r--r-- | gui/src/renderer/containers/SupportPage.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/lib/utilityHooks.ts | 13 | ||||
| -rw-r--r-- | gui/src/shared/promise.ts | 6 |
15 files changed, 59 insertions, 90 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts index a79a934537..d55b511feb 100644 --- a/gui/src/main/account-data-cache.ts +++ b/gui/src/main/account-data-cache.ts @@ -2,7 +2,6 @@ import { closeToExpiry, hasExpired } from '../shared/account-expiry'; import { AccountToken, IAccountData, VoucherResponse } from '../shared/daemon-rpc-types'; import { DateComponent, dateByAddingComponent } from '../shared/date-helper'; import log from '../shared/logging'; -import consumePromise from '../shared/promise'; import { Scheduler } from '../shared/scheduler'; import { InvalidAccountError } from './errors'; @@ -50,7 +49,7 @@ export default class AccountDataCache { // Only fetch if there's no fetch for this account number in progress. if (!this.performingFetch) { - consumePromise(this.performFetch(accountToken)); + void this.performFetch(accountToken); } } else if (watcher) { watcher.onFinish(); @@ -149,7 +148,7 @@ export default class AccountDataCache { private scheduleFetch(accountToken: AccountToken, delay: number) { this.fetchRetryScheduler.schedule(() => { - consumePromise(this.performFetch(accountToken)); + void this.performFetch(accountToken); }, delay); } diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 10159ad49e..28b8e651dc 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -54,7 +54,6 @@ import log from '../shared/logging'; import * as managementInterface from './management_interface/management_interface_grpc_pb'; import * as grpcTypes from './management_interface/management_interface_pb'; import { CommunicationError, InvalidAccountError } from './errors'; -import consumePromise from '../shared/promise'; const NETWORK_CALL_TIMEOUT = 10000; const CHANNEL_STATE_TIMEOUT = 1000 * 60 * 60; @@ -585,11 +584,9 @@ export class DaemonRpc { this.connectionObservers.forEach((observer) => observer.onClose()); this.isConnected = false; // Try and reconnect in case - consumePromise( - this.connect().catch((error) => { - log.error(`Failed to reconnect - ${error}`); - }), - ); + void this.connect().catch((error) => { + log.error(`Failed to reconnect - ${error}`); + }); this.setChannelCallback(currentState); } else if (!wasConnected && currentState === grpc.connectivityState.READY) { this.isConnected = true; @@ -632,11 +629,9 @@ export class DaemonRpc { this.isConnected = false; } if (!this.isConnected) { - consumePromise( - this.connect().catch((error) => { - log.error(`Failed to reconnect - ${error}`); - }), - ); + void this.connect().catch((error) => { + log.error(`Failed to reconnect - ${error}`); + }); } }, 3000); } diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 54ea32932f..a81324fd27 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -49,7 +49,6 @@ import { UnsupportedVersionNotificationProvider, UpdateAvailableNotificationProvider, } from '../shared/notifications/notification'; -import consumePromise from '../shared/promise'; import { Scheduler } from '../shared/scheduler'; import AccountDataCache from './account-data-cache'; import { getOpenAtLogin, setOpenAtLogin } from './autostart'; @@ -510,7 +509,7 @@ class ApplicationMain { // disable pinch to zoom if (this.windowController.webContents) { - consumePromise(this.windowController.webContents.setVisualZoomLevelLimits(1, 1)); + void this.windowController.webContents.setVisualZoomLevelLimits(1, 1); } } } @@ -583,7 +582,7 @@ class ApplicationMain { } // fetch the latest version info in background - consumePromise(this.fetchLatestVersion()); + void this.fetchLatestVersion(); // reset the reconnect backoff when connection established. this.reconnectBackoff.reset(); @@ -636,7 +635,7 @@ class ApplicationMain { }; private connectToDaemon() { - consumePromise(this.daemonRpc.connect()); + void this.daemonRpc.connect(); } private recoverFromBootstrapError(_error?: Error) { @@ -719,7 +718,7 @@ class ApplicationMain { private setTunnelState(newState: TunnelState) { this.tunnelState = newState; this.updateTrayIcon(newState, this.settings.blockWhenDisconnected); - consumePromise(this.updateLocation()); + void this.updateLocation(); if (process.platform === 'linux') { this.tray?.setContextMenu(this.createTrayContextMenu()); @@ -751,8 +750,8 @@ class ApplicationMain { this.updateAccountDataOnAccountChange(oldSettings.accountToken, newSettings.accountToken); if (oldSettings.accountToken !== newSettings.accountToken) { - consumePromise(this.updateAccountHistory()); - consumePromise(this.fetchWireguardKey()); + void this.updateAccountHistory(); + void this.fetchWireguardKey(); } if (oldSettings.showBetaReleases !== newSettings.showBetaReleases) { @@ -763,7 +762,7 @@ class ApplicationMain { IpcMainEventChannel.settings.notify(this.windowController.webContents, newSettings); if (windowsSplitTunneling) { - consumePromise(this.updateSplitTunnelingApplications(newSettings.splitTunnel.appsList)); + void this.updateSplitTunnelingApplications(newSettings.splitTunnel.appsList); } } @@ -1147,7 +1146,7 @@ class ApplicationMain { }); IpcMainEventChannel.guiSettings.handleSetUnpinnedWindow((unpinnedWindow: boolean) => { - consumePromise(this.setUnpinnedWindow(unpinnedWindow)); + void this.setUnpinnedWindow(unpinnedWindow); }); IpcMainEventChannel.guiSettings.handleSetPreferredLocale((locale: string) => { @@ -1174,7 +1173,7 @@ class ApplicationMain { IpcMainEventChannel.accountHistory.handleClear(async () => { await this.daemonRpc.clearAccountHistory(); - consumePromise(this.updateAccountHistory()); + void this.updateAccountHistory(); }); IpcMainEventChannel.wireguardKeys.handleGenerateKey(async () => { @@ -1367,7 +1366,7 @@ class ApplicationMain { if (this.autoConnectOnWireguardKeyEvent) { this.autoConnectOnWireguardKeyEvent = false; this.autoConnectFallbackScheduler.cancel(); - consumePromise(this.autoConnect()); + void this.autoConnect(); } } @@ -1484,7 +1483,7 @@ class ApplicationMain { private updateDaemonsAutoConnect() { const daemonAutoConnect = this.guiSettings.autoConnect && getOpenAtLogin(); if (daemonAutoConnect !== this.settings.autoConnect) { - consumePromise(this.daemonRpc.setAutoConnect(daemonAutoConnect)); + void this.daemonRpc.setAutoConnect(daemonAutoConnect); } } @@ -1598,19 +1597,16 @@ 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 { default: installer, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = await import( + 'electron-devtools-installer' + ); const forceDownload = !!process.env.UPGRADE_EXTENSIONS; - for (const name of extensions) { - try { - await installer.default(installer[name], { - forceDownload, - loadExtensionOptions: { allowFileAccess: true }, - }); - } catch (e) { - log.info(`Error installing ${name} extension: ${e.message}`); - } + const options = { forceDownload, loadExtensionOptions: { allowFileAccess: true } }; + try { + await installer(REACT_DEVELOPER_TOOLS, options); + await installer(REDUX_DEVTOOLS, options); + } catch (e) { + log.info(`Error installing extension: ${e.message}`); } } @@ -1685,7 +1681,7 @@ class ApplicationMain { // make the window visible on all workspaces and prevent the icon from showing in the dock // and app switcher. if (this.guiSettings.unpinnedWindow) { - consumePromise(app.dock.show()); + void app.dock.show(); } else { appWindow.setVisibleOnAllWorkspaces(true); app.dock.hide(); @@ -1774,16 +1770,16 @@ class ApplicationMain { if (this.tunnelState.state === 'disconnected') { // Workaround: gRPC calls are sometimes delayed by a few seconds and setImmediate // mitigates this. https://github.com/grpc/grpc-node/issues/882 - setImmediate(() => consumePromise(this.daemonRpc.connectTunnel())); + setImmediate(() => void this.daemonRpc.connectTunnel()); } else { - setImmediate(() => consumePromise(this.daemonRpc.disconnectTunnel())); + setImmediate(() => void this.daemonRpc.disconnectTunnel()); } }, }, { label: messages.gettext('Reconnect'), enabled: this.tunnelState.state === 'connected' || this.tunnelState.state === 'connecting', - click: () => setImmediate(() => consumePromise(this.daemonRpc.reconnectTunnel())), + click: () => setImmediate(() => void this.daemonRpc.reconnectTunnel()), }, ]; diff --git a/gui/src/main/notification-controller.ts b/gui/src/main/notification-controller.ts index ca0e12888f..c4816e796a 100644 --- a/gui/src/main/notification-controller.ts +++ b/gui/src/main/notification-controller.ts @@ -13,7 +13,6 @@ import { SystemNotification, SystemNotificationProvider, } from '../shared/notifications/notification'; -import consumePromise from '../shared/promise'; interface NotificationControllerDelegate { openApp(): void; @@ -137,7 +136,7 @@ export default class NotificationController { private performAction(action?: NotificationAction) { if (action && action.type === 'open-url') { - consumePromise(this.notificationControllerDelegate.openLink(action.url, action.withAuth)); + void this.notificationControllerDelegate.openLink(action.url, action.withAuth); } } diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index a92ffb2e8a..5dfdb7bf29 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -21,7 +21,6 @@ import { IGuiSettingsState, SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-se import { messages, relayLocations } from '../shared/gettext'; import log, { ConsoleOutput } from '../shared/logging'; import { IRelayListPair, LaunchApplicationResult } from '../shared/ipc-schema'; -import consumePromise from '../shared/promise'; import { Scheduler } from '../shared/scheduler'; import History, { ITransitionSpecification, transitions } from './lib/history'; import { loadTranslations } from './lib/load-translations'; @@ -138,7 +137,7 @@ export default class AppRenderer { }); IpcRendererEventChannel.daemon.listenConnected(() => { - consumePromise(this.onDaemonConnected()); + void this.onDaemonConnected(); }); IpcRendererEventChannel.daemon.listenDisconnected(() => { @@ -243,7 +242,7 @@ export default class AppRenderer { this.setWireguardPublicKey(initialState.wireguardPublicKey); if (initialState.isConnected) { - consumePromise(this.onDaemonConnected()); + void this.onDaemonConnected(); } this.checkContentHeight(); @@ -369,7 +368,7 @@ export default class AppRenderer { } catch (e) { log.error(`Failed to get the WWW auth token: ${e.message}`); } - consumePromise(this.openUrl(`${link}?token=${token}`)); + void this.openUrl(`${link}?token=${token}`); } public async setAllowLan(allowLan: boolean) { @@ -489,7 +488,7 @@ export default class AppRenderer { } public removeSplitTunnelingApplication(application: IApplication | string) { - consumePromise(IpcRendererEventChannel.windowsSplitTunneling.removeApplication(application)); + void IpcRendererEventChannel.windowsSplitTunneling.removeApplication(application); } public collectProblemReport(toRedact?: string): Promise<string> { diff --git a/gui/src/renderer/components/AdvancedSettings.tsx b/gui/src/renderer/components/AdvancedSettings.tsx index 62232b6b8c..338a4d5b81 100644 --- a/gui/src/renderer/components/AdvancedSettings.tsx +++ b/gui/src/renderer/components/AdvancedSettings.tsx @@ -8,7 +8,6 @@ import { TunnelProtocol, } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; -import consumePromise from '../../shared/promise'; import { IpAddress } from '../lib/ip'; import { WgKeyState } from '../redux/settings/reducers'; import { @@ -599,7 +598,7 @@ export default class AdvancedSettings extends React.Component<IProps, IState> { }; private confirmPublicDnsAddress = () => { - consumePromise(this.addDnsAddress(this.state.publicDnsIpToConfirm!, true)); + void this.addDnsAddress(this.state.publicDnsIpToConfirm!, true); this.hideCustomDnsConfirmationDialog(); }; @@ -627,15 +626,13 @@ export default class AdvancedSettings extends React.Component<IProps, IState> { private removeDnsAddress = (address: string) => { const addresses = this.props.dns.customOptions.addresses.filter((item) => item !== address); - consumePromise( - this.props.setDnsOptions({ - ...this.props.dns, - state: addresses.length > 0 && this.props.dns.state === 'custom' ? 'custom' : 'default', - customOptions: { - addresses, - }, - }), - ); + void this.props.setDnsOptions({ + ...this.props.dns, + state: addresses.length > 0 && this.props.dns.state === 'custom' ? 'custom' : 'default', + customOptions: { + addresses, + }, + }); }; private tunnelProtocolItems = ( diff --git a/gui/src/renderer/components/Login.tsx b/gui/src/renderer/components/Login.tsx index 4198bcb9dd..96d3929fe0 100644 --- a/gui/src/renderer/components/Login.tsx +++ b/gui/src/renderer/components/Login.tsx @@ -1,7 +1,6 @@ import React, { useCallback } from 'react'; import { sprintf } from 'sprintf-js'; import { colors } from '../../config.json'; -import consumePromise from '../../shared/promise'; import { messages } from '../../shared/gettext'; import { formatAccountToken } from '../lib/account'; import Accordion from './Accordion'; @@ -217,7 +216,7 @@ export default class Login extends React.Component<IProps, IState> { }; private onClearAccountHistory = () => { - consumePromise(this.clearAccountHistory()); + void this.clearAccountHistory(); }; private async clearAccountHistory() { diff --git a/gui/src/renderer/components/SplitTunnelingSettings.tsx b/gui/src/renderer/components/SplitTunnelingSettings.tsx index 30948dae35..1b41a6683d 100644 --- a/gui/src/renderer/components/SplitTunnelingSettings.tsx +++ b/gui/src/renderer/components/SplitTunnelingSettings.tsx @@ -4,7 +4,6 @@ import { sprintf } from 'sprintf-js'; import { colors } from '../../config.json'; import { messages } from '../../shared/gettext'; import { IApplication, ILinuxSplitTunnelingApplication } from '../../shared/application-types'; -import consumePromise from '../../shared/promise'; import { useAppContext } from '../context'; import { useHistory } from '../lib/history'; import { useAsyncEffect } from '../lib/utilityHooks'; @@ -142,7 +141,7 @@ function LinuxSplitTunnelingSettings(props: IPlatformSplitTunnelingSettingsProps const [applications, setApplications] = useState<ILinuxSplitTunnelingApplication[]>(); const [browseError, setBrowseError] = useState<string>(); - useEffect(() => consumePromise(getLinuxSplitTunnelingApplications().then(setApplications)), []); + useEffect(() => void getLinuxSplitTunnelingApplications().then(setApplications), []); const launchApplication = useCallback( async (application: ILinuxSplitTunnelingApplication | string) => { diff --git a/gui/src/renderer/components/SvgMap.tsx b/gui/src/renderer/components/SvgMap.tsx index 93b3b7fdc3..cae3c68ed6 100644 --- a/gui/src/renderer/components/SvgMap.tsx +++ b/gui/src/renderer/components/SvgMap.tsx @@ -226,8 +226,7 @@ function SvgMap(props: IProps) { style={mapStyle} projection={ // Workaround for incorrect type definition in @types/react-simple-maps. - /* @ts-ignore */ - projection as () => GeoProjection + (projection as unknown) as () => GeoProjection } projectionConfig={projectionConfig}> <ZoomableGroup diff --git a/gui/src/renderer/containers/AccountPage.tsx b/gui/src/renderer/containers/AccountPage.tsx index 8751107c74..641374c504 100644 --- a/gui/src/renderer/containers/AccountPage.tsx +++ b/gui/src/renderer/containers/AccountPage.tsx @@ -1,6 +1,5 @@ import { connect } from 'react-redux'; import { links } from '../../config.json'; -import consumePromise from '../../shared/promise'; import Account from '../components/Account'; import withAppContext, { IAppContext } from '../context'; @@ -16,7 +15,7 @@ const mapStateToProps = (state: IReduxState) => ({ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAppContext) => { return { onLogout: () => { - consumePromise(props.app.logout()); + void props.app.logout(); }, onClose: () => { props.history.pop(); diff --git a/gui/src/renderer/containers/LoginPage.tsx b/gui/src/renderer/containers/LoginPage.tsx index a56e6ec04a..6797f40d3e 100644 --- a/gui/src/renderer/containers/LoginPage.tsx +++ b/gui/src/renderer/containers/LoginPage.tsx @@ -1,6 +1,5 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import consumePromise from '../../shared/promise'; import Login from '../components/Login'; import withAppContext, { IAppContext } from '../context'; import accountActions from '../redux/account/actions'; @@ -18,7 +17,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { const { resetLoginError, updateAccountToken } = bindActionCreators(accountActions, dispatch); return { login: (account: string) => { - consumePromise(props.app.login(account)); + void props.app.login(account); }, resetLoginError: () => { resetLoginError(); @@ -26,7 +25,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { openExternalLink: (url: string) => props.app.openUrl(url), updateAccountToken, clearAccountHistory: () => props.app.clearAccountHistory(), - createNewAccount: () => consumePromise(props.app.createNewAccount()), + createNewAccount: () => void props.app.createNewAccount(), }; }; diff --git a/gui/src/renderer/containers/PreferencesPage.tsx b/gui/src/renderer/containers/PreferencesPage.tsx index 671ba33c26..a050afedf7 100644 --- a/gui/src/renderer/containers/PreferencesPage.tsx +++ b/gui/src/renderer/containers/PreferencesPage.tsx @@ -1,7 +1,6 @@ import { connect } from 'react-redux'; import { IDnsOptions } from '../../shared/daemon-rpc-types'; import log from '../../shared/logging'; -import consumePromise from '../../shared/promise'; import Preferences from '../components/Preferences'; import withAppContext, { IAppContext } from '../context'; import { IHistoryProps, withHistory } from '../lib/history'; @@ -39,10 +38,10 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp props.app.setAutoConnect(autoConnect); }, setAllowLan: (allowLan: boolean) => { - consumePromise(props.app.setAllowLan(allowLan)); + void props.app.setAllowLan(allowLan); }, setShowBetaReleases: (showBetaReleases: boolean) => { - consumePromise(props.app.setShowBetaReleases(showBetaReleases)); + void props.app.setShowBetaReleases(showBetaReleases); }, setStartMinimized: (startMinimized: boolean) => { props.app.setStartMinimized(startMinimized); diff --git a/gui/src/renderer/containers/SupportPage.tsx b/gui/src/renderer/containers/SupportPage.tsx index a4bdbd4ac3..8457d6f6ff 100644 --- a/gui/src/renderer/containers/SupportPage.tsx +++ b/gui/src/renderer/containers/SupportPage.tsx @@ -1,6 +1,5 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import consumePromise from '../../shared/promise'; import Support from '../components/Support'; import withAppContext, { IAppContext } from '../context'; import { IHistoryProps, withHistory } from '../lib/history'; @@ -24,7 +23,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext & IHisto props.history.pop(); }, viewLog(id: string) { - consumePromise(props.app.viewLog(id)); + void props.app.viewLog(id); }, saveReportForm, clearReportForm, diff --git a/gui/src/renderer/lib/utilityHooks.ts b/gui/src/renderer/lib/utilityHooks.ts index 9e8cea0bad..d20cb80883 100644 --- a/gui/src/renderer/lib/utilityHooks.ts +++ b/gui/src/renderer/lib/utilityHooks.ts @@ -1,5 +1,4 @@ import React, { useCallback, useEffect, useRef } from 'react'; -import consumePromise from '../../shared/promise'; export function useMounted() { const mountedRef = useRef(false); @@ -36,13 +35,11 @@ export function useAsyncEffect( useEffect(() => { const promise = effect(); return () => { - consumePromise( - promise.then((destructor) => { - if (isMounted() && destructor) { - return destructor(); - } - }), - ); + void promise.then((destructor) => { + if (isMounted() && destructor) { + return destructor(); + } + }); }; }, dependencies); } diff --git a/gui/src/shared/promise.ts b/gui/src/shared/promise.ts deleted file mode 100644 index c0228e23e8..0000000000 --- a/gui/src/shared/promise.ts +++ /dev/null @@ -1,6 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-empty-function -const noop = () => {}; - -export default function consumePromise<T>(promise: Promise<T>): void { - promise.then(noop, noop); -} |
