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

Hotfix/remove recurring angular call #1154

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion app/browser/tools/activityHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ 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');
});
}

Expand All @@ -58,6 +62,8 @@ class ActivityHub {
} else {
inst.controller.appStateService.setMachineState(state);
}
}).catch(() => {
console.error('Failed to set Machine State');
});
}

Expand All @@ -68,6 +74,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
8 changes: 6 additions & 2 deletions app/browser/tools/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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);
}
}
}
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
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.14",
"version": "1.4.15",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down
Loading
Loading