From dc27c52ddd52d92a3ff0bd1b81ba4633ac824e9d Mon Sep 17 00:00:00 2001 From: Jijo Joseph Date: Sun, 4 Feb 2024 14:03:01 +0530 Subject: [PATCH] Added new flag --awayOnSystemIdle --- app/browser/notifications/activityManager.js | 15 ++++++++--- app/browser/tools/activityHub.js | 10 +++++++ app/config/index.js | 5 ++++ app/index.js | 26 ++++++++++++++++--- ...IsmaelMartinez.teams_for_linux.appdata.xml | 7 +++++ package.json | 2 +- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/browser/notifications/activityManager.js b/app/browser/notifications/activityManager.js index 60dc0ffc..384c6710 100644 --- a/app/browser/notifications/activityManager.js +++ b/app/browser/notifications/activityManager.js @@ -34,9 +34,18 @@ class ActivityManager { watchSystemIdleState() { const self = this; - self.ipcRenderer.invoke('getSystemIdleState').then((value) => { - activityHub.setMachineState(value === 'active' ? 1 : 2); - const timeOut = (value === 'active' ? self.config.appIdleTimeoutCheckInterval : self.config.appActiveCheckInterval) * 1000; + self.ipcRenderer.invoke('getSystemIdleState').then((state) => { + activityHub.setMachineState(state.system === 'active' ? 1 : 2); + const timeOut = (state.system === 'active' ? self.config.appIdleTimeoutCheckInterval : self.config.appActiveCheckInterval) * 1000; + + if (this.config.awayOnSystemIdle) { + if (state.system === 'active' && state.userIdle === 1) { + activityHub.setUserStatus(1); + } else if (state.system !== 'active' && state.userCurrent === 1) { + activityHub.setUserStatus(3); + } + } + setTimeout(() => self.watchSystemIdleState(), timeOut); }); } diff --git a/app/browser/tools/activityHub.js b/app/browser/tools/activityHub.js index cc741916..ceb25731 100644 --- a/app/browser/tools/activityHub.js +++ b/app/browser/tools/activityHub.js @@ -61,6 +61,16 @@ class ActivityHub { }); } + /** + * + * @param {number} status + */ + setUserStatus(status) { + instance.whenReady().then((inst) => { + inst.injector.get('presenceService').setMyStatus(status, null, true); + }); + } + refreshAppState(controller, state) { const self = controller.appStateService; controller.appStateService.refreshAppState.apply(self, [() => { diff --git a/app/config/index.js b/app/config/index.js index 9cfd9c2c..e2a988a5 100644 --- a/app/config/index.js +++ b/app/config/index.js @@ -227,6 +227,11 @@ function argv(configPath, appVersion) { incomingCallCommandArgs: { default: [], describe: 'Arguments for the incomming call command.' + }, + awayOnSystemIdle: { + default: false, + describe: 'Sets the user status as away when system goes idle', + type: 'boolean' } }) .parse(process.argv.slice(1)); diff --git a/app/index.js b/app/index.js index 1ededd5a..36617677 100644 --- a/app/index.js +++ b/app/index.js @@ -31,6 +31,7 @@ const notificationSounds = [{ }]; let userStatus = -1; +let idleTimeUserStatus = -1; // Notification sound player /** @@ -56,7 +57,7 @@ app.commandLine.appendSwitch('try-supported-channel-layouts'); const disabledFeatures = app.commandLine.hasSwitch('disable-features') ? app.commandLine.getSwitchValue('disable-features').split(',') : ['HardwareMediaKeyHandling']; -if(!disabledFeatures.includes('HardwareMediaKeyHandling')) +if (!disabledFeatures.includes('HardwareMediaKeyHandling')) disabledFeatures.push('HardwareMediaKeyHandling'); app.commandLine.appendSwitch('disable-features', disabledFeatures.join(',')); @@ -172,9 +173,26 @@ async function handleGetSystemIdleTime() { } async function handleGetSystemIdleState() { - const idleState = powerMonitor.getSystemIdleState(config.appIdleTimeout); - logger.debug(`GetSystemIdleState => IdleTimeout: ${config.appIdleTimeout}s, IdleTimeoutPollInterval: ${config.appIdleTimeoutCheckInterval}s, ActiveCheckPollInterval: ${config.appActiveCheckInterval}s, IdleTime: ${powerMonitor.getSystemIdleTime()}s, IdleState: '${idleState}'`); - return idleState; + const systemIdleState = powerMonitor.getSystemIdleState(config.appIdleTimeout); + logger.debug(`GetSystemIdleState => IdleTimeout: ${config.appIdleTimeout}s, IdleTimeoutPollInterval: ${config.appIdleTimeoutCheckInterval}s, ActiveCheckPollInterval: ${config.appActiveCheckInterval}s, IdleTime: ${powerMonitor.getSystemIdleTime()}s, IdleState: '${systemIdleState}'`); + + if (systemIdleState !== 'active' && idleTimeUserStatus == -1) { + idleTimeUserStatus = userStatus; + } + + const state = { + ...{ + system: systemIdleState, + userIdle: idleTimeUserStatus, + userCurrent: userStatus + } + }; + + if (systemIdleState === 'active') { + idleTimeUserStatus = -1 + } + + return state; } async function handleGetZoomLevel(_, name) { diff --git a/com.github.IsmaelMartinez.teams_for_linux.appdata.xml b/com.github.IsmaelMartinez.teams_for_linux.appdata.xml index 8bd1c5ca..4dcf054b 100644 --- a/com.github.IsmaelMartinez.teams_for_linux.appdata.xml +++ b/com.github.IsmaelMartinez.teams_for_linux.appdata.xml @@ -14,6 +14,13 @@ https://github.com/IsmaelMartinez/teams-for-linux/issues com.github.IsmaelMartinez.teams_for_linux.desktop + + +
    +
  • New: Experimental switch --awayOnSystemIdle which sets the user status to away when system goes idle
  • +
+
+
    diff --git a/package.json b/package.json index c2076cd7..c68b9923 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "teams-for-linux", - "version": "1.4.9", + "version": "1.4.10", "main": "app/index.js", "description": "Unofficial client for Microsoft Teams for Linux", "homepage": "https://github.com/IsmaelMartinez/teams-for-linux",