Skip to content

Commit

Permalink
Feature/teams v2 activityhub changes (#1178)
Browse files Browse the repository at this point in the history
* initial wip work to move the tray notifications out of the activity manager/handler

* adding tray notification for react option

* adding the changes into the appdata file for flathub:
  • Loading branch information
IsmaelMartinez committed Apr 5, 2024
1 parent ab4d0cb commit 7c29935
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 179 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions app/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function initializeModules(config, ipcRenderer) {
require('./tools/zoom').init(config);
require('./tools/shortcuts').init(config);
require('./tools/chromeApi')(config);
require('./tools/mutationTitle').init(config);
require('./tools/trayIconRenderer').init(config, ipcRenderer);
require('./tools/settings').init(config, ipcRenderer);
require('./tools/customBackgrounds')(config, ipcRenderer);
require('./tools/theme').init(config, ipcRenderer);
Expand Down
47 changes: 3 additions & 44 deletions app/browser/notifications/activityManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const TrayIconRenderer = require('../tools/trayIconRenderer');
const activityHub = require('../tools/activityHub');
const wakeLock = require('../tools/wakeLock');

Expand All @@ -9,21 +8,10 @@ class ActivityManager {
*/
constructor(ipcRenderer, config) {
this.ipcRenderer = ipcRenderer;
this.iconRenderer = new TrayIconRenderer(config);
this.config = config;
this.myStatus = -1;
}

updateActivityCount(count) {
this.iconRenderer.render(count).then(icon => {
this.ipcRenderer.send('tray-update', {
icon: icon,
flash: (count > 0 && !this.config.disableNotificationWindowFlash)
});
});
this.ipcRenderer.invoke('set-badge-count', count);
}

start() {
setActivityHandlers(this);
setEventHandlers(this);
Expand Down Expand Up @@ -51,9 +39,6 @@ class ActivityManager {
}
}

/**
* @param {ActivityManager} self
*/
function setActivityHandlers(self) {
activityHub.on('activities-count-updated', updateActivityCountHandler(self));
activityHub.on('incoming-call-created', incomingCallCreatedHandler(self));
Expand All @@ -65,71 +50,48 @@ function setActivityHandlers(self) {
activityHub.on('my-status-changed', myStatusChangedHandler(self));
}

/**
* @param {ActivityManager} self
*/
function setEventHandlers(self) {
self.ipcRenderer.on('enable-wakelock', () => wakeLock.enable());
self.ipcRenderer.on('disable-wakelock', () => wakeLock.disable());
}

/**
* @param {ActivityManager} self
*/
function updateActivityCountHandler(self) {
function updateActivityCountHandler() {
return async (data) => {
self.updateActivityCount(data.count);
const event = new CustomEvent('unread-count', { detail: { number: data.count } });
window.dispatchEvent(event);
};
}

/**
* @param {ActivityManager} self
*/
function incomingCallCreatedHandler(self) {
return async (data) => {
self.ipcRenderer.invoke('incoming-call-created', data);
};
}

/**
* @param {ActivityManager} self
*/
function incomingCallConnectingHandler(self) {
return async () => {
self.ipcRenderer.invoke('incoming-call-connecting');
};
}

/**
* @param {ActivityManager} self
*/
function incomingCallDisconnectingHandler(self) {
return async () => {
self.ipcRenderer.invoke('incoming-call-disconnecting');
};
}

/**
* @param {ActivityManager} self
*/
function callConnectedHandler(self) {
return async () => {
self.ipcRenderer.invoke('call-connected');
};
}

/**
* @param {ActivityManager} self
*/
function callDisconnectedHandler(self) {
return async () => {
self.ipcRenderer.invoke('call-disconnected');
};
}

/**
* @param {ActivityManager} self
*/
// eslint-disable-next-line no-unused-vars
function meetingStartNotifyHandler(self) {
if (!self.config.disableMeetingNotifications) {
Expand All @@ -142,9 +104,6 @@ function meetingStartNotifyHandler(self) {
return null;
}

/**
* @param {ActivityManager} self
*/
// eslint-disable-next-line no-unused-vars
function myStatusChangedHandler(self) {
// eslint-disable-next-line no-unused-vars
Expand Down
32 changes: 32 additions & 0 deletions app/browser/tools/mutationTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class MutationObserverTitle {

init(config) {
if (config.useMutationTitleLogic) {
console.log('MutationObserverTitle enabled');
window.addEventListener('DOMContentLoaded', this._applyMutationToTitleLogic);
}
}

_applyMutationToTitleLogic() {
console.log('Appliying MutationObserverTitle logic');
const observer = new window.MutationObserver(
() => {
console.log('title changed');
console.log(window.document.title);
const regex = /^\((\d+)\)/;
const match = window.document.title.match(regex);
if (match) {
const number = match[1];
console.log(number);
const event = new CustomEvent('unread-count', { detail: { number: number } });
window.dispatchEvent(event);
}
}
);
observer.observe(window.document.querySelector('title'),{ childList: true });
console.log('MutationObserverTitle logic applied');
}

}

exports = module.exports = new MutationObserverTitle();
20 changes: 11 additions & 9 deletions app/browser/tools/reactHandler.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
class ReactHandler {

_getTeams2ReactElement() {
return document.getElementById('app');
getTeams2IdleTracker() {
const teams2CoreServices = this._getTeams2CoreServices();
return teams2CoreServices?.clientState?._idleTracker;
}

_getTeams2CoreServices() {
return this._getTeams2ReactElement()?._reactRootContainer?._internalRoot?.current?.updateQueue?.baseState?.element?.props?.coreServices;
getTeams2ClientPreferences() {
const teams2CoreServices = this._getTeams2CoreServices();
return teams2CoreServices?.clientPreferences?.clientPreferences;
}

getTeams2IdleTracker() {
return this._getTeams2CoreServices()?.clientState?._idleTracker;
_getTeams2ReactElement() {
return document.getElementById('app');
}

getTeams2ClientPreferences() {
return this._getTeams2CoreServices()?.clientPreferences?.clientPreferences;
_getTeams2CoreServices() {
const reactElement = this._getTeams2ReactElement();
return reactElement?._reactRootContainer?._internalRoot?.current?.updateQueue?.baseState?.element?.props?.coreServices;
}
}

Expand Down
60 changes: 28 additions & 32 deletions app/browser/tools/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@ const ReactHandler = require('./reactHandler');
const instance = require('./instance');

class ThemeManager {
/**
* @param {object} config
* @param {Electron.IpcRenderer} ipcRenderer
*/
init(config, ipcRenderer) {
this.ipcRenderer = ipcRenderer;
this.config = config;
init(config, ipcRenderer) {
this.ipcRenderer = ipcRenderer;
this.config = config;

const clientPreferences = ReactHandler.getTeams2ClientPreferences();
if (clientPreferences) {
console.log('Using react to set the follow system theme');
ReactHandler.getTeams2ClientPreferences().theme.followOsTheme = config.followSystemTheme;
}
const clientPreferences = ReactHandler.getTeams2ClientPreferences();
if (clientPreferences) {
console.log('Using react to set the follow system theme');
ReactHandler.getTeams2ClientPreferences().theme.followOsTheme = config.followSystemTheme;
}

if (config.followSystemTheme) {
console.log('followSystemTheme', config.followSystemTheme);
this.ipcRenderer.on('system-theme-changed', this.applyTheme);
}
}
if (config.followSystemTheme) {
console.log('followSystemTheme', config.followSystemTheme);
this.ipcRenderer.on('system-theme-changed', this.applyTheme);
}
}

applyTheme = async (event, ...args) => {
const theme = args[0] ? 'dark' : 'default';
const clientPreferences = ReactHandler.getTeams2ClientPreferences();
if (clientPreferences) {
console.log('Using react to set the theme');
clientPreferences.theme.userTheme = theme;
console.log('Theme changed to', theme);
} else {
console.log('Using angular to set the theme');
const inst = await instance.whenReady().catch(() => {
console.error('Failed to apply Theme');
});
inst.controller.layoutService.setTheme(theme);
}
}
async applyTheme (event, ...args) {
const theme = args[0] ? 'dark' : 'default';
const clientPreferences = ReactHandler.getTeams2ClientPreferences();
if (clientPreferences) {
console.log('Using react to set the theme');
clientPreferences.theme.userTheme = theme;
console.log('Theme changed to', theme);
} else {
console.log('Using angular to set the theme');
const inst = await instance.whenReady().catch(() => {
console.error('Failed to apply Theme');
});
inst.controller.layoutService.setTheme(theme);
}
}
}

module.exports = new ThemeManager();
19 changes: 17 additions & 2 deletions app/browser/tools/trayIconRenderer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
const { nativeImage } = require('electron');
const TrayIconChooser = require('./trayIconChooser');
class TrayIconRenderer {
constructor(config) {
init(config, ipcRenderer) {
this.ipcRenderer = ipcRenderer;
this.config = config;
const iconChooser = new TrayIconChooser(config);
this.baseIcon = nativeImage.createFromPath(iconChooser.getFile());
this.iconSize = this.baseIcon.getSize();
window.addEventListener('unread-count', this.updateActivityCount.bind(this));
}

updateActivityCount(event) {
const count = event.detail.number;
this.render(count).then(icon => {
console.log('sending tray-update');
this.ipcRenderer.send('tray-update', {
icon: icon,
flash: (count > 0 && !this.config.disableNotificationWindowFlash)
});
});
this.ipcRenderer.invoke('set-badge-count', count);
}

render(newActivityCount) {
Expand Down Expand Up @@ -57,4 +72,4 @@ class TrayIconRenderer {
}
}

module.exports = exports = TrayIconRenderer;
module.exports = exports = new TrayIconRenderer();

0 comments on commit 7c29935

Please sign in to comment.