Skip to content

Commit

Permalink
deprecate onlineCheckMethod and change log level to console.info (#1431)
Browse files Browse the repository at this point in the history
* automating the isOnline test to deprecate the need of checkOnlineMethod. Changing the default log level to console.info instead of using the electron-log defaults

* updating release date and improving the warning message
  • Loading branch information
IsmaelMartinez authored Oct 3, 2024
1 parent 33e040c commit c94791d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 80 deletions.
25 changes: 14 additions & 11 deletions app/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Here is the list of available arguments and its usage:
| appIconType | Type of tray icon to be used default/light/dark | *default*, light, dark |
| appIdleTimeout | A numeric value in seconds as duration before app considers the system as idle | 300 |
| appIdleTimeoutCheckInterval | A numeric value in seconds as poll interval to check if the appIdleTimeout is reached | 10 |
| appLogLevels | Comma separated list of log levels (error,warn,info,debug) | error,warn |
| appLogLevels **deprecated - use logLevels** | Comma separated list of log levels (error,warn,info,debug) | error,warn |
| appTitle | A text to be suffixed with page title | Microsoft Teams |
| authServerWhitelist | Set auth-server-whitelist value (string) | * |
| awayOnSystemIdle | Boolean to set the user status as away when system goes idle | false |
Expand Down Expand Up @@ -53,13 +53,13 @@ Here is the list of available arguments and its usage:
| incomingCallCommand | Command to execute on an incoming call. (string) | |
| incomingCallCommandArgs | Arguments for the incomming call command. | [] |
| isCustomBackgroundEnabled | A boolean flag to enable/disable custom background images | false |
| logConfig | A string value to set the log manager to use (`Falsy`, `console`, or a valid electron-log configuration) | *{}* (electron-log) |
| meetupJoinRegEx | Meetup-join and channel regular expession | /^https:\/\/teams\.(microsoft|live)\.com\/.*(?:meetup-join|channel)/g |
| logConfig | A string value to set the log manager to use (`Falsy`, `console`, or a valid electron-log configuration) | **console.info** via (electron-log) |
| meetupJoinRegEx | Meetup-join and channel regular expession | /^https:\/\/teams\.(microsoft\|live)\.com\/.*(?:meetup-join\|channel)/g |
| menubar | A value controls the menu bar behaviour | *auto*, visible, hidden |
| minimized | Boolean to start the application minimized | false |
| notificationMethod | Notification method to be used by the application (`web`/`electron`) | *web*, electron |
| ntlmV2enabled | Set enable-ntlm-v2 value | 'true' |
| onlineCheckMethod | Type of network test for checking online status. | *https*, dns, native, none |
| onlineCheckMethod **automated - please remove** | Type of network test for checking online status. | *https*, dns, native, none |
| optInTeamsV2 | Boolean to opt in to use Teams V2 | false |
| partition | BrowserWindow webpreferences partition | persist:teams-4-linux |
| proxyServer | Proxy Server with format address:port (string) | null |
Expand Down Expand Up @@ -205,18 +205,14 @@ This is managed by the `logConfig` option, that has the following options:

You have some simple options to use the `electron-log` as your log manager. Like:

* Use the default `electron-log` values:
```json
{ "logConfig": "{}" }
```

* Making console level as `debug` and disabling the log to file
**Current configuration**
* Making console level as `info` and disabling the log to file. :
```json
{
"logConfig": {
"transports": {
"console": {
"level": "debug"
"level": "info"
},
"file": {
"level": false
Expand All @@ -226,6 +222,13 @@ You have some simple options to use the `electron-log` as your log manager. Like
}
```


* Use the default `electron-log` values:
```json
{ "logConfig": {} }
```


Or more complex:

* Changing the console log format and rotating the file logs:
Expand Down
12 changes: 11 additions & 1 deletion app/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,16 @@ function extractYargConfig(configObject, appVersion) {
type: 'boolean'
},
logConfig: {
default: '{}',
default: {
"transports": {
"console": {
"level": "info"
},
"file": {
"level": false
}
}
},
describe: 'Electron-log configuration. See logger.js for configurable values. To disable it provide a Falsy value.',
type: 'object'
},
Expand Down Expand Up @@ -266,6 +275,7 @@ function extractYargConfig(configObject, appVersion) {
type: 'string'
},
onlineCheckMethod: {
deprecated: 'It has been automated.\n Please remove this option from your config file',
default: 'https',
describe: 'Type of network test for checking online status.',
type: 'string',
Expand Down
2 changes: 0 additions & 2 deletions app/config/logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const log = require('electron-log/main');
const _ = require('lodash');


exports.init = function (config) {
if (config) {
if (config == 'console') {
Expand All @@ -12,7 +11,6 @@ exports.init = function (config) {
_.mergeWith(log, config,
(obj, src) => typeof obj === 'function' ? Object.assign(obj, src) : undefined,
);
console.debug(`Logger initialised with transports: ${JSON.stringify(log.transports)}`);
log.initialize();
Object.assign(console, log.functions);
if (log.transports?.file?.level) {
Expand Down
114 changes: 60 additions & 54 deletions app/connectionManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@ class ConnectionManager {
_ConnectionManager_window.set(this, options.window);
_ConnectionManager_config.set(this, options.config);
_ConnectionManager_currentUrl.set(this, url || this.config.url);
ipcMain.on('offline-retry', assignOfflineRetryHandler(this));
powerMonitor.on('resume', assignOfflineRetryHandler(this));
ipcMain.on('offline-retry', this.refresh)
powerMonitor.on('resume', this.refresh);
this.window.webContents.on('did-fail-load', assignOnDidFailLoadEventHandler(this));
this.refresh();
}

async refresh() {
const currentUrl = this.window.webContents.getURL();
const hasUrl = currentUrl?.startsWith('https://');
const connected = await this.isOnline(1000, 1);
if (!connected) {
this.window.setTitle('Waiting for network...');
console.debug('Waiting for network...');
}
const retryConnected = connected || await this.isOnline(1000, 30);
if (retryConnected) {
this.window.setTitle('Waiting for network...');
console.debug('Waiting for network...');
const connected = await this.isOnline();
if (connected) {
if (hasUrl) {
this.window.reload();
} else {
Expand All @@ -48,56 +45,65 @@ class ConnectionManager {
}
}

async isOnline(timeout, retries) {
const onlineCheckMethod = this.config.onlineCheckMethod;
let resolved = false;
for (let i = 1; i <= retries && !resolved; i++) {
resolved = await this.isOnlineTest(onlineCheckMethod, this.config.url);
if (!resolved) await sleep(timeout);
}
if (resolved) {
console.debug('Network test successful with method ' + onlineCheckMethod);
} else {
console.debug('Network test failed with method ' + onlineCheckMethod);
}
return resolved;
}
async isOnline() {
const onlineCheckMethods = [
{
// Perform an actual HTTPS request, similar to loading the Teams app.
method: 'https',
tries: 10,
networkTest: async () => {
console.debug('Testing network using net.request() for ' + this.config.url);
return await isOnlineHttps(this.config.url);
}
},
{
// Sometimes too optimistic, might be false-positive where an HTTP proxy is
// mandatory but not reachable yet.
method: 'dns',
tries: 5,
networkTest: async () => {
const testDomain = (new URL(this.config.url)).hostname;
console.debug('Testing network using net.resolveHost() for ' + testDomain);
return await isOnlineDns(testDomain);
}
},
{
// Sounds good but be careful, too optimistic in my experience; and at the contrary,
// might also be false negative where no DNS is available for internet domains, but
// an HTTP proxy is actually available and working.
method: 'native',
tries: 5,
networkTest: async () => {
console.debug('Testing network using net.isOnline()');
return net.isOnline();
}
},
{
// That's more an escape gate in case all methods are broken, it disables
// the network test (assumes we're online).
method: 'none',
tries: 1,
networkTest: async () => {
console.warn('Network test is disabled, assuming online.');
return true;
}
}
];

async isOnlineTest(onlineCheckMethod, testUrl) {
switch (onlineCheckMethod) {
case 'none':
// That's more an escape gate in case all methods are broken, it disables
// the network test (assumes we're online).
console.warn('Network test is disabled, assuming online status.');
return true;
case 'dns': {
// Sometimes too optimistic, might be false-positive where an HTTP proxy is
// mandatory but not reachable yet.
const testDomain = (new URL(testUrl)).hostname;
console.debug('Testing network using net.resolveHost() for ' + testDomain);
return await isOnlineDns(testDomain);
}
case 'native':
// Sounds good but be careful, too optimistic in my experience; and at the contrary,
// might also be false negative where no DNS is available for internet domains, but
// an HTTP proxy is actually available and working.
console.debug('Testing network using net.isOnline()');
return net.isOnline();
case 'https':
default:
// Perform an actual HTTPS request, similar to loading the Teams app.
console.debug('Testing network using net.request() for ' + testUrl);
return await isOnlineHttps(testUrl);
for (const onlineCheckMethod of onlineCheckMethods) {
for (let i = 1; i <= onlineCheckMethod.tries; i++) {
const online = await onlineCheckMethod.networkTest();
if (online) {
console.debug('Network test successful with method ' + onlineCheckMethod.method);
return true;
}
await sleep(500);
}
}
return false;
}
}

function assignOfflineRetryHandler(cm) {
return () => {
cm.refresh();
};
}

function assignOnDidFailLoadEventHandler(cm) {
return (event, code, description) => {
console.error(`assignOnDidFailLoadEventHandler : ${JSON.stringify(event)} - ${code} - ${description}`);
Expand Down
8 changes: 8 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,14 @@
<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.11.1" date="2024-10-03">
<description>
<ul>
<li>Automated network check and deprecating `onlineCheckMethod`</li>
<li>Changing default logger to console.info and no file, instead of using the electron-log defaults</li>
</ul>
</description>
</release>
<release version="1.11.0" date="2024-09-24">
<description>
<ul>
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.11.0",
"version": "1.11.1",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down Expand Up @@ -53,12 +53,12 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@electron/fuses": "^1.7.0",
"@eslint/js": "^9.9.0",
"@electron/fuses": "^1.8.0",
"@eslint/js": "^9.11.1",
"electron": "^32.1.2",
"electron-builder": "^25.0.5",
"eslint": "^9.11.1",
"globals": "^15.9.0"
"globals": "^15.10.0"
},
"build": {
"appId": "teams-for-linux",
Expand Down

0 comments on commit c94791d

Please sign in to comment.