diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-10-04 11:35:59 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-10-09 10:16:53 +0200 |
| commit | 469c501f736e98ea6a20f1e76b40550d6ad995cd (patch) | |
| tree | 88c0fbab003216eff6bcaf2fb87c02d634025558 /gui/src/renderer | |
| parent | 4e26e4c36345afbca25a1a1e760927cd74d2c1a5 (diff) | |
| download | mullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.tar.xz mullvadvpn-469c501f736e98ea6a20f1e76b40550d6ad995cd.zip | |
Add custom lists to settings, ipc and rpc calls
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 36 | ||||
| -rw-r--r-- | gui/src/renderer/components/Filter.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/components/select-location/select-location-helpers.ts | 42 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/actions.ts | 25 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/reducers.ts | 13 |
5 files changed, 77 insertions, 43 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 155922bc4d..7c7df73796 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -12,6 +12,7 @@ import { DeviceState, IAccountData, IAppVersionInfo, + ICustomList, IDevice, IDeviceRemoval, IDnsOptions, @@ -336,6 +337,12 @@ export default class AppRenderer { public openUrl = (url: string) => IpcRendererEventChannel.app.openUrl(url); public showOpenDialog = (options: Electron.OpenDialogOptions) => IpcRendererEventChannel.app.showOpenDialog(options); + public createCustomList = (name: string) => + IpcRendererEventChannel.customLists.createCustomList(name); + public deleteCustomList = (id: string) => + IpcRendererEventChannel.customLists.deleteCustomList(id); + public updateCustomList = (customList: ICustomList) => + IpcRendererEventChannel.customLists.updateCustomList(customList); public login = async (accountToken: AccountToken) => { const actions = this.reduxActions; @@ -778,6 +785,7 @@ export default class AppRenderer { reduxSettings.updateDnsOptions(newSettings.tunnelOptions.dns); reduxSettings.updateSplitTunnelingState(newSettings.splitTunnel.enableExclusions); reduxSettings.updateObfuscationSettings(newSettings.obfuscationSettings); + reduxSettings.updateCustomLists(newSettings.customLists); this.setRelaySettings(newSettings.relaySettings); this.setBridgeSettings(newSettings.bridgeSettings); @@ -1002,20 +1010,11 @@ export default class AppRenderer { const location = relaySettings.normal.location; if (location !== 'any' && 'only' in location) { const constraint = location.only; - const relayLocations = state.settings.relayLocations; - if ('country' in constraint) { - const country = relayLocations.find(({ code }) => constraint.country === code); - return { country: country?.name, ...coordinates }; - } else if ('city' in constraint) { - const country = relayLocations.find(({ code }) => constraint.city[0] === code); - const city = country?.cities.find(({ code }) => constraint.city[1] === code); - - return { country: country?.name, city: city?.name, ...coordinates }; - } else if ('hostname' in constraint) { - const country = relayLocations.find(({ code }) => constraint.hostname[0] === code); - const city = country?.cities.find((location) => location.code === constraint.hostname[1]); + if ('hostname' in constraint) { + const country = relayLocations.find(({ code }) => constraint.country === code); + const city = country?.cities.find(({ code }) => constraint.city === code); let entryHostname: string | undefined; const multihopConstraint = relaySettings.normal.wireguardConstraints.useMultihop; @@ -1026,16 +1025,25 @@ export default class AppRenderer { 'hostname' in entryLocationConstraint.only && entryLocationConstraint.only.hostname.length === 3 ) { - entryHostname = entryLocationConstraint.only.hostname[2]; + entryHostname = entryLocationConstraint.only.hostname; } return { country: country?.name, city: city?.name, - hostname: constraint.hostname[2], + hostname: constraint.hostname, entryHostname, ...coordinates, }; + } else if ('city' in constraint) { + const country = relayLocations.find(({ code }) => constraint.country === code); + const city = country?.cities.find(({ code }) => constraint.city === code); + + return { country: country?.name, city: city?.name, ...coordinates }; + } else if ('country' in constraint) { + const country = relayLocations.find(({ code }) => constraint.country === code); + + return { country: country?.name, ...coordinates }; } } } diff --git a/gui/src/renderer/components/Filter.tsx b/gui/src/renderer/components/Filter.tsx index 26ed781396..6b369aa39b 100644 --- a/gui/src/renderer/components/Filter.tsx +++ b/gui/src/renderer/components/Filter.tsx @@ -12,7 +12,7 @@ import { } from '../lib/filter-locations'; import { useHistory } from '../lib/history'; import { useBoolean, useNormalRelaySettings } from '../lib/utilityHooks'; -import { IRelayLocationRedux } from '../redux/settings/reducers'; +import { IRelayLocationCountryRedux } from '../redux/settings/reducers'; import { IReduxState, useSelector } from '../redux/store'; import Accordion from './Accordion'; import * as AppButton from './AppButton'; @@ -158,7 +158,7 @@ function useFilteredFilters(providers: string[], ownership: Ownership) { } // Returns all available providers in the provided relay list. -function providersFromRelays(relays: IRelayLocationRedux[]) { +function providersFromRelays(relays: IRelayLocationCountryRedux[]) { const providers = relays.flatMap((country) => country.cities.flatMap((city) => city.relays.map((relay) => relay.provider)), ); diff --git a/gui/src/renderer/components/select-location/select-location-helpers.ts b/gui/src/renderer/components/select-location/select-location-helpers.ts index 46225645cc..23d059ac0a 100644 --- a/gui/src/renderer/components/select-location/select-location-helpers.ts +++ b/gui/src/renderer/components/select-location/select-location-helpers.ts @@ -5,16 +5,20 @@ import { compareRelayLocationLoose, LiftedConstraint, RelayLocation, + RelayLocationCity, + RelayLocationCountry, + RelayLocationCustomList, + RelayLocationRelay, } from '../../../shared/daemon-rpc-types'; import { messages, relayLocations } from '../../../shared/gettext'; import { IRelayLocationCityRedux, - IRelayLocationRedux, + IRelayLocationCountryRedux, IRelayLocationRelayRedux, NormalBridgeSettingsRedux, NormalRelaySettingsRedux, } from '../../redux/settings/reducers'; -import { DisabledReason, LocationType } from './select-location-types'; +import { DisabledReason, LocationSpecification, LocationType } from './select-location-types'; export function isSelected( relayLocation: RelayLocation, @@ -58,13 +62,10 @@ export function defaultExpandedLocations( // Expands a relay location and its parents function expandRelayLocation(location: RelayLocation): RelayLocation[] { - if ('city' in location) { - return [{ country: location.city[0] }]; - } else if ('hostname' in location) { - return [ - { country: location.hostname[0] }, - { city: [location.hostname[0], location.hostname[1]] }, - ]; + if ('hostname' in location) { + return [{ country: location.country }, { country: location.country, city: location.city }]; + } else if ('city' in location) { + return [{ country: location.country }]; } else { return []; } @@ -104,15 +105,12 @@ export function formatRowName( export function isRelayDisabled( relay: IRelayLocationRelayRedux, - location: [string, string, string], + location: RelayLocationRelay, disabledLocation?: { location: RelayLocation; reason: DisabledReason }, ): DisabledReason | undefined { if (!relay.active) { return DisabledReason.inactive; - } else if ( - disabledLocation && - compareRelayLocation({ hostname: location }, disabledLocation.location) - ) { + } else if (disabledLocation && compareRelayLocation(location, disabledLocation.location)) { return disabledLocation.reason; } else { return undefined; @@ -121,11 +119,11 @@ export function isRelayDisabled( export function isCityDisabled( city: IRelayLocationCityRedux, - location: [string, string], + location: RelayLocationCity, disabledLocation?: { location: RelayLocation; reason: DisabledReason }, ): DisabledReason | undefined { const relaysDisabled = city.relays.map((relay) => - isRelayDisabled(relay, [...location, relay.hostname]), + isRelayDisabled(relay, { ...location, hostname: relay.hostname }), ); if (relaysDisabled.every((status) => status === DisabledReason.inactive)) { return DisabledReason.inactive; @@ -144,7 +142,7 @@ export function isCityDisabled( if ( disabledLocation && - compareRelayLocation({ city: location }, disabledLocation.location) && + compareRelayLocation(location, disabledLocation.location) && city.relays.filter((relay) => relay.active).length <= 1 ) { return disabledLocation.reason; @@ -154,11 +152,13 @@ export function isCityDisabled( } export function isCountryDisabled( - country: IRelayLocationRedux, - location: string, + country: IRelayLocationCountryRedux, + location: RelayLocationCountry, disabledLocation?: { location: RelayLocation; reason: DisabledReason }, ): DisabledReason | undefined { - const citiesDisabled = country.cities.map((city) => isCityDisabled(city, [location, city.code])); + const citiesDisabled = country.cities.map((city) => + isCityDisabled(city, { ...location, city: city.code }), + ); if (citiesDisabled.every((status) => status === DisabledReason.inactive)) { return DisabledReason.inactive; } @@ -175,7 +175,7 @@ export function isCountryDisabled( if ( disabledLocation && - compareRelayLocation({ country: location }, disabledLocation.location) && + compareRelayLocation(location, disabledLocation.location) && country.cities.flatMap((city) => city.relays).filter((relay) => relay.active).length <= 1 ) { return disabledLocation.reason; diff --git a/gui/src/renderer/redux/settings/actions.ts b/gui/src/renderer/redux/settings/actions.ts index dad71de024..585aad5732 100644 --- a/gui/src/renderer/redux/settings/actions.ts +++ b/gui/src/renderer/redux/settings/actions.ts @@ -1,12 +1,13 @@ import { IWindowsApplication } from '../../../shared/application-types'; import { BridgeState, + CustomLists, IDnsOptions, IWireguardEndpointData, ObfuscationSettings, } from '../../../shared/daemon-rpc-types'; import { IGuiSettingsState } from '../../../shared/gui-settings-state'; -import { BridgeSettingsRedux, IRelayLocationRedux, RelaySettingsRedux } from './reducers'; +import { BridgeSettingsRedux, IRelayLocationCountryRedux, RelaySettingsRedux } from './reducers'; export interface IUpdateGuiSettingsAction { type: 'UPDATE_GUI_SETTINGS'; @@ -20,7 +21,7 @@ export interface IUpdateRelayAction { export interface IUpdateRelayLocationsAction { type: 'UPDATE_RELAY_LOCATIONS'; - relayLocations: IRelayLocationRedux[]; + relayLocations: IRelayLocationCountryRedux[]; } export interface IUpdateWireguardEndpointData { @@ -98,6 +99,11 @@ export interface ISetObfuscationSettings { obfuscationSettings: ObfuscationSettings; } +export interface ISetCustomLists { + type: 'SET_CUSTOM_LISTS'; + customLists: CustomLists; +} + export type SettingsAction = | IUpdateGuiSettingsAction | IUpdateRelayAction @@ -116,7 +122,8 @@ export type SettingsAction = | IUpdateDnsOptionsAction | IUpdateSplitTunnelingStateAction | ISetSplitTunnelingApplicationsAction - | ISetObfuscationSettings; + | ISetObfuscationSettings + | ISetCustomLists; function updateGuiSettings(guiSettings: IGuiSettingsState): IUpdateGuiSettingsAction { return { @@ -132,7 +139,9 @@ function updateRelay(relay: RelaySettingsRedux): IUpdateRelayAction { }; } -function updateRelayLocations(relayLocations: IRelayLocationRedux[]): IUpdateRelayLocationsAction { +function updateRelayLocations( + relayLocations: IRelayLocationCountryRedux[], +): IUpdateRelayLocationsAction { return { type: 'UPDATE_RELAY_LOCATIONS', relayLocations, @@ -254,6 +263,13 @@ function updateObfuscationSettings( }; } +function updateCustomLists(customLists: CustomLists): ISetCustomLists { + return { + type: 'SET_CUSTOM_LISTS', + customLists, + }; +} + export default { updateGuiSettings, updateRelay, @@ -273,4 +289,5 @@ export default { updateSplitTunnelingState, setSplitTunnelingApplications, updateObfuscationSettings, + updateCustomLists, }; diff --git a/gui/src/renderer/redux/settings/reducers.ts b/gui/src/renderer/redux/settings/reducers.ts index 2030d70844..b400799095 100644 --- a/gui/src/renderer/redux/settings/reducers.ts +++ b/gui/src/renderer/redux/settings/reducers.ts @@ -1,6 +1,7 @@ import { IWindowsApplication } from '../../../shared/application-types'; import { BridgeState, + CustomLists, IDnsOptions, IpVersion, IWireguardEndpointData, @@ -77,7 +78,7 @@ export interface IRelayLocationCityRedux { relays: IRelayLocationRelayRedux[]; } -export interface IRelayLocationRedux { +export interface IRelayLocationCountryRedux { name: string; code: string; cities: IRelayLocationCityRedux[]; @@ -87,7 +88,7 @@ export interface ISettingsReduxState { autoStart: boolean; guiSettings: IGuiSettingsState; relaySettings: RelaySettingsRedux; - relayLocations: IRelayLocationRedux[]; + relayLocations: IRelayLocationCountryRedux[]; wireguardEndpointData: IWireguardEndpointData; allowLan: boolean; enableIpv6: boolean; @@ -106,6 +107,7 @@ export interface ISettingsReduxState { splitTunneling: boolean; splitTunnelingApplications: IWindowsApplication[]; obfuscationSettings: ObfuscationSettings; + customLists: CustomLists; } const initialState: ISettingsReduxState = { @@ -169,6 +171,7 @@ const initialState: ISettingsReduxState = { port: 'any', }, }, + customLists: [], }; export default function ( @@ -293,6 +296,12 @@ export default function ( obfuscationSettings: action.obfuscationSettings, }; + case 'SET_CUSTOM_LISTS': + return { + ...state, + customLists: action.customLists, + }; + default: return state; } |
