Skip to content

Commit

Permalink
Pull 04 04 (#3)
Browse files Browse the repository at this point in the history
* removing the angular recurring call to disable some promotions as I suspect is creating a wee leak (IsmaelMartinez#1152)

* Hotfix/remove recurring angular call (IsmaelMartinez#1153)

* removing the angular recurring call to disable some promotions as I suspect is creating a wee leak

* missing removal of angular in the index.js browser section

* Hotfix/remove recurring angular call (IsmaelMartinez#1154)

* removing the angular recurring call to disable some promotions as I suspect is creating a wee leak

* missing removal of angular in the index.js browser section

* only retry 5 times to get the angular instances

* add support for changing idle (away) state in Teams2 (IsmaelMartinez#1157)

* add support for changing idle (away) state in Teams2

* package.json: bump version to 1.4.16

* feat: add opt in handling for teams v2 (IsmaelMartinez#1160)

* feat: add opt in handling for teams v2

* add support for changing idle (away) state in Teams2 (IsmaelMartinez#1157)

* add support for changing idle (away) state in Teams2

* package.json: bump version to 1.4.16

* feat: add opt in handling for teams v2

* fix: handle both cases and avoid unnecessary reloads

* chore: version bump

* Update app/config/index.js

wording change - accepted

Co-authored-by: IsmaelMartinez <ISMAELMARTINEZ@GMAIL.COM>

* chore: updated README

fix: fix some codeBeat failures

* fix: missing passed option object

* Update app/config/index.js

---------

Co-authored-by: Marcel S. Henselin <marcel.henselin@mmmake.com>
Co-authored-by: Sebastian Hiebl <bastidest@mailbox.org>
Co-authored-by: IsmaelMartinez <ISMAELMARTINEZ@GMAIL.COM>

---------

Co-authored-by: IsmaelMartinez <ISMAELMARTINEZ@GMAIL.COM>
Co-authored-by: Sebastian Hiebl <bastidest@mailbox.org>
Co-authored-by: Marcel S. Henselin <marcel@henselin.net>
Co-authored-by: Marcel S. Henselin <marcel.henselin@mmmake.com>
Co-authored-by: Kristian Magaš <km@appon.net>
  • Loading branch information
6 people committed Apr 4, 2024
1 parent 8925d90 commit 7acbb8a
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 166 deletions.
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
29 changes: 0 additions & 29 deletions app/browser/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global angular */
(function () {
const { ipcRenderer } = require('electron');
const ActivityManager = require('./notifications/activityManager');
Expand All @@ -10,36 +9,8 @@

new ActivityManager(ipcRenderer, config).start();

document.addEventListener('DOMContentLoaded', () => {
modifyAngularSettingsWithTimeout();
});
});

function disablePromoteStuff(injector) {
injector.get('settingsService').appConfig.promoteMobile = false;
injector.get('settingsService').appConfig.promoteDesktop = false;
injector.get('settingsService').appConfig.hideGetAppButton = true;
injector.get('settingsService').appConfig.enableMobileDownloadMailDialog = false;
}

function modifyAngularSettingsWithTimeout() {
setTimeout(() => {
try {
let injector = angular.element(document).injector();

if (injector) {
disablePromoteStuff(injector);

injector.get('settingsService').settingsService.refreshSettings();
}
} catch (error) {
if (error instanceof ReferenceError) {
modifyAngularSettingsWithTimeout();
}
}
}, 4000);
}

Object.defineProperty(navigator.serviceWorker, 'register', {
value: () => {
return Promise.reject();
Expand Down
38 changes: 31 additions & 7 deletions app/browser/tools/activityHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,48 @@ class ActivityHub {
}

start() {
instance.whenReady().then(assignEventHandlers);
instance.whenReady().then(assignEventHandlers).catch(() => {
console.error('Failed to start Activity Hub by assigning Event Handlers');
});
}

setDefaultTitle(title) {
instance.whenReady().then(inst => {
inst.controller.pageTitleDefault = title;
}).catch(() => {
console.error('Failed to set Default Title');
});
}

/**
* @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);
}
});
} 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 All @@ -68,6 +90,8 @@ class ActivityHub {
setUserStatus(status) {
instance.whenReady().then((inst) => {
inst.injector.get('presenceService').setMyStatus(status, null, true);
}).catch(() => {
console.error('Failed to set User Status');
});
}

Expand Down
4 changes: 3 additions & 1 deletion app/browser/tools/customBackgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ let ipRenderer = null;
function init(conf, ipcr) {
config = conf;
ipRenderer = ipcr;
instance.whenReady().then(overrideMSMethod);
instance.whenReady().then(overrideMSMethod).catch(() => {
console.error('Failed to override MS Method');
});
}

/**
Expand Down
20 changes: 18 additions & 2 deletions app/browser/tools/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@ class Instance {
/**
* @returns {Promise<{controller:object,injector:object}>}
*/
async whenReady() {
async whenReady(tries = 0) {
if (tries >= 5) {
throw new Error('Failed to get app objects after 5 tries');
}

const obj = getAppObjects();
if (obj) {
return obj;
} else {
await sleep(4000);
return await this.whenReady();
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
10 changes: 8 additions & 2 deletions app/browser/tools/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Settings {
* @param {Electron.IpcRendererEvent} event
*/
async function retrieve(event) {
const inst = await instance.whenReady();
const inst = await instance.whenReady().catch(() => {
console.error('Failed to retrieve Teams settings');
return;
});
const settings = {
theme: inst.controller.layoutService.getTheme(),
chatDensity: inst.controller.layoutService.getChatDensity(),
Expand All @@ -55,7 +58,10 @@ function getDeviceLabelFromId(controller, id, kind) {
* @param {...any} args
*/
async function restore(event, ...args) {
const inst = await instance.whenReady();
const inst = await instance.whenReady().catch(() => {
console.error('Failed to restore Teams settings');
return;
});
inst.controller.layoutService.setTheme(args[0].theme);
inst.controller.layoutService.setChatDensity(args[0].chatDensity);
args[0].devices.camera = getDeviceIdFromLabel(inst.controller,args[0].devices.camera,1);
Expand Down
4 changes: 3 additions & 1 deletion app/browser/tools/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class ThemeManager {

applyTheme = async (event, ...args) => {
const theme = args[0] ? 'dark' : 'default';
const inst = await instance.whenReady();
const inst = await instance.whenReady().catch(() => {
console.error('Failed to apply Theme');
});
inst.controller.layoutService.setTheme(theme);
}
}
Expand Down

0 comments on commit 7acbb8a

Please sign in to comment.