Skip to content

Commit

Permalink
Move 'needFullDiskAccess' out of tunnel-state.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Nov 20, 2024
1 parent 531eb0d commit ba92de1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 19 additions & 4 deletions desktop/packages/mullvad-vpn/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AccessMethodSetting,
DaemonEvent,
DeviceEvent,
ErrorStateCause,
IRelayListWithEndpointData,
ISettings,
TunnelState,
Expand Down Expand Up @@ -130,6 +131,10 @@ class ApplicationMain

private currentApiAccessMethod?: AccessMethodSetting;

// If set to true, the GUI should restart the daemon when it exits.
// This is to make sure that the daemon is granted full-disk access.
private needFullDiskAccess = false;

public constructor() {
this.daemonRpc = new DaemonRpc(
new ConnectionObserver(this.onDaemonConnected, this.onDaemonDisconnected),
Expand Down Expand Up @@ -324,7 +329,7 @@ class ApplicationMain
};

private onBeforeQuit = async (event: Electron.Event) => {
if (this.tunnelState.needFullDiskAccess) {
if (this.needFullDiskAccess) {
await this.daemonRpc.prepareRestart(true);
}

Expand Down Expand Up @@ -537,7 +542,7 @@ class ApplicationMain

// fetch the tunnel state
try {
this.tunnelState.handleNewTunnelState(await this.daemonRpc.getState());
await this.handleNewTunnelState(await this.daemonRpc.getState());
} catch (e) {
const error = e as Error;
log.error(`Failed to fetch the tunnel state: ${error.message}`);
Expand Down Expand Up @@ -692,7 +697,7 @@ class ApplicationMain
const daemonEventListener = new SubscriptionListener(
(daemonEvent: DaemonEvent) => {
if ('tunnelState' in daemonEvent) {
this.tunnelState.handleNewTunnelState(daemonEvent.tunnelState);
this.handleNewTunnelState(daemonEvent.tunnelState);

Check failure on line 700 in desktop/packages/mullvad-vpn/src/main/index.ts

View workflow job for this annotation

GitHub Actions / check-frontend (ubuntu-latest)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else if ('settings' in daemonEvent) {
this.setSettings(daemonEvent.settings);
} else if ('relayList' in daemonEvent) {
Expand Down Expand Up @@ -738,6 +743,16 @@ class ApplicationMain
void this.updateSplitTunnelingApplications(newSettings.splitTunnel.appsList);
}

private async handleNewTunnelState(newState: TunnelState) {
this.tunnelState.handleNewTunnelState(await this.daemonRpc.getState());
if (
newState.state === 'error' &&
newState.details?.cause === ErrorStateCause.needFullDiskPermissions
) {
this.needFullDiskAccess = true;
}
}

private setRelayList(relayList: IRelayListWithEndpointData) {
this.relayList = relayList;
IpcMainEventChannel.relays.notify?.(relayList);
Expand Down Expand Up @@ -834,7 +849,7 @@ class ApplicationMain
});
IpcMainEventChannel.macOsSplitTunneling.handleNeedFullDiskPermissions(async () => {
const fullDiskState = await this.daemonRpc.needFullDiskPermissions();
this.tunnelState.needFullDiskAccess = fullDiskState;
this.needFullDiskAccess = fullDiskState;
return fullDiskState;
});

Expand Down
10 changes: 1 addition & 9 deletions desktop/packages/mullvad-vpn/src/main/tunnel-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connectEnabled, disconnectEnabled, reconnectEnabled } from '../shared/connect-helper';
import { ErrorStateCause, ILocation, TunnelState } from '../shared/daemon-rpc-types';
import { ILocation, TunnelState } from '../shared/daemon-rpc-types';
import { Scheduler } from '../shared/scheduler';

export interface TunnelStateProvider {
Expand All @@ -11,8 +11,6 @@ export interface TunnelStateHandlerDelegate {
}

export default class TunnelStateHandler {
public needFullDiskAccess = false;

// The current tunnel state
private tunnelStateValue: TunnelState = { state: 'disconnected' };
// When pressing connect/disconnect/reconnect the app assumes what the next state will be before
Expand Down Expand Up @@ -55,12 +53,6 @@ export default class TunnelStateHandler {
}

public handleNewTunnelState(newState: TunnelState) {
if (newState.state === 'error' && newState.details) {
if (newState.details.cause === ErrorStateCause.needFullDiskPermissions) {
this.needFullDiskAccess = true;
}
}

// If there's a fallback state set then the app is in an assumed next state and need to check
// if it's now reached or if the current state should be ignored and set as the fallback state.
if (this.tunnelStateFallback) {
Expand Down

0 comments on commit ba92de1

Please sign in to comment.