diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-11-03 19:38:17 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-03-14 13:58:44 +0100 |
| commit | d5f21653bec09d342112d66c5d20eca38e16b49e (patch) | |
| tree | 9d6b8baacd70c2f84909e45fc7ea9976e9314e4d /gui/src/renderer | |
| parent | 46fa74ad03658ad0afa9dc984565b7f10106af94 (diff) | |
| download | mullvadvpn-d5f21653bec09d342112d66c5d20eca38e16b49e.tar.xz mullvadvpn-d5f21653bec09d342112d66c5d20eca38e16b49e.zip | |
Add rpc and ipc calls for listing and removing devices
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 32 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/actions.ts | 14 |
2 files changed, 28 insertions, 18 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index ff46b76f1a..595ded57c5 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -31,7 +31,9 @@ import { BridgeState, IAccountData, IAppVersionInfo, - IDeviceConfig, + IDevice, + DeviceConfig, + IDeviceRemoval, IDnsOptions, ILocation, ISettings, @@ -93,7 +95,7 @@ export default class AppRenderer { private relayListPair!: IRelayListPair; private tunnelState!: TunnelState; private settings!: ISettings; - private deviceConfig!: IDeviceConfig; + private deviceConfig: DeviceConfig; private guiSettings!: IGuiSettingsState; private loginState: 'none' | 'logging in' | 'creating account' = 'none'; private loginScheduler = new Scheduler(); @@ -122,10 +124,9 @@ export default class AppRenderer { this.setAccountExpiry(newAccountData?.expiry); }); - IpcRendererEventChannel.account.listenDevice((deviceConfig: IDeviceConfig) => { + IpcRendererEventChannel.account.listenDevice((deviceConfig: DeviceConfig) => { const oldDeviceConfig = this.deviceConfig; - this.deviceConfig = deviceConfig; - this.handleAccountChange(deviceConfig, oldDeviceConfig.accountToken); + this.handleAccountChange(deviceConfig, oldDeviceConfig?.accountToken); }); IpcRendererEventChannel.accountHistory.listen((newAccountHistory?: AccountToken) => { @@ -232,7 +233,7 @@ export default class AppRenderer { const navigationBase = this.getNavigationBase( initialState.isConnected, - initialState.deviceConfig.accountToken, + initialState.deviceConfig?.accountToken, ); this.history = new History(navigationBase); } @@ -307,6 +308,14 @@ export default class AppRenderer { IpcRendererEventChannel.account.updateData(); } + public listDevices(accountToken: AccountToken): Promise<Array<IDevice>> { + return IpcRendererEventChannel.account.listDevices(accountToken); + } + + public removeDevice(deviceRemoval: IDeviceRemoval): Promise<void> { + return IpcRendererEventChannel.account.removeDevice(deviceRemoval); + } + public async connectTunnel(): Promise<void> { return IpcRendererEventChannel.tunnel.connect(); } @@ -615,7 +624,7 @@ export default class AppRenderer { const pathname = this.history.location.pathname; const nextPath = this.getNavigationBase( this.connectedToDaemon, - this.deviceConfig.accountToken, + this.deviceConfig?.accountToken, ); // First level contains the possible next locations and the second level contains the possible @@ -737,10 +746,11 @@ export default class AppRenderer { } } - private handleAccountChange(newDeviceConfig: IDeviceConfig, oldAccount?: string) { + private handleAccountChange(newDeviceConfig: DeviceConfig, oldAccount?: string) { const reduxAccount = this.reduxActions.account; - const newAccount = newDeviceConfig.accountToken; + this.deviceConfig = newDeviceConfig; + const newAccount = newDeviceConfig?.accountToken; if (oldAccount && !newAccount) { this.loginScheduler.cancel(); @@ -748,8 +758,8 @@ export default class AppRenderer { this.resetNavigation(); } else if ( - newDeviceConfig.accountToken !== undefined && - newDeviceConfig.device !== undefined && + newDeviceConfig?.accountToken !== undefined && + newDeviceConfig?.device !== undefined && oldAccount !== newAccount ) { switch (this.loginState) { diff --git a/gui/src/renderer/redux/account/actions.ts b/gui/src/renderer/redux/account/actions.ts index ebc63e322c..2eb9f21a17 100644 --- a/gui/src/renderer/redux/account/actions.ts +++ b/gui/src/renderer/redux/account/actions.ts @@ -1,4 +1,4 @@ -import { AccountToken, IDeviceConfig } from '../../../shared/daemon-rpc-types'; +import { AccountToken, DeviceConfig } from '../../../shared/daemon-rpc-types'; interface IStartLoginAction { type: 'START_LOGIN'; @@ -8,7 +8,7 @@ interface IStartLoginAction { interface ILoggedInAction { type: 'LOGGED_IN'; accountToken: AccountToken; - deviceName: string; + deviceName?: string; } interface ILoginFailedAction { @@ -36,7 +36,7 @@ interface ICreateAccountFailed { interface IAccountCreated { type: 'ACCOUNT_CREATED'; accountToken: AccountToken; - deviceName: string; + deviceName?: string; expiry: string; } @@ -80,11 +80,11 @@ function startLogin(accountToken: AccountToken): IStartLoginAction { }; } -function loggedIn(deviceConfig: Required<IDeviceConfig>): ILoggedInAction { +function loggedIn(deviceConfig: NonNullable<DeviceConfig>): ILoggedInAction { return { type: 'LOGGED_IN', accountToken: deviceConfig.accountToken, - deviceName: deviceConfig.device.name, + deviceName: deviceConfig.device?.name, }; } @@ -120,11 +120,11 @@ function createAccountFailed(error: Error): ICreateAccountFailed { }; } -function accountCreated(deviceConfig: Required<IDeviceConfig>, expiry: string): IAccountCreated { +function accountCreated(deviceConfig: NonNullable<DeviceConfig>, expiry: string): IAccountCreated { return { type: 'ACCOUNT_CREATED', accountToken: deviceConfig.accountToken, - deviceName: deviceConfig.device.name, + deviceName: deviceConfig.device?.name, expiry, }; } |
