Skip to content

Commit

Permalink
Several improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SRichner committed Feb 21, 2024
1 parent 7191704 commit 1c859bd
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/electron/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ app.whenReady().then(async () => {
await appUpdaterService.checkForUpdates({ silent: true });
appUpdaterService.startCheckForUpdatesInterval();

await trackers.registerTrackerCallback(
TrackerType.WindowsActivityTracker,
WindowActivityTrackerService.handleWindowChange
);

await trackers.registerTrackerCallback(
TrackerType.UserInputTracker,
UserInputTrackerService.handleUserInputEvent
);
if (studyConfig.trackers.windowActivityTracker.enabled) {
await trackers.registerTrackerCallback(
TrackerType.WindowsActivityTracker,
WindowActivityTrackerService.handleWindowChange
);
}
if (studyConfig.trackers.userInputTracker.enabled) {
await trackers.registerTrackerCallback(
TrackerType.UserInputTracker,
UserInputTrackerService.handleUserInputEvent
);
}

await trackers.startAllTrackers();
LOG.info(`Trackers started: ${trackers.getRunningTrackerNames()}`);
LOG.info(`Trackers started: ${trackers.getRunningTrackerNames().join(', ')}`);

powerMonitor.on('suspend', async (): Promise<void> => {
LOG.debug('The system is going to sleep');
Expand Down Expand Up @@ -112,3 +115,23 @@ app.whenReady().then(async () => {
);
}
});

let isAppQuitting = false;
app.on('before-quit', async (event): Promise<void> => {
LOG.info('app.on(before-quit) called');
if (!isAppQuitting) {
event.preventDefault();
LOG.info(`Stopping all (${trackers.getRunningTrackerNames().join(', ')}) trackers...`);
await trackers.stopAllTrackers();
LOG.info(`All trackers stopped. Running: ${trackers.getRunningTrackerNames().length}`);
isAppQuitting = true;
app.exit();
}
});

// Don't quit when all windows are closed
app.on('window-all-closed', () => {
// if (process.platform !== 'darwin') {
// app.quit();
// }
});

0 comments on commit 1c859bd

Please sign in to comment.