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
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'
},
optInV2: {
mhenselin marked this conversation as resolved.
Show resolved Hide resolved
default: false,
describe: 'opt in to use V2',
IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
type: 'boolean'
},
proxyServer: {
default: null,
describe: 'Proxy Server with format address:port',
Expand Down
37 changes: 35 additions & 2 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ function applyAppConfiguration(config, window) {
});
}

if (config.optInV2) {
IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
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);
});
}

if (!config.optInV2) {
IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
window.webContents.executeJavaScript('localStorage.getItem("tmp.isOptedIntoT2Web");', true)
.then(result => {
if (result) {
window.webContents.executeJavaScript('localStorage.removeItem("tmp.isOptedIntoT2Web");', true)
.then(window.reload())
.catch(err => {
console.log('could not remove localStorage variable', err);
});
}
})
.catch(err => {
console.log('could not read localStorage variable', err);
});
IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
}

IsmaelMartinez marked this conversation as resolved.
Show resolved Hide resolved
window.webContents.setUserAgent(config.chromeUserAgent);

if (!config.minimized) {
Expand Down Expand Up @@ -180,7 +213,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 +388,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