Skip to content

Commit

Permalink
add support for changing idle (away) state in Teams2 (#1157)
Browse files Browse the repository at this point in the history
* add support for changing idle (away) state in Teams2

* package.json: bump version to 1.4.16
  • Loading branch information
bastidest committed Mar 28, 2024
1 parent 0135fc8 commit 82f480b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
32 changes: 24 additions & 8 deletions app/browser/tools/activityHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,31 @@ class ActivityHub {
* @param {number} state
*/
setMachineState(state) {
instance.whenReady().then((inst) => {
if (state === 1) {
this.refreshAppState(inst.controller, state);
} else {
inst.controller.appStateService.setMachineState(state);
const teams2IdleTracker = instance.getTeams2IdleTracker();
if (teams2IdleTracker) {
try {
console.log(`setMachineState teams2 state=${state}`);
if (state === 1) {
// ALTERNATIVE: teams2IdleTracker._idleStateBehaviorSubject.next('Active');
teams2IdleTracker.handleMonitoredWindowEvent();
} else {
// ALTERNATIVE: teams2IdleTracker._idleStateBehaviorSubject.next('Inactive');
teams2IdleTracker.transitionToIdle();
}
} catch(e) {
console.error('Failed to set teams2 Machine State', e);
}
}).catch(() => {
console.error('Failed to set Machine State');
});
} else {
instance.whenReady().then((inst) => {
if (state === 1) {
this.refreshAppState(inst.controller, state);
} else {
inst.controller.appStateService.setMachineState(state);
}
}).catch(() => {
console.error('Failed to set Machine State');
});
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions app/browser/tools/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ class Instance {
return await this.whenReady(tries + 1);
}
}

getTeams2ReactElement() {
return document.getElementById('app');
}

getTeams2CoreServices() {
return this.getTeams2ReactElement()?._reactRootContainer?._internalRoot?.current?.updateQueue?.baseState?.element?.props?.coreServices;
}

getTeams2IdleTracker() {
return this.getTeams2CoreServices()?.clientState?._idleTracker;
}
}

function getAppObjects() {
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.15",
"version": "1.4.16",
"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 82f480b

Please sign in to comment.