Skip to content

Commit

Permalink
adding how to debug in bug report, moving react logic into its own ha…
Browse files Browse the repository at this point in the history
…ndler, moving theme.js to use react instead of angular, change regex in mainAppWindow to allow for v1 and v2 versions and removing some rough lines
  • Loading branch information
IsmaelMartinez committed Apr 4, 2024
1 parent 134d579 commit c79c26b
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 75 deletions.
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ If applicable, add screenshots to help explain your problem.
- Installation package [deb, rpm, snap, AppImage, tar.gz, source...]
- Version [e.g. 0.1.17]

**Debug**
When possible, please run the application from the terminal using `--webDebug` and try to reproduce the error.

The provide in this section the output from both the terminal and the browser debug console.

```bash
teams-for-linux --webDebug --appLogLevels=error,info,warn,debug
```

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion app/appConfiguration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class AppConfiguration {
}
}

module.exports = { AppConfiguration };
module.exports = { AppConfiguration };
3 changes: 2 additions & 1 deletion app/browser/tools/activityHub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const instance = require('./instance');
const ReactHandler = require('./reactHandler');
/**
* @type {Array<{handler:(data)=>void,event:string,handle:number}>}
*/
Expand Down Expand Up @@ -56,7 +57,7 @@ class ActivityHub {
* @param {number} state
*/
setMachineState(state) {
const teams2IdleTracker = instance.getTeams2IdleTracker();
const teams2IdleTracker = ReactHandler.getTeams2IdleTracker();
if (teams2IdleTracker) {
try {
console.log(`setMachineState teams2 state=${state}`);
Expand Down
12 changes: 0 additions & 12 deletions app/browser/tools/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ 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
20 changes: 20 additions & 0 deletions app/browser/tools/reactHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ReactHandler {

_getTeams2ReactElement() {
return document.getElementById('app');
}

_getTeams2CoreServices() {
return this._getTeams2ReactElement()?._reactRootContainer?._internalRoot?.current?.updateQueue?.baseState?.element?.props?.coreServices;
}

getTeams2IdleTracker() {
return this._getTeams2CoreServices()?.clientState?._idleTracker;
}

getTeams2ClientPreferences() {
return this._getTeams2CoreServices()?.clientPreferences?.clientPreferences;
}
}

module.exports = new ReactHandler();
13 changes: 7 additions & 6 deletions app/browser/tools/theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const instance = require('./instance');
const ReactHandler = require('./reactHandler');

class ThemeManager {
/**
Expand All @@ -8,17 +8,18 @@ class ThemeManager {
init(config, ipcRenderer) {
this.ipcRenderer = ipcRenderer;
this.config = config;
ReactHandler.getTeams2ClientPreferences().followOsTheme = config.followSystemTheme;
if (config.followSystemTheme) {
this.ipcRenderer.on('system-theme-changed', this.applyTheme);
console.log('followSystemTheme', config.followSystemTheme);
this.ipcRenderer.on('system-theme-changed', this.applyTheme);
}
}

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

Expand Down
56 changes: 28 additions & 28 deletions app/browser/tools/wakeLock.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
var _WakeLock_lock = new WeakMap();
class WakeLock {
constructor() {
_WakeLock_lock.set(this, null);
}
constructor() {
_WakeLock_lock.set(this, null);
}

async enable() {
try {
var lock = await navigator.wakeLock.request('screen');
lock.addEventListener('release', () => {
console.log('Wake Lock was released');
});
console.log('Wake Lock is active');
_WakeLock_lock.set(this, lock);
async enable() {
try {
var lock = await navigator.wakeLock.request('screen');
lock.addEventListener('release', () => {
console.log('Wake Lock was released');
});
console.log('Wake Lock is active');
_WakeLock_lock.set(this, lock);

} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}

async disable() {
var lock = _WakeLock_lock.get(this);
if (!lock) {
return;
}
try {
await lock.release();
lock = null;
_WakeLock_lock.set(this, lock);
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}
async disable() {
var lock = _WakeLock_lock.get(this);
if (!lock) {
return;
}
try {
await lock.release();
lock = null;
_WakeLock_lock.set(this, lock);
} catch (err) {
console.error(`${err.name}, ${err.message}`);
}
}
}

const wakeLock = new WakeLock();
Expand Down
2 changes: 1 addition & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,4 @@ function onCustomBGServiceConfigDownloadFailure(err) {
catch (err) {
logger.error(`Failed to save remote configuration at '${dlpath}'`);
}
}
}
8 changes: 4 additions & 4 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ function restoreWindow() {
}

function processArgs(args) {
var regHttps = /^https:\/\/teams.microsoft.com\/l\/(meetup-join|channel)\//g;
var regMS = /^msteams:\/l\/(meetup-join|channel)\//g;
var regHttps = /^https:\/\/teams.microsoft.com\/.*(?:meetup-join|channel)/g;

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High

This regular expression has an unescaped '.' before 'microsoft.com', so it might match more hosts than expected.
var regMS = /^msteams:\/.*(?:meetup-join|channel)/g;
logger.debug('processArgs:', args);
for (const arg of args) {
if (regHttps.test(arg)) {
Expand Down Expand Up @@ -317,7 +317,7 @@ function onBeforeSendHeadersHandler(detail, callback) {
* @returns {{action: 'deny'} | {action: 'allow', outlivesOpener?: boolean, overrideBrowserWindowOptions?: Electron.BrowserWindowConstructorOptions}}
*/
function onNewWindow(details) {
if (details.url.startsWith('https://teams.microsoft.com/l/meetup-join')) {
if (details.url.startsWith('https://teams.microsoft.com/l/meetup-join') || details.url.startsWith('https://teams.microsoft.com/v2/l/meetup-join')) {
logger.debug('DEBUG - captured meetup-join url');
return { action: 'deny' };
} else if (details.url === 'about:blank' || details.url === 'about:blank#blocked') {
Expand Down Expand Up @@ -619,4 +619,4 @@ function enableWakeLockOnWindowRestore() {
if (isOnCall) {
window.webContents.send('enable-wakelock');
}
}
}
2 changes: 1 addition & 1 deletion app/menus/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ function getNotificationsMenu(Menus) {
}
]
};
}
}
2 changes: 1 addition & 1 deletion app/menus/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class ApplicationTray {
this.tray.destroy();
}
}
exports = module.exports = ApplicationTray;
exports = module.exports = ApplicationTray;
2 changes: 1 addition & 1 deletion app/spellCheckProvider/codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,4 @@ const codes = [
}
];

module.exports = codes;
module.exports = codes;
2 changes: 1 addition & 1 deletion app/spellCheckProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ function stringCompare(str1, str2) {
return le ? -1 : gr ? 1 : 0;
}

module.exports = { SpellCheckProvider };
module.exports = { SpellCheckProvider };
1 change: 0 additions & 1 deletion app/streamSelector/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,3 @@ function createQualitySelector(properties) {
defaultSelection = defaultSelection > -1 ? defaultSelection : properties.screens.length - 1;
properties.sscontainer.selectedIndex = defaultSelection;
}

2 changes: 0 additions & 2 deletions app/streamSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,3 @@ function createScreenRequestHandler() {
}

module.exports = { StreamSelector };


29 changes: 14 additions & 15 deletions scripts/afterpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const {flipFuses, FuseVersion, FuseV1Options} = require('@electron/fuses');
const {chmod} = require('fs/promises');

function getAppFileName(context) {
const productFileName = context.packager.appInfo.productFilename
const productFileName = context.packager.appInfo.productFilename;

switch (context.electronPlatformName) {
case 'win32':
return `${productFileName}.exe`;
case 'darwin':
return `${productFileName}.app`;
case 'mas':
return `${productFileName}.app`;
case 'linux':
return context.packager.executableName;
default:
return '';
case 'win32':
return `${productFileName}.exe`;
case 'darwin':
return `${productFileName}.app`;
case 'mas':
return `${productFileName}.app`;
case 'linux':
return context.packager.executableName;
default:
return '';
}
}

Expand All @@ -25,11 +25,10 @@ exports.default = async function afterPack(context) {
await flipFuses(
path,
{
version: FuseVersion.V1,
[FuseV1Options.EnableCookieEncryption]: true,
version: FuseVersion.V1,
[FuseV1Options.EnableCookieEncryption]: true,
},
);

);
} catch (error) {
console.error('afterPack error: ', error);
process.exit(1);
Expand Down

0 comments on commit c79c26b

Please sign in to comment.