2017-11-05 02:49:23 +02:00
|
|
|
// This is the initialization for the Electron RENDERER process
|
|
|
|
|
2018-01-21 19:01:37 +02:00
|
|
|
// Disable React message in console "Download the React DevTools for a better development experience"
|
|
|
|
// https://stackoverflow.com/questions/42196819/disable-hide-download-the-react-devtools#42196820
|
2019-07-30 09:35:42 +02:00
|
|
|
// eslint-disable-next-line no-undef
|
2018-01-21 19:01:37 +02:00
|
|
|
__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
|
|
|
|
supportsFiber: true,
|
|
|
|
inject: function() {},
|
|
|
|
onCommitFiberRoot: function() {},
|
|
|
|
onCommitFiberUnmount: function() {},
|
|
|
|
};
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const app = require('./app').default;
|
2021-01-22 19:41:11 +02:00
|
|
|
const Folder = require('@joplin/lib/models/Folder').default;
|
|
|
|
const Resource = require('@joplin/lib/models/Resource').default;
|
|
|
|
const BaseItem = require('@joplin/lib/models/BaseItem').default;
|
|
|
|
const Note = require('@joplin/lib/models/Note').default;
|
|
|
|
const Tag = require('@joplin/lib/models/Tag').default;
|
|
|
|
const NoteTag = require('@joplin/lib/models/NoteTag').default;
|
|
|
|
const MasterKey = require('@joplin/lib/models/MasterKey').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const Setting = require('@joplin/lib/models/Setting').default;
|
2021-01-22 19:41:11 +02:00
|
|
|
const Revision = require('@joplin/lib/models/Revision').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const Logger = require('@joplin/lib/Logger').default;
|
|
|
|
const FsDriverNode = require('@joplin/lib/fs-driver-node').default;
|
|
|
|
const shim = require('@joplin/lib/shim').default;
|
|
|
|
const { shimInit } = require('@joplin/lib/shim-init-node.js');
|
2021-08-23 19:47:07 +02:00
|
|
|
const EncryptionService = require('@joplin/lib/services/e2ee/EncryptionService').default;
|
2020-10-09 19:35:46 +02:00
|
|
|
const bridge = require('electron').remote.require('./bridge').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const { FileApiDriverLocal } = require('@joplin/lib/file-api-driver-local.js');
|
2020-11-19 18:38:44 +02:00
|
|
|
const React = require('react');
|
2017-11-05 02:17:48 +02:00
|
|
|
|
2019-12-18 13:49:44 +02:00
|
|
|
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()}`);
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
const fsDriver = new FsDriverNode();
|
|
|
|
Logger.fsDriver_ = fsDriver;
|
|
|
|
Resource.fsDriver_ = fsDriver;
|
2017-12-13 21:01:04 +02:00
|
|
|
EncryptionService.fsDriver_ = fsDriver;
|
2018-01-17 20:51:15 +02:00
|
|
|
FileApiDriverLocal.fsDriver_ = fsDriver;
|
2017-11-05 02:17:48 +02:00
|
|
|
|
|
|
|
// That's not good, but it's to avoid circular dependency issues
|
|
|
|
// in the BaseItem class.
|
2018-03-09 22:59:12 +02:00
|
|
|
BaseItem.loadClass('Note', Note);
|
|
|
|
BaseItem.loadClass('Folder', Folder);
|
|
|
|
BaseItem.loadClass('Resource', Resource);
|
|
|
|
BaseItem.loadClass('Tag', Tag);
|
|
|
|
BaseItem.loadClass('NoteTag', NoteTag);
|
|
|
|
BaseItem.loadClass('MasterKey', MasterKey);
|
2019-05-06 22:35:29 +02:00
|
|
|
BaseItem.loadClass('Revision', Revision);
|
2017-11-05 02:17:48 +02:00
|
|
|
|
2020-06-03 18:07:50 +02:00
|
|
|
Setting.setConstant('appId', `net.cozic.joplin${bridge().env() === 'dev' ? 'dev' : ''}-desktop`);
|
2018-03-09 22:59:12 +02:00
|
|
|
Setting.setConstant('appType', 'desktop');
|
2017-11-05 02:17:48 +02:00
|
|
|
|
2020-06-03 18:07:50 +02:00
|
|
|
console.info(`appId: ${Setting.value('appId')}`);
|
|
|
|
console.info(`appType: ${Setting.value('appType')}`);
|
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
let keytar;
|
|
|
|
try {
|
|
|
|
keytar = shim.platformSupportsKeyChain() ? require('keytar') : null;
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Cannot load keytar - keychain support will be disabled', error);
|
|
|
|
keytar = null;
|
|
|
|
}
|
|
|
|
|
2021-04-07 19:12:37 +02:00
|
|
|
function appVersion() {
|
|
|
|
const p = require('./packageInfo.js');
|
|
|
|
return p.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
shimInit(null, keytar, React, appVersion);
|
2017-12-14 02:23:32 +02:00
|
|
|
|
2017-11-21 21:31:21 +02:00
|
|
|
// Disable drag and drop of links inside application (which would
|
|
|
|
// open it as if the whole app was a browser)
|
2020-05-21 10:14:33 +02:00
|
|
|
document.addEventListener('dragover', event => event.preventDefault());
|
|
|
|
document.addEventListener('drop', event => event.preventDefault());
|
2017-11-22 21:20:19 +02:00
|
|
|
|
2017-11-21 21:31:21 +02:00
|
|
|
// Disable middle-click (which would open a new browser window, but we don't want this)
|
2020-05-21 10:14:33 +02:00
|
|
|
document.addEventListener('auxclick', event => event.preventDefault());
|
2017-11-21 21:31:21 +02:00
|
|
|
|
2017-11-22 21:29:49 +02:00
|
|
|
// 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.
|
2018-03-09 22:59:12 +02:00
|
|
|
document.addEventListener('click', (event) => event.preventDefault());
|
2017-11-22 21:29:49 +02:00
|
|
|
|
2020-08-02 13:28:50 +02:00
|
|
|
app().start(bridge().processArgv()).then((result) => {
|
|
|
|
if (!result || !result.action) {
|
2020-10-09 19:35:46 +02:00
|
|
|
require('./gui/Root');
|
2020-08-02 13:28:50 +02:00
|
|
|
} else if (result.action === 'upgradeSyncTarget') {
|
|
|
|
require('./gui/Root_UpgradeSyncTarget');
|
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
}).catch((error) => {
|
2020-07-03 23:32:39 +02:00
|
|
|
const env = bridge().env();
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (error.code == 'flagError') {
|
|
|
|
bridge().showErrorMessageBox(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.
|
2020-03-14 01:46:14 +02:00
|
|
|
const msg = ['Fatal error:', error.message];
|
2018-03-09 22:59:12 +02:00
|
|
|
if (error.fileName) msg.push(error.fileName);
|
|
|
|
if (error.lineNumber) msg.push(error.lineNumber);
|
|
|
|
if (error.stack) msg.push(error.stack);
|
2020-07-03 23:32:39 +02:00
|
|
|
|
|
|
|
if (env === 'dev') {
|
|
|
|
console.error(error);
|
|
|
|
} else {
|
|
|
|
bridge().showErrorMessageBox(msg.join('\n\n'));
|
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
}
|
2018-03-07 21:11:55 +02:00
|
|
|
|
2020-07-03 23:32:39 +02:00
|
|
|
// In dev, we leave the app open as debug statements in the console can be useful
|
|
|
|
if (env !== 'dev') bridge().electronApp().exit(1);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|