Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add opt in handling for teams v2 #1160

Merged
merged 10 commits into from
Mar 31, 2024
3 changes: 2 additions & 1 deletion app/appConfiguration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ let _AppConfiguration_settingsStore = new WeakMap();

class AppConfiguration {
/**
* @param {string} configPath
* @param {string} configPath
* @param appVersion
*/
constructor(configPath, appVersion) {
_AppConfiguration_configPath.set(this, configPath);
Expand Down
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();
IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
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
89 changes: 45 additions & 44 deletions app/config/README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ function argv(configPath, appVersion) {
describe: 'BrowserWindow webpreferences partition',
type: 'string'
},
optInTeamsV2: {
default: false,
describe: 'Opt in to use Teams V2',
type: 'boolean'
},
proxyServer: {
default: null,
describe: 'Proxy Server with format address:port',
Expand Down
28 changes: 26 additions & 2 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ function applyAppConfiguration(config, window) {
});
}

handleTeamsV2OptIn(config);

window.webContents.setUserAgent(config.chromeUserAgent);

if (!config.minimized) {
Expand All @@ -130,6 +132,28 @@ function applyAppConfiguration(config, window) {
}
}

function handleTeamsV2OptIn(config) {
if (config.optInTeamsV2) {
config.url = 'https://teams.microsoft.com/v2/';
window.webContents.executeJavaScript('localStorage.getItem("tmp.isOptedIntoT2Web");', true)
.then(result => {
if ((result == null) || !result) {
window.webContents.executeJavaScript('localStorage.setItem("tmp.isOptedIntoT2Web", true);', true)
.then(window.reload())
.catch(err => {
console.log('could not set localStorage variable', err);
});
}
})
.catch(err => {
console.log('could not read localStorage variable', err);
});
return;
}
window.webContents.executeJavaScript('localStorage.removeItem("tmp.isOptedIntoT2Web");', true)
.then(window.reload());
}

/**
* Applies Electron's spell checker capabilities if language codes are provided.
* @param {Array<string>} languages Array of language codes to use with spell checker.
Expand Down Expand Up @@ -180,7 +204,7 @@ function onDidFrameFinishLoad(event, isMainFrame, frameProcessId, frameRoutingId
}

const wf = webFrameMain.fromId(frameProcessId, frameRoutingId);
customCSS.onDidFrameFinishLoad(wf, config)
customCSS.onDidFrameFinishLoad(wf, config);
}

function restoreWindow() {
Expand Down Expand Up @@ -355,7 +379,7 @@ function addEventHandlers() {
window.webContents.session.webRequest.onBeforeSendHeaders(getWebRequestFilterFromURL(), onBeforeSendHeadersHandler);
login.handleLoginDialogTry(window);
window.webContents.on('did-finish-load', onDidFinishLoad);
window.webContents.on("did-frame-finish-load", onDidFrameFinishLoad);
window.webContents.on('did-frame-finish-load', onDidFrameFinishLoad);
window.on('closed', onWindowClosed);
window.webContents.addListener('before-input-event', onBeforeInput);
}
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.17",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down