Skip to content

Commit

Permalink
Working on the handleShutdown method
Browse files Browse the repository at this point in the history
has become tiring, and I'm not getting the desired result. :|
  • Loading branch information
ircfspace committed Jan 4, 2025
1 parent 923274b commit e679645
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class OblivionDesktop {
await this.setupInitialConfiguration();
this.setupIpcEvents();
this.setupAppEvents();
this.handleShutdown();
}

private async setupInitialConfiguration(): Promise<void> {
Expand Down Expand Up @@ -403,20 +404,6 @@ class OblivionDesktop {
//this.exitProcess();
});

if (process.platform !== 'win32') {
powerMonitor.on('shutdown', async (event: Event) => {
event.preventDefault();
this.exitProcess();
});
} else {
app.on('session-end', () => {
this.exitProcess();
});
process.on('SIGTERM', () => {
this.exitProcess();
});
}

app.setAsDefaultProtocolClient('oblivion');
app.on('open-url', (event: Event) => {
event.preventDefault();
Expand All @@ -426,6 +413,31 @@ class OblivionDesktop {
});
}

private shutdownHandlersRegistered = false;
private handleShutdown(): void {
if (this.shutdownHandlersRegistered) return;
this.shutdownHandlersRegistered = true;
try {
if (process.platform === 'win32') {
app.on('session-end', () => {
this.exitProcess();
});
['SIGTERM', 'SIGINT', 'SIGHUP'].forEach((signal) => {
process.on(signal, () => {
this.exitProcess();
});
});
} else {
powerMonitor.on('shutdown', async (event: Event) => {
event.preventDefault();
this.exitProcess();
});
}
} catch (error) {
log.error('Error setting up shutdown handlers:', error);
}
}

private async setupTray(): Promise<void> {
this.state.userLang = String((await settings.get('lang')) || defaultSettings.lang);
this.state.appLang = getTranslate(this.state.userLang);
Expand Down

0 comments on commit e679645

Please sign in to comment.