Skip to content

Commit

Permalink
Restart daemon when full-disk access message has been shown
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Nov 20, 2024
1 parent 634338a commit 7a55043
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 5 additions & 3 deletions desktop/packages/mullvad-vpn/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class ApplicationMain
};

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

Expand Down Expand Up @@ -832,8 +832,10 @@ class ApplicationMain
splitTunneling!.removeApplicationFromCache(application);
return Promise.resolve();
});
IpcMainEventChannel.macOsSplitTunneling.handleNeedFullDiskPermissions(() => {
return this.daemonRpc.needFullDiskPermissions();
IpcMainEventChannel.macOsSplitTunneling.handleNeedFullDiskPermissions(async () => {
const fullDiskState = await this.daemonRpc.needFullDiskPermissions();
this.tunnelState.needFullDiskAccess = fullDiskState;
return fullDiskState;
});

IpcMainEventChannel.app.handleQuit(() => this.disconnectAndQuit());
Expand Down
16 changes: 7 additions & 9 deletions desktop/packages/mullvad-vpn/src/main/tunnel-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 All @@ -20,15 +22,10 @@ export default class TunnelStateHandler {
// Scheduler for discarding the assumed next state.
private tunnelStateFallbackScheduler = new Scheduler();

private receivedFullDiskAccessError = false;

private lastKnownDisconnectedLocation: Partial<ILocation> | undefined;

public constructor(private delegate: TunnelStateHandlerDelegate) {}

public get hasReceivedFullDiskAccessError() {
return this.receivedFullDiskAccessError;
}
public get tunnelState() {
return this.tunnelStateValue;
}
Expand Down Expand Up @@ -58,10 +55,11 @@ export default class TunnelStateHandler {
}

public handleNewTunnelState(newState: TunnelState) {
if (newState.state === 'error' && newState.details) {
if (newState.details.cause === ErrorStateCause.needFullDiskPermissions) {
this.receivedFullDiskAccessError = true;
}
if (
newState.state === 'error' &&
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
Expand Down

0 comments on commit 7a55043

Please sign in to comment.