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 531eb0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 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
9 changes: 3 additions & 6 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 @@ -60,7 +57,7 @@ export default class TunnelStateHandler {
public handleNewTunnelState(newState: TunnelState) {
if (newState.state === 'error' && newState.details) {
if (newState.details.cause === ErrorStateCause.needFullDiskPermissions) {
this.receivedFullDiskAccessError = true;
this.needFullDiskAccess = true;
}
}

Expand Down

0 comments on commit 531eb0d

Please sign in to comment.