Skip to content

Commit

Permalink
Adding the handleShutdown method to enhance the app's exit logic duri…
Browse files Browse the repository at this point in the history
…ng system shutdown/restart
  • Loading branch information
ircfspace committed Jan 4, 2025
1 parent 7c4b9f6 commit 335d966
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,23 @@ class OblivionDesktop {
});
}

private handleShutdown() {
if (this.state.mainWindow) {
this.state.mainWindow.webContents.send('app-shutdown');
}
return new Promise<void>(async (resolve, reject) => {
try {
if (this.state.mainWindow) {
await exitTheApp(this.state.mainWindow);
}
resolve();
} catch (error) {
reject(error);
log.error('Error during shutdown:', error);
}
});
}

private setupAppEvents(): void {
app.on('second-instance', () => {
if (this.state.mainWindow) {
Expand Down Expand Up @@ -400,19 +417,19 @@ class OblivionDesktop {
powerMonitor.on('shutdown', async (event: Event) => {
event.preventDefault();
try {
await exitTheApp(this.state.mainWindow);
await this.handleShutdown();
app.quit();
} catch {
app.quit();
app.exit(1);
}
});
} else {
app.on('session-end', async () => {
try {
await exitTheApp(this.state.mainWindow);
await this.handleShutdown();
app.quit();
} catch {
app.quit();
app.exit(1);
}
});
}
Expand Down

0 comments on commit 335d966

Please sign in to comment.