1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-29 21:21:15 +02:00

Desktop: Remove useless React warnings from console

This commit is contained in:
Laurent Cozic 2019-12-18 11:49:44 +00:00
parent c534305c7b
commit ce7671151c
3 changed files with 36 additions and 0 deletions

View File

@ -33,6 +33,10 @@ class ElectronAppWrapper {
return this.win_; return this.win_;
} }
env() {
return this.env_;
}
createWindow() { createWindow() {
// Set to true to view errors if the application does not start // Set to true to view errors if the application does not start
const debugEarlyBugs = this.env_ === 'dev' && false; const debugEarlyBugs = this.env_ === 'dev' && false;

View File

@ -14,6 +14,10 @@ class Bridge {
return this.electronWrapper_; return this.electronWrapper_;
} }
env() {
return this.electronWrapper_.env();
}
processArgv() { processArgv() {
return process.argv; return process.argv;
} }

View File

@ -30,6 +30,34 @@ const EncryptionService = require('lib/services/EncryptionService');
const { bridge } = require('electron').remote.require('./bridge'); const { bridge } = require('electron').remote.require('./bridge');
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js'); const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
if (bridge().env() === 'dev') {
const newConsole = function(oldConsole) {
const output = {};
const fnNames = ['assert', 'clear', 'context', 'count', 'countReset', 'debug', 'dir', 'dirxml', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'memory', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeLog', 'timeStamp', 'trace', 'warn'];
for (const fnName of fnNames) {
if (fnName === 'warn') {
output.warn = function(...text) {
const s = [...text].join('');
// React spams the console with walls of warnings even outside of strict mode, and even after having renamed
// unsafe methods to UNSAFE_xxxx, so we need to hack the console to remove them...
if (s.indexOf('Warning: componentWillReceiveProps has been renamed, and is not recommended for use') === 0) return;
if (s.indexOf('Warning: componentWillUpdate has been renamed, and is not recommended for use.') === 0) return;
oldConsole.warn(...text);
};
} else {
output[fnName] = function(...text) {
return oldConsole[fnName](...text);
};
}
}
return output;
}(window.console);
window.console = newConsole;
}
console.info(`Environment: ${bridge().env()}`);
const fsDriver = new FsDriverNode(); const fsDriver = new FsDriverNode();
Logger.fsDriver_ = fsDriver; Logger.fsDriver_ = fsDriver;
Resource.fsDriver_ = fsDriver; Resource.fsDriver_ = fsDriver;