diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-11-22 12:13:24 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2024-01-29 09:33:49 +0100 |
| commit | b8eb0a732ce8c9c542203fbc063674fb9cc24384 (patch) | |
| tree | 27231801d7fa663be08b5c9606550cdd6380295b /gui/src/renderer | |
| parent | db9f5abf496019d3e40b62833c334b550e2d759a (diff) | |
| download | mullvadvpn-b8eb0a732ce8c9c542203fbc063674fb9cc24384.tar.xz mullvadvpn-b8eb0a732ce8c9c542203fbc063674fb9cc24384.zip | |
Add API access methods to Electron IPC
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 27 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/actions.ts | 32 | ||||
| -rw-r--r-- | gui/src/renderer/redux/settings/reducers.ts | 18 |
3 files changed, 76 insertions, 1 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 3806c12413..01d76474d4 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -6,9 +6,11 @@ import { StyleSheetManager } from 'styled-components'; import { hasExpired } from '../shared/account-expiry'; import { ILinuxSplitTunnelingApplication, IWindowsApplication } from '../shared/application-types'; import { + AccessMethodSetting, AccountToken, BridgeSettings, BridgeState, + CustomProxy, DeviceEvent, DeviceState, IAccountData, @@ -21,6 +23,7 @@ import { IRelayListWithEndpointData, ISettings, liftConstraint, + NewAccessMethodSetting, ObfuscationSettings, RelaySettings, TunnelState, @@ -155,6 +158,10 @@ export default class AppRenderer { this.updateBlockedState(this.tunnelState, newSettings.blockWhenDisconnected); }); + IpcRendererEventChannel.settings.listenApiAccessMethodSettingChange((setting) => { + this.setCurrentApiAccessMethod(setting); + }); + IpcRendererEventChannel.relays.listen((relayListPair: IRelayListWithEndpointData) => { this.setRelayListPair(relayListPair); }); @@ -231,6 +238,7 @@ export default class AppRenderer { this.setGuiSettings(initialState.guiSettings); this.storeAutoStart(initialState.autoStart); this.setChangelog(initialState.changelog, initialState.forceShowChanges); + this.setCurrentApiAccessMethod(initialState.currentApiAccessMethod); if (initialState.macOsScrollbarVisibility !== undefined) { this.reduxActions.userInterface.setMacOsScrollbarVisibility( @@ -343,6 +351,18 @@ export default class AppRenderer { IpcRendererEventChannel.customLists.deleteCustomList(id); public updateCustomList = (customList: ICustomList) => IpcRendererEventChannel.customLists.updateCustomList(customList); + public addApiAccessMethod = (method: NewAccessMethodSetting) => + IpcRendererEventChannel.settings.addApiAccessMethod(method); + public updateApiAccessMethod = (method: AccessMethodSetting) => + IpcRendererEventChannel.settings.updateApiAccessMethod(method); + public removeApiAccessMethod = (id: string) => + IpcRendererEventChannel.settings.removeApiAccessMethod(id); + public setApiAccessMethod = (id: string) => + IpcRendererEventChannel.settings.setApiAccessMethod(id); + public testApiAccessMethodById = (id: string) => + IpcRendererEventChannel.settings.testApiAccessMethodById(id); + public testCustomApiAccessMethod = (method: CustomProxy) => + IpcRendererEventChannel.settings.testCustomApiAccessMethod(method); public login = async (accountToken: AccountToken) => { const actions = this.reduxActions; @@ -782,6 +802,7 @@ export default class AppRenderer { reduxSettings.updateSplitTunnelingState(newSettings.splitTunnel.enableExclusions); reduxSettings.updateObfuscationSettings(newSettings.obfuscationSettings); reduxSettings.updateCustomLists(newSettings.customLists); + reduxSettings.updateApiAccessMethods(newSettings.apiAccessMethods); this.setReduxRelaySettings(newSettings.relaySettings); this.setBridgeSettings(newSettings.bridgeSettings); @@ -963,6 +984,12 @@ export default class AppRenderer { } } + private setCurrentApiAccessMethod(method?: AccessMethodSetting) { + if (method) { + this.reduxActions.settings.updateCurrentApiAccessMethod(method); + } + } + private getLocationFromConstraints(): Partial<ILocation> { const state = this.reduxStore.getState(); const coordinates = { diff --git a/gui/src/renderer/redux/settings/actions.ts b/gui/src/renderer/redux/settings/actions.ts index 585aad5732..969f8b0a41 100644 --- a/gui/src/renderer/redux/settings/actions.ts +++ b/gui/src/renderer/redux/settings/actions.ts @@ -1,5 +1,7 @@ import { IWindowsApplication } from '../../../shared/application-types'; import { + AccessMethodSetting, + ApiAccessMethodSettings, BridgeState, CustomLists, IDnsOptions, @@ -104,6 +106,16 @@ export interface ISetCustomLists { customLists: CustomLists; } +export interface ISetApiAccessMethods { + type: 'SET_API_ACCESS_METHODS'; + accessMethods: ApiAccessMethodSettings; +} + +export interface ISetCurrentApiAccessMethod { + type: 'SET_CURRENT_API_ACCESS_METHOD'; + accessMethod: AccessMethodSetting; +} + export type SettingsAction = | IUpdateGuiSettingsAction | IUpdateRelayAction @@ -123,7 +135,9 @@ export type SettingsAction = | IUpdateSplitTunnelingStateAction | ISetSplitTunnelingApplicationsAction | ISetObfuscationSettings - | ISetCustomLists; + | ISetCustomLists + | ISetApiAccessMethods + | ISetCurrentApiAccessMethod; function updateGuiSettings(guiSettings: IGuiSettingsState): IUpdateGuiSettingsAction { return { @@ -270,6 +284,20 @@ function updateCustomLists(customLists: CustomLists): ISetCustomLists { }; } +function updateApiAccessMethods(methods: ApiAccessMethodSettings): ISetApiAccessMethods { + return { + type: 'SET_API_ACCESS_METHODS', + accessMethods: methods, + }; +} + +function updateCurrentApiAccessMethod(setting: AccessMethodSetting): ISetCurrentApiAccessMethod { + return { + type: 'SET_CURRENT_API_ACCESS_METHOD', + accessMethod: setting, + }; +} + export default { updateGuiSettings, updateRelay, @@ -290,4 +318,6 @@ export default { setSplitTunnelingApplications, updateObfuscationSettings, updateCustomLists, + updateApiAccessMethods, + updateCurrentApiAccessMethod, }; diff --git a/gui/src/renderer/redux/settings/reducers.ts b/gui/src/renderer/redux/settings/reducers.ts index 3d03093e0a..39e4b3de56 100644 --- a/gui/src/renderer/redux/settings/reducers.ts +++ b/gui/src/renderer/redux/settings/reducers.ts @@ -1,5 +1,7 @@ import { IWindowsApplication } from '../../../shared/application-types'; import { + AccessMethodSetting, + ApiAccessMethodSettings, BridgeState, BridgeType, CustomLists, @@ -107,6 +109,8 @@ export interface ISettingsReduxState { splitTunnelingApplications: IWindowsApplication[]; obfuscationSettings: ObfuscationSettings; customLists: CustomLists; + apiAccessMethods: ApiAccessMethodSettings; + currentApiAccessMethod?: AccessMethodSetting; } const initialState: ISettingsReduxState = { @@ -173,6 +177,8 @@ const initialState: ISettingsReduxState = { }, }, customLists: [], + apiAccessMethods: [], + currentApiAccessMethod: undefined, }; export default function ( @@ -303,6 +309,18 @@ export default function ( customLists: action.customLists, }; + case 'SET_API_ACCESS_METHODS': + return { + ...state, + apiAccessMethods: action.accessMethods, + }; + + case 'SET_CURRENT_API_ACCESS_METHOD': + return { + ...state, + currentApiAccessMethod: action.accessMethod, + }; + default: return state; } |
