diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-09-10 14:35:00 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-09-12 12:50:51 +0200 |
| commit | 57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea (patch) | |
| tree | fc85b595edbdda91e5f7e894d7ed536d0ac69ba8 /gui/src/main | |
| parent | ef20b724201e5c374e6080298974bc8e97818cf2 (diff) | |
| download | mullvadvpn-57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea.tar.xz mullvadvpn-57f5d8f246fa688a36e3138cbbcd51dd95fdf7ea.zip | |
Add bridge selector
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/index.ts | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 4f0454d5e2..ac583f4300 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import * as uuid from 'uuid'; import { AccountToken, + BridgeSettings, BridgeState, DaemonEvent, IAccountData, @@ -16,6 +17,7 @@ import { ISettings, IWireguardPublicKey, KeygenEvent, + RelayLocation, RelaySettings, RelaySettingsUpdate, TunnelState, @@ -427,7 +429,11 @@ class ApplicationMain { // fetch relays try { - this.setRelays(await this.daemonRpc.getRelayLocations(), this.settings.relaySettings); + this.setRelays( + await this.daemonRpc.getRelayLocations(), + this.settings.relaySettings, + this.settings.bridgeState, + ); } catch (error) { log.error(`Failed to fetch relay locations: ${error.message}`); @@ -533,7 +539,11 @@ class ApplicationMain { } else if ('settings' in daemonEvent) { this.setSettings(daemonEvent.settings); } else if ('relayList' in daemonEvent) { - this.setRelays(daemonEvent.relayList, this.settings.relaySettings); + this.setRelays( + daemonEvent.relayList, + this.settings.relaySettings, + this.settings.bridgeState, + ); } else if ('wireguardKey' in daemonEvent) { this.handleWireguardKeygenEvent(daemonEvent.wireguardKey); } @@ -620,7 +630,7 @@ class ApplicationMain { // since settings can have the relay constraints changed, the relay // list should also be updated - this.setRelays(this.relays, newSettings.relaySettings); + this.setRelays(this.relays, newSettings.relaySettings, newSettings.bridgeState); } private setLocation(newLocation: ILocation) { @@ -631,16 +641,24 @@ class ApplicationMain { } } - private setRelays(newRelayList: IRelayList, relaySettings: RelaySettings) { + private setRelays( + newRelayList: IRelayList, + relaySettings: RelaySettings, + bridgeState: BridgeState, + ) { this.relays = newRelayList; + const filteredRelays = this.processRelaysForPresentation(newRelayList, relaySettings); + const filteredBridges = this.processBridgesForPresentation(newRelayList, bridgeState); if (this.windowController) { - IpcMainEventChannel.relays.notify(this.windowController.webContents, filteredRelays); + IpcMainEventChannel.relays.notify(this.windowController.webContents, { + relays: filteredRelays, + bridges: filteredBridges, + }); } } - // private processRelaysForPresentation( relayList: IRelayList, relaySettings: RelaySettings, @@ -672,20 +690,39 @@ class ApplicationMain { } return { - countries: relayList.countries.map((country) => { - return { + countries: relayList.countries.map((country) => ({ + ...country, + cities: country.cities + .map((city) => ({ + ...city, + relays: city.relays.filter(fnHasWantedTunnels), + })) + .filter((city) => city.relays.length > 0), + })), + }; + } + + private processBridgesForPresentation( + relayList: IRelayList, + bridgeState: BridgeState, + ): IRelayList { + if (bridgeState === 'on') { + const filteredCountries = relayList.countries + .map((country) => ({ ...country, cities: country.cities - .map((city) => { - return { - ...city, - relays: city.relays.filter(fnHasWantedTunnels), - }; - }) + .map((city) => ({ + ...city, + relays: city.relays.filter((relay) => relay.bridges), + })) .filter((city) => city.relays.length > 0), - }; - }), - }; + })) + .filter((country) => country.cities.length > 0); + + return { countries: filteredCountries }; + } else { + return { countries: [] }; + } } private setDaemonVersion(daemonVersion: string) { @@ -893,6 +930,7 @@ class ApplicationMain { settings: this.settings, location: this.location, relays: this.processRelaysForPresentation(this.relays, this.settings.relaySettings), + bridges: this.processBridgesForPresentation(this.relays, this.settings.bridgeState), currentVersion: this.currentVersion, upgradeVersion: this.upgradeVersion, guiSettings: this.guiSettings.state, @@ -917,7 +955,15 @@ class ApplicationMain { IpcMainEventChannel.settings.handleUpdateRelaySettings((update: RelaySettingsUpdate) => this.daemonRpc.updateRelaySettings(update), ); + IpcMainEventChannel.settings.handleUpdateBridgeLocation((location: RelayLocation) => { + const bridgeSettings: BridgeSettings = { + normal: { + location: { only: location }, + }, + }; + return this.daemonRpc.setBridgeSettings(bridgeSettings); + }); IpcMainEventChannel.autoStart.handleSet((autoStart: boolean) => { return this.setAutoStart(autoStart); }); |
