diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-06-17 16:55:21 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-06-24 14:22:23 +0200 |
| commit | 14fcbe159ea35ebd4e4d0adebd182e47631335cb (patch) | |
| tree | acc327998e3fa82c06c61c064bf0b370b6adc18b /desktop | |
| parent | 41a021c7d4efdb74b1c71e7567d22ffc930411c4 (diff) | |
| download | mullvadvpn-14fcbe159ea35ebd4e4d0adebd182e47631335cb.tar.xz mullvadvpn-14fcbe159ea35ebd4e4d0adebd182e47631335cb.zip | |
Enable support for creating a custom list with locations
Diffstat (limited to 'desktop')
6 files changed, 27 insertions, 6 deletions
diff --git a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts index 206070598c..35c1f775f4 100644 --- a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts +++ b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts @@ -24,6 +24,7 @@ import { IRelayListWithEndpointData, ISettings, NewAccessMethodSetting, + NewCustomList, ObfuscationSettings, ObfuscationType, RelaySettings, @@ -45,6 +46,7 @@ import { convertToCustomList, convertToCustomProxy, convertToNewApiAccessMethodSetting, + convertToNewCustomList, convertToNormalBridgeSettings, convertToRelayConstraints, ensureExists, @@ -573,9 +575,12 @@ export class DaemonRpc extends GrpcClient { await this.call<grpcTypes.DeviceRemoval, Empty>(this.client.removeDevice, grpcDeviceRemoval); } - public async createCustomList(name: string): Promise<void | CustomListError> { + public async createCustomList(newCustomList: NewCustomList): Promise<void | CustomListError> { try { - await this.callString<Empty>(this.client.createCustomList, name); + await this.call<grpcTypes.NewCustomList, StringValue>( + this.client.createCustomList, + convertToNewCustomList(newCustomList), + ); } catch (e) { const error = e as grpc.ServiceError; if (error.code === 6) { diff --git a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts index 64c805c3b9..c5c6ccf4d2 100644 --- a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts +++ b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts @@ -47,6 +47,7 @@ import { LoggedInDeviceState, LoggedOutDeviceState, NewAccessMethodSetting, + NewCustomList, ObfuscationSettings, ObfuscationType, Ownership, @@ -1345,6 +1346,14 @@ function convertFromSocksAuth(auth: grpcTypes.SocksAuth): SocksAuth { }; } +export function convertToNewCustomList(customList: NewCustomList): grpcTypes.NewCustomList { + const newCustomList = new grpcTypes.NewCustomList(); + newCustomList.setName(customList.name); + const locations = customList.locations.map(convertToGeographicConstraint); + newCustomList.setLocationsList(locations); + return newCustomList; +} + export function ensureExists<T>(value: T | undefined, errorMessage: string): T { if (value) { return value; diff --git a/desktop/packages/mullvad-vpn/src/renderer/app.tsx b/desktop/packages/mullvad-vpn/src/renderer/app.tsx index 7ceab22c2f..8c39327f40 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/app.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/app.tsx @@ -29,6 +29,7 @@ import { ISettings, liftConstraint, NewAccessMethodSetting, + NewCustomList, ObfuscationSettings, RelaySettings, TunnelState, @@ -408,8 +409,8 @@ export default class AppRenderer { public getPathBaseName = (path: string) => IpcRendererEventChannel.app.getPathBaseName(path); public showOpenDialog = (options: Electron.OpenDialogOptions) => IpcRendererEventChannel.app.showOpenDialog(options); - public createCustomList = (name: string) => - IpcRendererEventChannel.customLists.createCustomList(name); + public createCustomList = (newCustomList: NewCustomList) => + IpcRendererEventChannel.customLists.createCustomList(newCustomList); public deleteCustomList = (id: string) => IpcRendererEventChannel.customLists.deleteCustomList(id); public updateCustomList = (customList: ICustomList) => diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/CustomLists.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/CustomLists.tsx index c16badd158..cd535dd91e 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/select-location/CustomLists.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/select-location/CustomLists.tsx @@ -81,7 +81,10 @@ export default function CustomLists(props: CustomListsProps) { const createList = useCallback( async (name: string): Promise<void | CustomListError> => { - const result = await createCustomList(name); + const result = await createCustomList({ + name, + locations: [], + }); // If an error is returned it should be passed as the return value. if (result) { return result; diff --git a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts index b00fe4587a..45ed498237 100644 --- a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts +++ b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts @@ -474,6 +474,8 @@ export interface ICustomList { locations: Array<RelayLocationGeographical>; } +export type NewCustomList = Pick<ICustomList, 'name' | 'locations'>; + export type CustomListError = { type: 'name already exists' }; export interface ISettings { diff --git a/desktop/packages/mullvad-vpn/src/shared/ipc-schema.ts b/desktop/packages/mullvad-vpn/src/shared/ipc-schema.ts index a85f55d18a..031d1fc593 100644 --- a/desktop/packages/mullvad-vpn/src/shared/ipc-schema.ts +++ b/desktop/packages/mullvad-vpn/src/shared/ipc-schema.ts @@ -20,6 +20,7 @@ import { IRelayListWithEndpointData, ISettings, NewAccessMethodSetting, + NewCustomList, ObfuscationSettings, RelaySettings, TunnelState, @@ -147,7 +148,7 @@ export const ipcSchema = { '': notifyRenderer<IRelayListWithEndpointData>(), }, customLists: { - createCustomList: invoke<string, void | CustomListError>(), + createCustomList: invoke<NewCustomList, void | CustomListError>(), deleteCustomList: invoke<string, void>(), updateCustomList: invoke<ICustomList, void | CustomListError>(), }, |
