summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2023-11-22 12:13:24 +0100
committerOskar Nyberg <oskar@mullvad.net>2024-01-29 09:33:49 +0100
commitb8eb0a732ce8c9c542203fbc063674fb9cc24384 (patch)
tree27231801d7fa663be08b5c9606550cdd6380295b /gui/src
parentdb9f5abf496019d3e40b62833c334b550e2d759a (diff)
downloadmullvadvpn-b8eb0a732ce8c9c542203fbc063674fb9cc24384.tar.xz
mullvadvpn-b8eb0a732ce8c9c542203fbc063674fb9cc24384.zip
Add API access methods to Electron IPC
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/default-settings.ts1
-rw-r--r--gui/src/main/index.ts21
-rw-r--r--gui/src/main/settings.ts21
-rw-r--r--gui/src/renderer/app.tsx27
-rw-r--r--gui/src/renderer/redux/settings/actions.ts32
-rw-r--r--gui/src/renderer/redux/settings/reducers.ts18
-rw-r--r--gui/src/shared/ipc-schema.ts11
7 files changed, 130 insertions, 1 deletions
diff --git a/gui/src/main/default-settings.ts b/gui/src/main/default-settings.ts
index fea88e4c27..4510a71896 100644
--- a/gui/src/main/default-settings.ts
+++ b/gui/src/main/default-settings.ts
@@ -71,5 +71,6 @@ export function getDefaultSettings(): ISettings {
},
},
customLists: [],
+ apiAccessMethods: [],
};
}
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 6c3a6373fb..3aa2cc3568 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -8,6 +8,7 @@ import config from '../config.json';
import { hasExpired } from '../shared/account-expiry';
import { IWindowsApplication } from '../shared/application-types';
import {
+ AccessMethodSetting,
DaemonEvent,
DeviceEvent,
IRelayListWithEndpointData,
@@ -117,6 +118,8 @@ class ApplicationMain
private relayList?: IRelayListWithEndpointData;
+ private currentApiAccessMethod?: AccessMethodSetting;
+
public constructor() {
this.daemonRpc = new DaemonRpc(
new ConnectionObserver(this.onDaemonConnected, this.onDaemonDisconnected),
@@ -550,6 +553,19 @@ class ApplicationMain
return this.handleBootstrapError(error);
}
+ // fetch current api access method
+ try {
+ this.currentApiAccessMethod = await this.daemonRpc.getCurrentApiAccessMethod();
+ IpcMainEventChannel.settings.notifyApiAccessMethodSettingChange?.(
+ this.currentApiAccessMethod,
+ );
+ } catch (e) {
+ const error = e as Error;
+ log.error(`Failed to fetch settings: ${error.message}`);
+
+ return this.handleBootstrapError(error);
+ }
+
if (this.tunnelStateExpectation) {
this.tunnelStateExpectation.fulfill();
}
@@ -658,6 +674,10 @@ class ApplicationMain
this.account.handleDeviceEvent(daemonEvent.device);
} else if ('deviceRemoval' in daemonEvent) {
IpcMainEventChannel.account.notifyDevices?.(daemonEvent.deviceRemoval);
+ } else if ('accessMethodSetting' in daemonEvent) {
+ IpcMainEventChannel.settings.notifyApiAccessMethodSettingChange?.(
+ daemonEvent.accessMethodSetting,
+ );
}
},
(error: Error) => {
@@ -726,6 +746,7 @@ class ApplicationMain
changelog: this.changelog ?? [],
forceShowChanges: CommandLineOptions.showChanges.match,
navigationHistory: this.navigationHistory,
+ currentApiAccessMethod: this.currentApiAccessMethod,
}));
IpcMainEventChannel.tunnel.handleConnect(this.connectTunnel);
diff --git a/gui/src/main/settings.ts b/gui/src/main/settings.ts
index fc2450581f..71a973daeb 100644
--- a/gui/src/main/settings.ts
+++ b/gui/src/main/settings.ts
@@ -71,6 +71,24 @@ export default class Settings implements Readonly<ISettings> {
IpcMainEventChannel.settings.handleSetObfuscationSettings((obfuscationSettings) => {
return this.daemonRpc.setObfuscationSettings(obfuscationSettings);
});
+ IpcMainEventChannel.settings.handleAddApiAccessMethod((method) => {
+ return this.daemonRpc.addApiAccessMethod(method);
+ });
+ IpcMainEventChannel.settings.handleUpdateApiAccessMethod((method) => {
+ return this.daemonRpc.updateApiAccessMethod(method);
+ });
+ IpcMainEventChannel.settings.handleRemoveApiAccessMethod((id) => {
+ return this.daemonRpc.removeApiAccessMethod(id);
+ });
+ IpcMainEventChannel.settings.handleSetApiAccessMethod((id) => {
+ return this.daemonRpc.setApiAccessMethod(id);
+ });
+ IpcMainEventChannel.settings.handleTestApiAccessMethodById((id) => {
+ return this.daemonRpc.testApiAccessMethodById(id);
+ });
+ IpcMainEventChannel.settings.handleTestCustomApiAccessMethod((method) => {
+ return this.daemonRpc.testCustomApiAccessMethod(method);
+ });
IpcMainEventChannel.guiSettings.handleSetEnableSystemNotifications((flag: boolean) => {
this.guiSettings.enableSystemNotifications = flag;
@@ -135,6 +153,9 @@ export default class Settings implements Readonly<ISettings> {
public get customLists() {
return this.settingsValue.customLists;
}
+ public get apiAccessMethods() {
+ return this.settingsValue.apiAccessMethods;
+ }
public get gui() {
return this.guiSettings;
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;
}
diff --git a/gui/src/shared/ipc-schema.ts b/gui/src/shared/ipc-schema.ts
index ecf34e93fb..3f348b1d86 100644
--- a/gui/src/shared/ipc-schema.ts
+++ b/gui/src/shared/ipc-schema.ts
@@ -2,11 +2,13 @@ import { GetTextTranslations } from 'gettext-parser';
import { ILinuxSplitTunnelingApplication, IWindowsApplication } from './application-types';
import {
+ AccessMethodSetting,
AccountDataError,
AccountToken,
BridgeSettings,
BridgeState,
CustomListError,
+ CustomProxy,
DeviceEvent,
DeviceState,
IAccountData,
@@ -17,6 +19,7 @@ import {
IDnsOptions,
IRelayListWithEndpointData,
ISettings,
+ NewAccessMethodSetting,
ObfuscationSettings,
RelaySettings,
TunnelState,
@@ -71,6 +74,7 @@ export interface IAppStateSnapshot {
changelog: IChangelog;
forceShowChanges: boolean;
navigationHistory?: IHistoryObject;
+ currentApiAccessMethod?: AccessMethodSetting;
}
// The different types of requests are:
@@ -160,6 +164,7 @@ export const ipcSchema = {
},
settings: {
'': notifyRenderer<ISettings>(),
+ apiAccessMethodSettingChange: notifyRenderer<AccessMethodSetting>(),
setAllowLan: invoke<boolean, void>(),
setShowBetaReleases: invoke<boolean, void>(),
setEnableIpv6: invoke<boolean, void>(),
@@ -172,6 +177,12 @@ export const ipcSchema = {
updateBridgeSettings: invoke<BridgeSettings, void>(),
setDnsOptions: invoke<IDnsOptions, void>(),
setObfuscationSettings: invoke<ObfuscationSettings, void>(),
+ addApiAccessMethod: invoke<NewAccessMethodSetting, string>(),
+ updateApiAccessMethod: invoke<AccessMethodSetting, void>(),
+ removeApiAccessMethod: invoke<string, void>(),
+ setApiAccessMethod: invoke<string, void>(),
+ testApiAccessMethodById: invoke<string, boolean>(),
+ testCustomApiAccessMethod: invoke<CustomProxy, boolean>(),
},
guiSettings: {
'': notifyRenderer<IGuiSettingsState>(),