Skip to content

Commit c94791d

Browse files
deprecate onlineCheckMethod and change log level to console.info (#1431)
* 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
1 parent 33e040c commit c94791d

File tree

7 files changed

+105
-80
lines changed

7 files changed

+105
-80
lines changed

app/config/README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here is the list of available arguments and its usage:
1919
| appIconType | Type of tray icon to be used default/light/dark | *default*, light, dark |
2020
| appIdleTimeout | A numeric value in seconds as duration before app considers the system as idle | 300 |
2121
| appIdleTimeoutCheckInterval | A numeric value in seconds as poll interval to check if the appIdleTimeout is reached | 10 |
22-
| appLogLevels | Comma separated list of log levels (error,warn,info,debug) | error,warn |
22+
| appLogLevels **deprecated - use logLevels** | Comma separated list of log levels (error,warn,info,debug) | error,warn |
2323
| appTitle | A text to be suffixed with page title | Microsoft Teams |
2424
| authServerWhitelist | Set auth-server-whitelist value (string) | * |
2525
| awayOnSystemIdle | Boolean to set the user status as away when system goes idle | false |
@@ -53,13 +53,13 @@ Here is the list of available arguments and its usage:
5353
| incomingCallCommand | Command to execute on an incoming call. (string) | |
5454
| incomingCallCommandArgs | Arguments for the incomming call command. | [] |
5555
| isCustomBackgroundEnabled | A boolean flag to enable/disable custom background images | false |
56-
| logConfig | A string value to set the log manager to use (`Falsy`, `console`, or a valid electron-log configuration) | *{}* (electron-log) |
57-
| meetupJoinRegEx | Meetup-join and channel regular expession | /^https:\/\/teams\.(microsoft|live)\.com\/.*(?:meetup-join|channel)/g |
56+
| logConfig | A string value to set the log manager to use (`Falsy`, `console`, or a valid electron-log configuration) | **console.info** via (electron-log) |
57+
| meetupJoinRegEx | Meetup-join and channel regular expession | /^https:\/\/teams\.(microsoft\|live)\.com\/.*(?:meetup-join\|channel)/g |
5858
| menubar | A value controls the menu bar behaviour | *auto*, visible, hidden |
5959
| minimized | Boolean to start the application minimized | false |
6060
| notificationMethod | Notification method to be used by the application (`web`/`electron`) | *web*, electron |
6161
| ntlmV2enabled | Set enable-ntlm-v2 value | 'true' |
62-
| onlineCheckMethod | Type of network test for checking online status. | *https*, dns, native, none |
62+
| onlineCheckMethod **automated - please remove** | Type of network test for checking online status. | *https*, dns, native, none |
6363
| optInTeamsV2 | Boolean to opt in to use Teams V2 | false |
6464
| partition | BrowserWindow webpreferences partition | persist:teams-4-linux |
6565
| proxyServer | Proxy Server with format address:port (string) | null |
@@ -205,18 +205,14 @@ This is managed by the `logConfig` option, that has the following options:
205205

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

208-
* Use the default `electron-log` values:
209-
```json
210-
{ "logConfig": "{}" }
211-
```
212-
213-
* Making console level as `debug` and disabling the log to file
208+
**Current configuration**
209+
* Making console level as `info` and disabling the log to file. :
214210
```json
215211
{
216212
"logConfig": {
217213
"transports": {
218214
"console": {
219-
"level": "debug"
215+
"level": "info"
220216
},
221217
"file": {
222218
"level": false
@@ -226,6 +222,13 @@ You have some simple options to use the `electron-log` as your log manager. Like
226222
}
227223
```
228224

225+
226+
* Use the default `electron-log` values:
227+
```json
228+
{ "logConfig": {} }
229+
```
230+
231+
229232
Or more complex:
230233

231234
* Changing the console log format and rotating the file logs:

app/config/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,16 @@ function extractYargConfig(configObject, appVersion) {
234234
type: 'boolean'
235235
},
236236
logConfig: {
237-
default: '{}',
237+
default: {
238+
"transports": {
239+
"console": {
240+
"level": "info"
241+
},
242+
"file": {
243+
"level": false
244+
}
245+
}
246+
},
238247
describe: 'Electron-log configuration. See logger.js for configurable values. To disable it provide a Falsy value.',
239248
type: 'object'
240249
},
@@ -266,6 +275,7 @@ function extractYargConfig(configObject, appVersion) {
266275
type: 'string'
267276
},
268277
onlineCheckMethod: {
278+
deprecated: 'It has been automated.\n Please remove this option from your config file',
269279
default: 'https',
270280
describe: 'Type of network test for checking online status.',
271281
type: 'string',

app/config/logger.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const log = require('electron-log/main');
22
const _ = require('lodash');
33

4-
54
exports.init = function (config) {
65
if (config) {
76
if (config == 'console') {
@@ -12,7 +11,6 @@ exports.init = function (config) {
1211
_.mergeWith(log, config,
1312
(obj, src) => typeof obj === 'function' ? Object.assign(obj, src) : undefined,
1413
);
15-
console.debug(`Logger initialised with transports: ${JSON.stringify(log.transports)}`);
1614
log.initialize();
1715
Object.assign(console, log.functions);
1816
if (log.transports?.file?.level) {

app/connectionManager/index.js

+60-54
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,19 @@ class ConnectionManager {
2121
_ConnectionManager_window.set(this, options.window);
2222
_ConnectionManager_config.set(this, options.config);
2323
_ConnectionManager_currentUrl.set(this, url || this.config.url);
24-
ipcMain.on('offline-retry', assignOfflineRetryHandler(this));
25-
powerMonitor.on('resume', assignOfflineRetryHandler(this));
24+
ipcMain.on('offline-retry', this.refresh)
25+
powerMonitor.on('resume', this.refresh);
2626
this.window.webContents.on('did-fail-load', assignOnDidFailLoadEventHandler(this));
2727
this.refresh();
2828
}
2929

3030
async refresh() {
3131
const currentUrl = this.window.webContents.getURL();
3232
const hasUrl = currentUrl?.startsWith('https://');
33-
const connected = await this.isOnline(1000, 1);
34-
if (!connected) {
35-
this.window.setTitle('Waiting for network...');
36-
console.debug('Waiting for network...');
37-
}
38-
const retryConnected = connected || await this.isOnline(1000, 30);
39-
if (retryConnected) {
33+
this.window.setTitle('Waiting for network...');
34+
console.debug('Waiting for network...');
35+
const connected = await this.isOnline();
36+
if (connected) {
4037
if (hasUrl) {
4138
this.window.reload();
4239
} else {
@@ -48,56 +45,65 @@ class ConnectionManager {
4845
}
4946
}
5047

51-
async isOnline(timeout, retries) {
52-
const onlineCheckMethod = this.config.onlineCheckMethod;
53-
let resolved = false;
54-
for (let i = 1; i <= retries && !resolved; i++) {
55-
resolved = await this.isOnlineTest(onlineCheckMethod, this.config.url);
56-
if (!resolved) await sleep(timeout);
57-
}
58-
if (resolved) {
59-
console.debug('Network test successful with method ' + onlineCheckMethod);
60-
} else {
61-
console.debug('Network test failed with method ' + onlineCheckMethod);
62-
}
63-
return resolved;
64-
}
48+
async isOnline() {
49+
const onlineCheckMethods = [
50+
{
51+
// Perform an actual HTTPS request, similar to loading the Teams app.
52+
method: 'https',
53+
tries: 10,
54+
networkTest: async () => {
55+
console.debug('Testing network using net.request() for ' + this.config.url);
56+
return await isOnlineHttps(this.config.url);
57+
}
58+
},
59+
{
60+
// Sometimes too optimistic, might be false-positive where an HTTP proxy is
61+
// mandatory but not reachable yet.
62+
method: 'dns',
63+
tries: 5,
64+
networkTest: async () => {
65+
const testDomain = (new URL(this.config.url)).hostname;
66+
console.debug('Testing network using net.resolveHost() for ' + testDomain);
67+
return await isOnlineDns(testDomain);
68+
}
69+
},
70+
{
71+
// Sounds good but be careful, too optimistic in my experience; and at the contrary,
72+
// might also be false negative where no DNS is available for internet domains, but
73+
// an HTTP proxy is actually available and working.
74+
method: 'native',
75+
tries: 5,
76+
networkTest: async () => {
77+
console.debug('Testing network using net.isOnline()');
78+
return net.isOnline();
79+
}
80+
},
81+
{
82+
// That's more an escape gate in case all methods are broken, it disables
83+
// the network test (assumes we're online).
84+
method: 'none',
85+
tries: 1,
86+
networkTest: async () => {
87+
console.warn('Network test is disabled, assuming online.');
88+
return true;
89+
}
90+
}
91+
];
6592

66-
async isOnlineTest(onlineCheckMethod, testUrl) {
67-
switch (onlineCheckMethod) {
68-
case 'none':
69-
// That's more an escape gate in case all methods are broken, it disables
70-
// the network test (assumes we're online).
71-
console.warn('Network test is disabled, assuming online status.');
72-
return true;
73-
case 'dns': {
74-
// Sometimes too optimistic, might be false-positive where an HTTP proxy is
75-
// mandatory but not reachable yet.
76-
const testDomain = (new URL(testUrl)).hostname;
77-
console.debug('Testing network using net.resolveHost() for ' + testDomain);
78-
return await isOnlineDns(testDomain);
79-
}
80-
case 'native':
81-
// Sounds good but be careful, too optimistic in my experience; and at the contrary,
82-
// might also be false negative where no DNS is available for internet domains, but
83-
// an HTTP proxy is actually available and working.
84-
console.debug('Testing network using net.isOnline()');
85-
return net.isOnline();
86-
case 'https':
87-
default:
88-
// Perform an actual HTTPS request, similar to loading the Teams app.
89-
console.debug('Testing network using net.request() for ' + testUrl);
90-
return await isOnlineHttps(testUrl);
93+
for (const onlineCheckMethod of onlineCheckMethods) {
94+
for (let i = 1; i <= onlineCheckMethod.tries; i++) {
95+
const online = await onlineCheckMethod.networkTest();
96+
if (online) {
97+
console.debug('Network test successful with method ' + onlineCheckMethod.method);
98+
return true;
99+
}
100+
await sleep(500);
101+
}
91102
}
103+
return false;
92104
}
93105
}
94106

95-
function assignOfflineRetryHandler(cm) {
96-
return () => {
97-
cm.refresh();
98-
};
99-
}
100-
101107
function assignOnDidFailLoadEventHandler(cm) {
102108
return (event, code, description) => {
103109
console.error(`assignOnDidFailLoadEventHandler : ${JSON.stringify(event)} - ${code} - ${description}`);

com.github.IsmaelMartinez.teams_for_linux.appdata.xml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
1515
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
1616
<releases>
17+
<release version="1.11.1" date="2024-10-03">
18+
<description>
19+
<ul>
20+
<li>Automated network check and deprecating `onlineCheckMethod`</li>
21+
<li>Changing default logger to console.info and no file, instead of using the electron-log defaults</li>
22+
</ul>
23+
</description>
24+
</release>
1725
<release version="1.11.0" date="2024-09-24">
1826
<description>
1927
<ul>

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "teams-for-linux",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"main": "app/index.js",
55
"description": "Unofficial client for Microsoft Teams for Linux",
66
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
@@ -53,12 +53,12 @@
5353
"yargs": "^17.7.2"
5454
},
5555
"devDependencies": {
56-
"@electron/fuses": "^1.7.0",
57-
"@eslint/js": "^9.9.0",
56+
"@electron/fuses": "^1.8.0",
57+
"@eslint/js": "^9.11.1",
5858
"electron": "^32.1.2",
5959
"electron-builder": "^25.0.5",
6060
"eslint": "^9.11.1",
61-
"globals": "^15.9.0"
61+
"globals": "^15.10.0"
6262
},
6363
"build": {
6464
"appId": "teams-for-linux",

0 commit comments

Comments
 (0)