Skip to content

Commit de60ef1

Browse files
dlonMarkusPettersson98
authored andcommitted
Restart daemon on exit if full-disk access error has been shown
1 parent 31d18ec commit de60ef1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

gui/src/main/daemon-rpc.ts

+4
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ export class DaemonRpc {
568568
await this.callEmpty(this.client.updateDevice);
569569
}
570570

571+
public prepareRestart(quit: boolean) {
572+
this.callBool(this.client.prepareRestart, quit);
573+
}
574+
571575
public async setDaitaSettings(daitaSettings: IDaitaSettings): Promise<void> {
572576
const grpcDaitaSettings = new grpcTypes.DaitaSettings();
573577
grpcDaitaSettings.setEnabled(daitaSettings.enabled);

gui/src/main/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ class ApplicationMain
322322
};
323323

324324
private onBeforeQuit = (event: Electron.Event) => {
325+
if (this.tunnelState.hasReceivedFullDiskError) {
326+
this.daemonRpc.prepareRestart(true);
327+
}
328+
325329
log.info('before-quit received');
326330
if (this.quitInitiated) {
327331
event.preventDefault();

gui/src/main/tunnel-state.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { connectEnabled, disconnectEnabled, reconnectEnabled } from '../shared/connect-helper';
2-
import { ILocation, TunnelState } from '../shared/daemon-rpc-types';
2+
import { ErrorStateCause, ILocation, TunnelState } from '../shared/daemon-rpc-types';
33
import { Scheduler } from '../shared/scheduler';
44

55
export interface TunnelStateProvider {
@@ -20,10 +20,15 @@ export default class TunnelStateHandler {
2020
// Scheduler for discarding the assumed next state.
2121
private tunnelStateFallbackScheduler = new Scheduler();
2222

23+
private receivedFullDiskError = false;
24+
2325
private lastKnownDisconnectedLocation: Partial<ILocation> | undefined;
2426

2527
public constructor(private delegate: TunnelStateHandlerDelegate) {}
2628

29+
public get hasReceivedFullDiskError() {
30+
return this.receivedFullDiskError;
31+
}
2732
public get tunnelState() {
2833
return this.tunnelStateValue;
2934
}
@@ -53,6 +58,12 @@ export default class TunnelStateHandler {
5358
}
5459

5560
public handleNewTunnelState(newState: TunnelState) {
61+
if (newState.state === 'error') {
62+
if (newState.details.cause === ErrorStateCause.needFullDiskPermissions) {
63+
this.receivedFullDiskError = true;
64+
}
65+
}
66+
5667
// If there's a fallback state set then the app is in an assumed next state and need to check
5768
// if it's now reached or if the current state should be ignored and set as the fallback state.
5869
if (this.tunnelStateFallback) {

0 commit comments

Comments
 (0)