Skip to content

Commit

Permalink
Merge pull request #1092 from jijojosephk/idle_away_flag
Browse files Browse the repository at this point in the history
Added new flag --awayOnSystemIdle
  • Loading branch information
jijojosephk authored Feb 4, 2024
2 parents 8553472 + dc27c52 commit dd2fe2f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
15 changes: 12 additions & 3 deletions app/browser/notifications/activityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
10 changes: 10 additions & 0 deletions app/browser/tools/activityHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, [() => {
Expand Down
5 changes: 5 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
26 changes: 22 additions & 4 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const notificationSounds = [{
}];

let userStatus = -1;
let idleTimeUserStatus = -1;

// Notification sound player
/**
Expand All @@ -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(','));
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions com.github.IsmaelMartinez.teams_for_linux.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
<releases>
<release version="1.4.10" date="2024-02-04">
<description>
<ul>
<li>New: Experimental switch --awayOnSystemIdle which sets the user status to away when system goes idle</li>
</ul>
</description>
</release>
<release version="1.4.9" date="2024-02-03">
<description>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit dd2fe2f

Please sign in to comment.