Skip to content

Commit

Permalink
adding the enableBackgroundCallsAuthentication removing writeUrlBlock…
Browse files Browse the repository at this point in the history
…Log, doing some check on the connectionManager and tray to ensure we don't get undefined values
  • Loading branch information
IsmaelMartinez committed Jan 21, 2025
1 parent 9575328 commit b1a18c5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 43 deletions.
4 changes: 3 additions & 1 deletion app/browser/tools/reactHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ class ReactHandler {
}
//document.getElementById('app')._reactRootContainer.current.updateQueue.baseState.element.props.coreServices

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

// document.getElementById('app')._reactRootContainer.current.updateQueue.baseState.element.props.coreServices.authenticationService._coreAuthService._authProvider.acquireToken("https://graph.microsoft.com", { correlation: document.getElementById('app')._reactRootContainer.current.updateQueue.baseState.element.props.coreServices.correlation} )
7 changes: 6 additions & 1 deletion app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ function extractYargConfig(configObject, appVersion) {
default: false,
describe: 'Use windows platform information in chromium. This is helpful if MFA app does not support Linux.'
},
enableBackgroundCallsAuthentication: {
default: true,
describe: 'Enable background calls for authentication to open in a child browser window (temporary solution for debugging)',
type: 'boolean'
},
followSystemTheme: {
default: false,
describe: 'Follow system theme',
Expand Down Expand Up @@ -242,7 +247,7 @@ function extractYargConfig(configObject, appVersion) {
default: {
"transports": {
"console": {
"level": "info"
"level": "debug"
},
"file": {
"level": false
Expand Down
10 changes: 8 additions & 2 deletions app/connectionManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ class ConnectionManager {
}

async refresh() {
const currentUrl = this.window.webContents.getURL();
if (!this.window) {
console.warn('Window is not available. Cannot refresh.');
return;
}
const currentUrl = this.window?.webContents?.getURL() || '';
const hasUrl = currentUrl?.startsWith('https://');
this.window.setTitle('Waiting for network...');
this.window?.setTitle('Waiting for network...');
console.debug('Waiting for network...');
const connected = await this.isOnline();
if (connected) {
if (hasUrl) {
console.debug('Reloading current page...');
this.window.reload();
} else {
console.debug('Loading initial URL...');
this.window.loadURL(this.currentUrl, { userAgent: this.config.chromeUserAgent });
}
} else {
Expand Down
40 changes: 11 additions & 29 deletions app/mainAppWindow/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { shell, app, nativeTheme, dialog, webFrameMain, Notification } = require('electron');
const path = require('path');
const { shell, BrowserWindow, app, nativeTheme, dialog, webFrameMain } = require('electron');
const login = require('../login');
const customCSS = require('../customCSS');
const Menus = require('../menus');
Expand All @@ -8,13 +7,11 @@ const { execFile } = require('child_process');
const TrayIconChooser = require('../browser/tools/trayIconChooser');
require('../appConfiguration');
const connMgr = require('../connectionManager');
const fs = require('fs');
const BrowserWindowManager = require('../mainAppWindow/browserWindowManager');

let iconChooser;
let intune;
let isControlPressed = false;
let lastNotifyTime = null;
let aboutBlankRequestCount = 0;
let config;
let window = null;
Expand Down Expand Up @@ -237,10 +234,17 @@ function onBeforeRequestHandler(details, callback) {
// Proceed normally
callback({});
} else {
// Open the request externally
console.debug('DEBUG - webRequest to ' + details.url + ' intercepted!');
//shell.openExternal(details.url);
writeUrlBlockLog(details.url);
if (this.config.enableBackgroundCallsAuthentication) {
console.debug('Opening the request in a hidden child window for authentication');
const child = new BrowserWindow({ parent: window, show: false });
child.loadURL(details.url);
child.once('ready-to-show', () => {
console.debug('Destroying the hidden child window');
child.destroy();
})
}

// decrement the counter
aboutBlankRequestCount -= 1;
callback({ cancel: true });
Expand Down Expand Up @@ -281,28 +285,6 @@ function onNewWindow(details) {
return secureOpenLink(details);
}

async function writeUrlBlockLog(url) {
const curBlockTime = new Date();
const logfile = path.join(appConfig.configPath, 'teams-for-linux-blocked.log');
const lstream = fs.createWriteStream(logfile, { flags: 'a' }).on('error', onLogStreamError);
lstream.write(`[${new Date().toLocaleString()}]: Blocked '${url}'\n`, onLogStreamError);
lstream.end();
const notifDuration = lastNotifyTime == null ? 60 : (curBlockTime.getTime() - lastNotifyTime.getTime()) / 1000;
if (notifDuration >= 60) {
new Notification({
title: 'Teams for Linux',
body: 'One or more web requests have been blocked. Please check the log for more details.'
}).show();
lastNotifyTime = curBlockTime;
}
}

function onLogStreamError(e) {
if (e) {
console.error(`onLogStreamError ${e.message}`);
}
}

function onPageTitleUpdated(_event, title) {
window.webContents.send('page-title', title);
}
Expand Down
13 changes: 6 additions & 7 deletions app/menus/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ class ApplicationTray {
this.iconPath = iconPath;
this.appMenu = appMenu;
this.config = config;
this.addTray();
}

addTray() {
this.tray = new Tray(this.iconPath);
this.tray.setToolTip(this.config.appTitle);
this.tray.on('click', () => this.showAndFocusWindow());
Expand All @@ -28,14 +25,16 @@ class ApplicationTray {
}

updateTrayImage(iconUrl, flash) {
const image = nativeImage.createFromDataURL(iconUrl);
if (this.tray && !this.tray.isDestroyed()) {
const image = nativeImage.createFromDataURL(iconUrl);

this.tray.setImage(image);
this.window.flashFrame(flash);
this.tray.setImage(image);
this.window.flashFrame(flash);
}
}

close() {
this.tray.destroy();
!this.tray.isDestroyed() ? this.tray.destroy() : null;
}
}
exports = module.exports = ApplicationTray;
10 changes: 10 additions & 0 deletions com.github.IsmaelMartinez.teams_for_linux.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
<releases>
<release version="1.12.7" date="2025-02-15">
<description>
<ul>
<li>Adding enableBackgroundCallsAuthentication config option to validate if this keeps the user authenticated for longer</li>
<li>Removing the writeUrlBlockLog function that use to log those requests into a file for debugging</li>
<li>Handling of UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'webContents') at PowerMonitor.refresh (.../app/connectionManager/index.js:31:34)</li>
<li>Checking the tray status before trying to update the badge count</li>
</ul>
</description>
</release>
<release version="1.12.6" date="2025-01-17">
<description>
<ul>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.12.6",
"version": "1.12.7",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down

0 comments on commit b1a18c5

Please sign in to comment.