Skip to content

Commit

Permalink
mattermost#1187 base proposal to sync user status to host OS
Browse files Browse the repository at this point in the history
  • Loading branch information
theriverman committed Dec 11, 2021
1 parent fca6a75 commit 93f1d66
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/UserActivityMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,27 @@ export class UserActivityMonitor extends EventEmitter {
log.error('Error getting system idle time:', err);
}
}, this.config.updateFrequencyMs) as unknown as number;

// Register powerMonitor listeners to synchornise user status to host OS events
log.debug('Registering powerMonitor listeners');
if (process.platform === 'win32' || process.platform === 'darwin') {
powerMonitor.addListener('lock-screen', this.listenerLockScreen);
powerMonitor.addListener('unlock-screen', this.listenerUnlockScreen);
}
}

/**
* Stop monitoring system events and idle time
*/
stopMonitoring() {
clearInterval(this.systemIdleTimeIntervalID);

// Unregister powerMonitor listeners to synchornise user status to host OS events
log.debug('Unregistering powerMonitor listeners');
if (process.platform === 'win32' || process.platform === 'darwin') {
powerMonitor.removeListener('lock-screen', this.listenerLockScreen);
powerMonitor.removeListener('unlock-screen', this.listenerUnlockScreen);
}
}

/**
Expand Down Expand Up @@ -135,6 +149,26 @@ export class UserActivityMonitor extends EventEmitter {
isSystemEvent,
});
}

protected listenerLockScreen() {
/**
* TODO:
* find a way to respect custom set user statuses, for example,
* don't do anything if the user has their status set to DnD.
*/
log.info('host OS screen has been locked');
userActivityMonitor.setActivityState(false, true);
}

protected listenerUnlockScreen() {
/**
* TODO:
* find a way to respect custom set user statuses, for example,
* don't do anything if the user has their status set to DnD.
*/
log.info('host OS screen has been unlocked');
userActivityMonitor.setActivityState(true, true);
}
}

const userActivityMonitor = new UserActivityMonitor();
Expand Down

0 comments on commit 93f1d66

Please sign in to comment.