You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
This commit is contained in:
@ -31,117 +31,122 @@ const React = require('react');
|
||||
const nodeSqlite = require('sqlite3');
|
||||
const initLib = require('@joplin/lib/initLib').default;
|
||||
|
||||
|
||||
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);
|
||||
};
|
||||
const main = async () => {
|
||||
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);
|
||||
return output;
|
||||
}(window.console);
|
||||
|
||||
window.console = newConsole;
|
||||
}
|
||||
window.console = newConsole;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`Environment: ${bridge().env()}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`Environment: ${bridge().env()}`);
|
||||
|
||||
const fsDriver = new FsDriverNode();
|
||||
Logger.fsDriver_ = fsDriver;
|
||||
Resource.fsDriver_ = fsDriver;
|
||||
EncryptionService.fsDriver_ = fsDriver;
|
||||
FileApiDriverLocal.fsDriver_ = fsDriver;
|
||||
const fsDriver = new FsDriverNode();
|
||||
Logger.fsDriver_ = fsDriver;
|
||||
Resource.fsDriver_ = fsDriver;
|
||||
EncryptionService.fsDriver_ = fsDriver;
|
||||
FileApiDriverLocal.fsDriver_ = fsDriver;
|
||||
|
||||
// That's not good, but it's to avoid circular dependency issues
|
||||
// in the BaseItem class.
|
||||
BaseItem.loadClass('Note', Note);
|
||||
BaseItem.loadClass('Folder', Folder);
|
||||
BaseItem.loadClass('Resource', Resource);
|
||||
BaseItem.loadClass('Tag', Tag);
|
||||
BaseItem.loadClass('NoteTag', NoteTag);
|
||||
BaseItem.loadClass('MasterKey', MasterKey);
|
||||
BaseItem.loadClass('Revision', Revision);
|
||||
// That's not good, but it's to avoid circular dependency issues
|
||||
// in the BaseItem class.
|
||||
BaseItem.loadClass('Note', Note);
|
||||
BaseItem.loadClass('Folder', Folder);
|
||||
BaseItem.loadClass('Resource', Resource);
|
||||
BaseItem.loadClass('Tag', Tag);
|
||||
BaseItem.loadClass('NoteTag', NoteTag);
|
||||
BaseItem.loadClass('MasterKey', MasterKey);
|
||||
BaseItem.loadClass('Revision', Revision);
|
||||
|
||||
Setting.setConstant('appId', `net.cozic.joplin${bridge().env() === 'dev' ? 'dev' : ''}-desktop`);
|
||||
Setting.setConstant('appType', 'desktop');
|
||||
Setting.setConstant('appId', `net.cozic.joplin${bridge().env() === 'dev' ? 'dev' : ''}-desktop`);
|
||||
Setting.setConstant('appType', 'desktop');
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`appId: ${Setting.value('appId')}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`appType: ${Setting.value('appType')}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`appId: ${Setting.value('appId')}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(`appType: ${Setting.value('appType')}`);
|
||||
|
||||
let keytar;
|
||||
try {
|
||||
keytar = shim.platformSupportsKeyChain() ? require('keytar') : null;
|
||||
} catch (error) {
|
||||
console.error('Cannot load keytar - keychain support will be disabled', error);
|
||||
keytar = null;
|
||||
}
|
||||
let keytar;
|
||||
try {
|
||||
keytar = shim.platformSupportsKeyChain() ? require('keytar') : null;
|
||||
} catch (error) {
|
||||
console.error('Cannot load keytar - keychain support will be disabled', error);
|
||||
keytar = null;
|
||||
}
|
||||
|
||||
function appVersion() {
|
||||
const p = require('./packageInfo.js');
|
||||
return p.version;
|
||||
}
|
||||
function appVersion() {
|
||||
const p = require('./packageInfo.js');
|
||||
return p.version;
|
||||
}
|
||||
|
||||
shimInit({
|
||||
keytar,
|
||||
React,
|
||||
appVersion,
|
||||
electronBridge: bridge(),
|
||||
nodeSqlite,
|
||||
});
|
||||
shimInit({
|
||||
keytar,
|
||||
React,
|
||||
appVersion,
|
||||
electronBridge: bridge(),
|
||||
nodeSqlite,
|
||||
});
|
||||
|
||||
// Disable drag and drop of links inside application (which would
|
||||
// open it as if the whole app was a browser)
|
||||
document.addEventListener('dragover', event => event.preventDefault());
|
||||
document.addEventListener('drop', event => event.preventDefault());
|
||||
// Disable drag and drop of links inside application (which would
|
||||
// open it as if the whole app was a browser)
|
||||
document.addEventListener('dragover', event => event.preventDefault());
|
||||
document.addEventListener('drop', event => event.preventDefault());
|
||||
|
||||
// Disable middle-click (which would open a new browser window, but we don't want this)
|
||||
document.addEventListener('auxclick', event => event.preventDefault());
|
||||
// Disable middle-click (which would open a new browser window, but we don't want this)
|
||||
document.addEventListener('auxclick', event => event.preventDefault());
|
||||
|
||||
// Each link (rendered as a button or list item) has its own custom click event
|
||||
// so disable the default. In particular this will disable Ctrl+Clicking a link
|
||||
// which would open a new browser window.
|
||||
document.addEventListener('click', (event) => {
|
||||
// We don't apply this to labels and inputs because it would break
|
||||
// checkboxes. Such a global event handler is probably not a good idea
|
||||
// anyway but keeping it for now, as it doesn't seem to break anything else.
|
||||
// https://github.com/facebook/react/issues/13477#issuecomment-489274045
|
||||
if (['LABEL', 'INPUT'].includes(event.target.nodeName)) return;
|
||||
// Each link (rendered as a button or list item) has its own custom click event
|
||||
// so disable the default. In particular this will disable Ctrl+Clicking a link
|
||||
// which would open a new browser window.
|
||||
document.addEventListener('click', (event) => {
|
||||
// We don't apply this to labels and inputs because it would break
|
||||
// checkboxes. Such a global event handler is probably not a good idea
|
||||
// anyway but keeping it for now, as it doesn't seem to break anything else.
|
||||
// https://github.com/facebook/react/issues/13477#issuecomment-489274045
|
||||
if (['LABEL', 'INPUT'].includes(event.target.nodeName)) return;
|
||||
|
||||
event.preventDefault();
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
const logger = new Logger();
|
||||
Logger.initializeGlobalLogger(logger);
|
||||
initLib(logger);
|
||||
const logger = new Logger();
|
||||
Logger.initializeGlobalLogger(logger);
|
||||
initLib(logger);
|
||||
|
||||
app().start(bridge().processArgv()).then((result) => {
|
||||
if (!result || !result.action) {
|
||||
const startResult = await app().start(bridge().processArgv());
|
||||
|
||||
if (!startResult || !startResult.action) {
|
||||
require('./gui/Root');
|
||||
} else if (result.action === 'upgradeSyncTarget') {
|
||||
} else if (startResult.action === 'upgradeSyncTarget') {
|
||||
require('./gui/Root_UpgradeSyncTarget');
|
||||
}
|
||||
}).catch((error) => {
|
||||
const env = bridge().env();
|
||||
};
|
||||
|
||||
main().catch((error) => {
|
||||
const env = bridge().env();
|
||||
console.error(error);
|
||||
|
||||
let errorMessage;
|
||||
if (error.code === 'flagError') {
|
||||
bridge().showErrorMessageBox(error.message);
|
||||
errorMessage = error.message;
|
||||
} else {
|
||||
// If something goes wrong at this stage we don't have a console or a log file
|
||||
// so display the error in a message box.
|
||||
@ -150,13 +155,12 @@ app().start(bridge().processArgv()).then((result) => {
|
||||
if (error.lineNumber) msg.push(error.lineNumber);
|
||||
if (error.stack) msg.push(error.stack);
|
||||
|
||||
if (env === 'dev') {
|
||||
console.error(error);
|
||||
} else {
|
||||
bridge().showErrorMessageBox(msg.join('\n\n'));
|
||||
}
|
||||
errorMessage = msg.join('\n\n');
|
||||
}
|
||||
|
||||
// In dev, we leave the app open as debug statements in the console can be useful
|
||||
if (env !== 'dev') bridge().electronApp().exit(1);
|
||||
// In dev, we give the option to leave the app open as debug statements in the
|
||||
// console can be useful
|
||||
const canIgnore = env === 'dev';
|
||||
bridge().electronApp().handleAppFailure(errorMessage, canIgnore);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user