1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/ReactNativeClient/lib/BaseApplication.ts

842 lines
27 KiB
TypeScript
Raw Normal View History

import Setting from 'lib/models/Setting';
import Logger, { TargetType } from 'lib/Logger';
import shim from 'lib/shim';
import BaseService from 'lib/services/BaseService';
import reducer from 'lib/reducer';
import KeychainServiceDriver from 'lib/services/keychain/KeychainServiceDriver.node';
import { _, setLocale } from 'lib/locale';
const { createStore, applyMiddleware } = require('redux');
const { defaultState, stateUtils } = require('lib/reducer');
const { JoplinDatabase } = require('lib/joplin-database.js');
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
const { DatabaseDriverNode } = require('lib/database-driver-node.js');
const BaseModel = require('lib/BaseModel.js');
const Folder = require('lib/models/Folder.js');
const BaseItem = require('lib/models/BaseItem.js');
const Note = require('lib/models/Note.js');
const Tag = require('lib/models/Tag.js');
const { splitCommandString } = require('lib/string-utils.js');
const { reg } = require('lib/registry.js');
const { time } = require('lib/time-utils.js');
const BaseSyncTarget = require('lib/BaseSyncTarget.js');
const reduxSharedMiddleware = require('lib/components/shared/reduxSharedMiddleware');
const os = require('os');
const fs = require('fs-extra');
const JoplinError = require('lib/JoplinError');
const EventEmitter = require('events');
const syswidecas = require('syswide-cas');
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
const SyncTargetFilesystem = require('lib/SyncTargetFilesystem.js');
const SyncTargetOneDrive = require('lib/SyncTargetOneDrive.js');
const SyncTargetNextcloud = require('lib/SyncTargetNextcloud.js');
const SyncTargetWebDAV = require('lib/SyncTargetWebDAV.js');
2018-03-26 19:33:55 +02:00
const SyncTargetDropbox = require('lib/SyncTargetDropbox.js');
const SyncTargetAmazonS3 = require('lib/SyncTargetAmazonS3.js');
const EncryptionService = require('lib/services/EncryptionService');
2018-10-08 20:11:53 +02:00
const ResourceFetcher = require('lib/services/ResourceFetcher');
const SearchEngineUtils = require('lib/services/searchengine/SearchEngineUtils');
const SearchEngine = require('lib/services/searchengine/SearchEngine');
const RevisionService = require('lib/services/RevisionService');
const ResourceService = require('lib/services/RevisionService');
const DecryptionWorker = require('lib/services/DecryptionWorker');
const { loadKeychainServiceAndSettings } = require('lib/services/SettingUtils');
const KvStore = require('lib/services/KvStore');
const MigrationService = require('lib/services/MigrationService');
const { toSystemSlashes } = require('lib/path-utils.js');
const { setAutoFreeze } = require('immer');
2020-09-12 00:57:06 +02:00
// const ntpClient = require('lib/vendor/ntp-client');
// ntpClient.dgram = require('dgram');
2020-09-09 01:34:27 +02:00
export default class BaseApplication {
private logger_:Logger;
private dbLogger_:Logger;
private eventEmitter_:any;
private scheduleAutoAddResourcesIID_:any = null;
private database_:any = null;
protected showStackTraces_:boolean = false;
protected showPromptString_:boolean = false;
// Note: this is basically a cache of state.selectedFolderId. It should *only*
// be derived from the state and not set directly since that would make the
// state and UI out of sync.
private currentFolder_:any = null;
protected store_:any = null;
constructor() {
this.logger_ = new Logger();
this.dbLogger_ = new Logger();
this.eventEmitter_ = new EventEmitter();
this.decryptionWorker_resourceMetadataButNotBlobDecrypted = this.decryptionWorker_resourceMetadataButNotBlobDecrypted.bind(this);
}
async destroy() {
if (this.scheduleAutoAddResourcesIID_) {
shim.clearTimeout(this.scheduleAutoAddResourcesIID_);
this.scheduleAutoAddResourcesIID_ = null;
}
await ResourceFetcher.instance().destroy();
await SearchEngine.instance().destroy();
await DecryptionWorker.instance().destroy();
await FoldersScreenUtils.cancelTimers();
await BaseItem.revisionService_.cancelTimers();
await ResourceService.instance().cancelTimers();
await reg.cancelTimers();
this.eventEmitter_.removeAllListeners();
KvStore.instance_ = null;
BaseModel.setDb(null);
reg.setDb(null);
BaseItem.revisionService_ = null;
RevisionService.instance_ = null;
ResourceService.instance_ = null;
ResourceService.isRunningInBackground = false;
ResourceFetcher.instance_ = null;
EncryptionService.instance_ = null;
DecryptionWorker.instance_ = null;
this.logger_.info('Base application terminated...');
this.logger_ = null;
this.dbLogger_ = null;
this.eventEmitter_ = null;
this.decryptionWorker_resourceMetadataButNotBlobDecrypted = null;
}
logger() {
return this.logger_;
}
public store() {
return this.store_;
}
currentFolder() {
return this.currentFolder_;
}
async refreshCurrentFolder() {
let newFolder = null;
if (this.currentFolder_) newFolder = await Folder.load(this.currentFolder_.id);
if (!newFolder) newFolder = await Folder.defaultFolder();
this.switchCurrentFolder(newFolder);
}
switchCurrentFolder(folder:any) {
2017-12-07 20:12:46 +02:00
if (!this.hasGui()) {
this.currentFolder_ = Object.assign({}, folder);
Setting.setValue('activeFolderId', folder ? folder.id : '');
2017-12-07 20:12:46 +02:00
} else {
this.dispatch({
type: 'FOLDER_SELECT',
id: folder ? folder.id : '',
2017-12-07 20:12:46 +02:00
});
}
}
// Handles the initial flags passed to main script and
// returns the remaining args.
async handleStartFlags_(argv:string[], setDefaults:boolean = true) {
const matched:any = {};
argv = argv.slice(0);
argv.splice(0, 2); // First arguments are the node executable, and the node JS file
while (argv.length) {
const arg = argv[0];
const nextArg = argv.length >= 2 ? argv[1] : null;
if (arg == '--profile') {
if (!nextArg) throw new JoplinError(_('Usage: %s', '--profile <dir-path>'), 'flagError');
matched.profileDir = nextArg;
argv.splice(0, 2);
continue;
}
if (arg == '--no-welcome') {
matched.welcomeDisabled = true;
argv.splice(0, 1);
continue;
}
if (arg == '--env') {
if (!nextArg) throw new JoplinError(_('Usage: %s', '--env <dev|prod>'), 'flagError');
matched.env = nextArg;
argv.splice(0, 2);
continue;
}
if (arg == '--is-demo') {
Setting.setConstant('isDemo', true);
argv.splice(0, 1);
continue;
}
if (arg == '--open-dev-tools') {
2019-12-17 19:06:55 +02:00
Setting.setConstant('flagOpenDevTools', true);
argv.splice(0, 1);
continue;
}
if (arg == '--debug') {
// Currently only handled by ElectronAppWrapper (isDebugMode property)
argv.splice(0, 1);
continue;
}
if (arg == '--update-geolocation-disabled') {
Note.updateGeolocationEnabled_ = false;
argv.splice(0, 1);
continue;
}
if (arg == '--stack-trace-enabled') {
this.showStackTraces_ = true;
argv.splice(0, 1);
continue;
}
if (arg == '--log-level') {
if (!nextArg) throw new JoplinError(_('Usage: %s', '--log-level <none|error|warn|info|debug>'), 'flagError');
matched.logLevel = Logger.levelStringToId(nextArg);
argv.splice(0, 2);
continue;
}
if (arg.indexOf('-psn') === 0) {
// Some weird flag passed by macOS - can be ignored.
// https://github.com/laurent22/joplin/issues/480
// https://stackoverflow.com/questions/10242115
argv.splice(0, 1);
continue;
}
if (arg === '--enable-logging') {
// Electron-specific flag used for debugging - ignore it
argv.splice(0, 1);
continue;
}
if (arg === '--dev-plugins') {
Setting.setConstant('startupDevPlugins', nextArg.split(',').map(p => p.trim()));
argv.splice(0, 2);
continue;
}
if (arg.indexOf('--remote-debugging-port=') === 0) {
// Electron-specific flag used for debugging - ignore it. Electron expects this flag in '--x=y' form, a single string.
argv.splice(0, 1);
continue;
}
if (arg === '--no-sandbox') {
// Electron-specific flag for running the app without chrome-sandbox
// Allows users to use it as a workaround for the electron+AppImage issue
// https://github.com/laurent22/joplin/issues/2246
argv.splice(0, 1);
continue;
}
if (arg.length && arg[0] == '-') {
throw new JoplinError(_('Unknown flag: %s', arg), 'flagError');
} else {
break;
}
}
if (setDefaults) {
if (!matched.logLevel) matched.logLevel = Logger.LEVEL_INFO;
if (!matched.env) matched.env = 'prod';
if (!matched.devPlugins) matched.devPlugins = [];
}
return {
matched: matched,
argv: argv,
};
}
on(eventName:string, callback:Function) {
return this.eventEmitter_.on(eventName, callback);
}
async exit(code = 0) {
await Setting.saveAll();
process.exit(code);
}
async refreshNotes(state:any, useSelectedNoteId:boolean = false, noteHash:string = '') {
let parentType = state.notesParentType;
let parentId = null;
if (parentType === 'Folder') {
parentId = state.selectedFolderId;
parentType = BaseModel.TYPE_FOLDER;
} else if (parentType === 'Tag') {
parentId = state.selectedTagId;
parentType = BaseModel.TYPE_TAG;
} else if (parentType === 'Search') {
parentId = state.selectedSearchId;
parentType = BaseModel.TYPE_SEARCH;
} else if (parentType === 'SmartFilter') {
parentId = state.selectedSmartFilterId;
parentType = BaseModel.TYPE_SMART_FILTER;
}
this.logger().debug('Refreshing notes:', parentType, parentId);
const options = {
order: stateUtils.notesOrder(state.settings),
uncompletedTodosOnTop: Setting.value('uncompletedTodosOnTop'),
showCompletedTodos: Setting.value('showCompletedTodos'),
caseInsensitive: true,
};
const source = JSON.stringify({
options: options,
parentId: parentId,
});
let notes = [];
2020-09-06 14:07:00 +02:00
let highlightedWords = [];
if (parentId) {
if (parentType === Folder.modelType()) {
notes = await Note.previews(parentId, options);
} else if (parentType === Tag.modelType()) {
notes = await Tag.notes(parentId, options);
} else if (parentType === BaseModel.TYPE_SEARCH) {
const search = BaseModel.byId(state.searches, parentId);
2020-09-15 15:01:07 +02:00
notes = await SearchEngineUtils.notesForQuery(search.query_pattern);
const parsedQuery = await SearchEngine.instance().parseQuery(search.query_pattern);
2020-09-06 14:07:00 +02:00
highlightedWords = SearchEngine.instance().allParsedQueryTerms(parsedQuery);
} else if (parentType === BaseModel.TYPE_SMART_FILTER) {
notes = await Note.previews(parentId, options);
}
}
this.store().dispatch({
type: 'SET_HIGHLIGHTED',
words: highlightedWords,
});
2020-09-06 14:07:00 +02:00
this.store().dispatch({
type: 'NOTE_UPDATE_ALL',
notes: notes,
notesSource: source,
});
if (useSelectedNoteId) {
this.store().dispatch({
type: 'NOTE_SELECT',
id: state.selectedNoteIds && state.selectedNoteIds.length ? state.selectedNoteIds[0] : null,
hash: noteHash,
});
} else {
const lastSelectedNoteIds = stateUtils.lastSelectedNoteIds(state);
const foundIds = [];
for (let i = 0; i < lastSelectedNoteIds.length; i++) {
const noteId = lastSelectedNoteIds[i];
let found = false;
for (let j = 0; j < notes.length; j++) {
if (notes[j].id === noteId) {
found = true;
break;
}
}
if (found) foundIds.push(noteId);
}
let selectedNoteId = null;
if (foundIds.length) {
selectedNoteId = foundIds[0];
} else {
selectedNoteId = notes.length ? notes[0].id : null;
}
this.store().dispatch({
type: 'NOTE_SELECT',
id: selectedNoteId,
});
}
}
resourceFetcher_downloadComplete(event:any) {
if (event.encrypted) {
DecryptionWorker.instance().scheduleStart();
}
}
async decryptionWorker_resourceMetadataButNotBlobDecrypted() {
ResourceFetcher.instance().scheduleAutoAddResources();
}
reducerActionToString(action:any) {
const o = [action.type];
if ('id' in action) o.push(action.id);
if ('noteId' in action) o.push(action.noteId);
if ('folderId' in action) o.push(action.folderId);
if ('tagId' in action) o.push(action.tagId);
if ('tag' in action) o.push(action.tag.id);
if ('folder' in action) o.push(action.folder.id);
if ('notesSource' in action) o.push(JSON.stringify(action.notesSource));
return o.join(', ');
}
hasGui() {
return false;
}
2017-12-07 20:12:46 +02:00
uiType() {
return this.hasGui() ? 'gui' : 'cli';
2017-12-07 20:12:46 +02:00
}
generalMiddlewareFn() {
const middleware = (store:any) => (next:any) => (action:any) => {
return this.generalMiddleware(store, next, action);
2019-07-29 15:43:53 +02:00
};
return middleware;
}
async applySettingsSideEffects(action:any = null) {
const sideEffects:any = {
'dateFormat': async () => {
time.setLocale(Setting.value('locale'));
time.setDateFormat(Setting.value('dateFormat'));
time.setTimeFormat(Setting.value('timeFormat'));
},
'net.ignoreTlsErrors': async () => {
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = Setting.value('net.ignoreTlsErrors') ? '0' : '1';
},
'net.customCertificates': async () => {
const caPaths = Setting.value('net.customCertificates').split(',');
for (let i = 0; i < caPaths.length; i++) {
const f = caPaths[i].trim();
if (!f) continue;
syswidecas.addCAs(f);
}
},
'encryption.enabled': async () => {
if (this.hasGui()) {
await EncryptionService.instance().loadMasterKeysFromSettings();
DecryptionWorker.instance().scheduleStart();
const loadedMasterKeyIds = EncryptionService.instance().loadedMasterKeyIds();
this.dispatch({
type: 'MASTERKEY_REMOVE_NOT_LOADED',
ids: loadedMasterKeyIds,
});
// Schedule a sync operation so that items that need to be encrypted
// are sent to sync target.
reg.scheduleSync();
}
},
'sync.interval': async () => {
if (this.hasGui()) reg.setupRecurrentSync();
},
};
sideEffects['timeFormat'] = sideEffects['dateFormat'];
sideEffects['locale'] = sideEffects['dateFormat'];
2019-09-06 19:33:30 +02:00
sideEffects['encryption.activeMasterKeyId'] = sideEffects['encryption.enabled'];
sideEffects['encryption.passwordCache'] = sideEffects['encryption.enabled'];
if (action) {
const effect = sideEffects[action.key];
if (effect) await effect();
} else {
for (const key in sideEffects) {
await sideEffects[key]();
}
}
}
async generalMiddleware(store:any, next:any, action:any) {
// this.logger().debug('Reducer action', this.reducerActionToString(action));
const result = next(action);
const newState = store.getState();
let refreshNotes = false;
let refreshFolders:boolean | string = false;
// let refreshTags = false;
let refreshNotesUseSelectedNoteId = false;
let refreshNotesHash = '';
await reduxSharedMiddleware(store, next, action);
2019-07-29 15:43:53 +02:00
if (this.hasGui() && ['NOTE_UPDATE_ONE', 'NOTE_DELETE', 'FOLDER_UPDATE_ONE', 'FOLDER_DELETE'].indexOf(action.type) >= 0) {
if (!(await reg.syncTarget().syncStarted())) reg.scheduleSync(30 * 1000, { syncSteps: ['update_remote', 'delete_remote'] });
SearchEngine.instance().scheduleSyncTables();
}
// Don't add FOLDER_UPDATE_ALL as refreshFolders() is calling it too, which
// would cause the sidebar to refresh all the time.
2019-07-29 15:43:53 +02:00
if (this.hasGui() && ['FOLDER_UPDATE_ONE'].indexOf(action.type) >= 0) {
refreshFolders = true;
}
if (action.type == 'HISTORY_BACKWARD' || action.type == 'HISTORY_FORWARD') {
refreshNotes = true;
refreshNotesUseSelectedNoteId = true;
}
if (action.type == 'HISTORY_BACKWARD' || action.type == 'HISTORY_FORWARD' || action.type == 'FOLDER_SELECT' || action.type === 'FOLDER_DELETE' || action.type === 'FOLDER_AND_NOTE_SELECT' || (action.type === 'SEARCH_UPDATE' && newState.notesParentType === 'Folder')) {
Setting.setValue('activeFolderId', newState.selectedFolderId);
this.currentFolder_ = newState.selectedFolderId ? await Folder.load(newState.selectedFolderId) : null;
refreshNotes = true;
if (action.type === 'FOLDER_AND_NOTE_SELECT') {
refreshNotesUseSelectedNoteId = true;
refreshNotesHash = action.hash;
}
}
if (this.hasGui() && (action.type == 'NOTE_IS_INSERTING_NOTES' && !action.value)) {
refreshNotes = true;
}
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'uncompletedTodosOnTop') || action.type == 'SETTING_UPDATE_ALL')) {
refreshNotes = true;
}
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'showCompletedTodos') || action.type == 'SETTING_UPDATE_ALL')) {
refreshNotes = true;
}
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key.indexOf('notes.sortOrder') === 0) || action.type == 'SETTING_UPDATE_ALL')) {
refreshNotes = true;
}
if (action.type == 'SMART_FILTER_SELECT') {
refreshNotes = true;
refreshNotesUseSelectedNoteId = true;
}
// Should refresh the notes when:
// - A tag is selected, to show the notes for that tag
// - When a tag is updated so that when searching by tags, the search results are updated
// https://github.com/laurent22/joplin/issues/3754
if (['TAG_SELECT', 'TAG_DELETE', 'TAG_UPDATE_ONE', 'NOTE_TAG_REMOVE'].includes(action.type)) {
refreshNotes = true;
}
if (action.type == 'SEARCH_SELECT' || action.type === 'SEARCH_DELETE') {
refreshNotes = true;
}
if (action.type == 'NOTE_TAG_REMOVE') {
if (newState.notesParentType === 'Tag' && newState.selectedTagId === action.item.id) {
if (newState.notes.length === newState.selectedNoteIds.length) {
await this.refreshCurrentFolder();
refreshNotesUseSelectedNoteId = true;
}
refreshNotes = true;
}
}
if (refreshNotes) {
await this.refreshNotes(newState, refreshNotesUseSelectedNoteId, refreshNotesHash);
2017-11-12 02:44:26 +02:00
}
if (action.type === 'NOTE_UPDATE_ONE' || action.type === 'NOTE_DELETE') {
refreshFolders = true;
}
if (this.hasGui() && action.type == 'SETTING_UPDATE_ALL') {
refreshFolders = 'now';
}
if (this.hasGui() && action.type == 'SETTING_UPDATE_ONE' && (
action.key.indexOf('folders.sortOrder') === 0 ||
action.key == 'showNoteCounts' ||
action.key == 'showCompletedTodos')) {
refreshFolders = 'now';
}
if (this.hasGui() && action.type === 'SYNC_GOT_ENCRYPTED_ITEM') {
DecryptionWorker.instance().scheduleStart();
}
if (this.hasGui() && action.type === 'SYNC_CREATED_OR_UPDATED_RESOURCE') {
ResourceFetcher.instance().autoAddResources();
2018-10-08 20:11:53 +02:00
}
if (action.type == 'SETTING_UPDATE_ONE') {
await this.applySettingsSideEffects(action);
} else if (action.type == 'SETTING_UPDATE_ALL') {
await this.applySettingsSideEffects();
}
if (refreshFolders) {
if (refreshFolders === 'now') {
await FoldersScreenUtils.refreshFolders();
} else {
await FoldersScreenUtils.scheduleRefreshFolders();
}
}
2019-07-29 15:43:53 +02:00
return result;
}
dispatch(action:any) {
if (this.store()) return this.store().dispatch(action);
}
reducer(state:any = defaultState, action:any) {
return reducer(state, action);
}
initRedux() {
this.store_ = createStore(this.reducer, applyMiddleware(this.generalMiddlewareFn()));
BaseModel.dispatch = this.store().dispatch;
FoldersScreenUtils.dispatch = this.store().dispatch;
2017-11-06 23:11:15 +02:00
reg.dispatch = this.store().dispatch;
BaseSyncTarget.dispatch = this.store().dispatch;
DecryptionWorker.instance().dispatch = this.store().dispatch;
ResourceFetcher.instance().dispatch = this.store().dispatch;
}
deinitRedux() {
this.store_ = null;
BaseModel.dispatch = function() {};
FoldersScreenUtils.dispatch = function() {};
reg.dispatch = function() {};
BaseSyncTarget.dispatch = function() {};
DecryptionWorker.instance().dispatch = function() {};
ResourceFetcher.instance().dispatch = function() {};
}
async readFlagsFromFile(flagPath:string) {
if (!fs.existsSync(flagPath)) return {};
let flagContent = fs.readFileSync(flagPath, 'utf8');
if (!flagContent) return {};
flagContent = flagContent.trim();
let flags = splitCommandString(flagContent);
flags.splice(0, 0, 'cmd');
flags.splice(0, 0, 'node');
flags = await this.handleStartFlags_(flags, false);
return flags.matched;
}
determineProfileDir(initArgs:any) {
let output = '';
if (initArgs.profileDir) {
output = initArgs.profileDir;
} else if (process && process.env && process.env.PORTABLE_EXECUTABLE_DIR) {
output = `${process.env.PORTABLE_EXECUTABLE_DIR}/JoplinProfile`;
} else {
output = `${os.homedir()}/.config/${Setting.value('appName')}`;
}
return toSystemSlashes(output, 'linux');
}
async start(argv:string[]):Promise<any> {
const startFlags = await this.handleStartFlags_(argv);
argv = startFlags.argv;
let initArgs = startFlags.matched;
if (argv.length) this.showPromptString_ = false;
let appName = initArgs.env == 'dev' ? 'joplindev' : 'joplin';
if (Setting.value('appId').indexOf('-desktop') >= 0) appName += '-desktop';
Setting.setConstant('appName', appName);
// https://immerjs.github.io/immer/docs/freezing
setAutoFreeze(initArgs.env === 'dev');
const profileDir = this.determineProfileDir(initArgs);
const resourceDirName = 'resources';
2019-09-19 23:51:18 +02:00
const resourceDir = `${profileDir}/${resourceDirName}`;
const tempDir = `${profileDir}/tmp`;
Setting.setConstant('env', initArgs.env);
Setting.setConstant('profileDir', profileDir);
2019-09-19 23:51:18 +02:00
Setting.setConstant('templateDir', `${profileDir}/templates`);
Setting.setConstant('resourceDirName', resourceDirName);
Setting.setConstant('resourceDir', resourceDir);
Setting.setConstant('tempDir', tempDir);
Setting.setConstant('pluginDir', `${profileDir}/plugins`);
SyncTargetRegistry.addClass(SyncTargetFilesystem);
SyncTargetRegistry.addClass(SyncTargetOneDrive);
SyncTargetRegistry.addClass(SyncTargetNextcloud);
SyncTargetRegistry.addClass(SyncTargetWebDAV);
SyncTargetRegistry.addClass(SyncTargetDropbox);
SyncTargetRegistry.addClass(SyncTargetAmazonS3);
try {
await shim.fsDriver().remove(tempDir);
} catch (error) {
// Can't do anything in this case, not even log, since the logger
// is not yet ready. But normally it's not an issue if the temp
// dir cannot be deleted.
}
await fs.mkdirp(profileDir, 0o755);
await fs.mkdirp(resourceDir, 0o755);
await fs.mkdirp(tempDir, 0o755);
// Clean up any remaining watched files (they start with "edit-")
await shim.fsDriver().removeAllThatStartWith(profileDir, 'edit-');
2019-09-19 23:51:18 +02:00
const extraFlags = await this.readFlagsFromFile(`${profileDir}/flags.txt`);
initArgs = Object.assign(initArgs, extraFlags);
this.logger_.addTarget(TargetType.File, { path: `${profileDir}/log.txt` });
Mobile: Upgraded React Native to v0.63 commit 2fb6cee90174bfcc02f77ba1606bfd8c4e2c8fc8 Merge: 4e303be85f db509955f6 Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 16:24:07 2020 +0100 Merge branch 'dev' into rn_63 commit 4e303be85f7b3162b7e5b96e18557da13acfc988 Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 16:14:39 2020 +0100 Clean up commit e3a37ec2d6f3e6cc07c018b11b3f80ca8256063e Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 15:57:55 2020 +0100 Use different script for pre-commit and manual start commit bd236648fcd92a812cd16369dfa2238d38c6638f Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 15:56:45 2020 +0100 Removed RN eslint config commit e7feda41c9b473cd18768f2ce7686611fa2b3d08 Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 15:27:08 2020 +0100 Revert "Disable git hook for now" This reverts commit 89263ac7425bae5b03b60742ab186441217b37dc. commit cfd63fe46fbc714c065f13dd9add5a0b8e18bf1f Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 13:02:32 2020 +0100 Ask permission to use geo-location commit 66059939a38460ba05c09eed7f3b19fc4ead924c Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 12:26:20 2020 +0100 Fixed WebView race condition commit 1e0d2b7b86d88629f19ae6574f73c945d422d0b5 Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 11:56:21 2020 +0100 Fixed webview issues commit f537d22d7fc4bcf6ddb54a4faadf72f585ae271c Author: Laurent Cozic <laurent@cozic.net> Date: Fri Oct 16 11:08:29 2020 +0100 Improve resource file watching commit eec32cf70aaf69b04a703ce49c3ede48a6ac1067 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 18:40:13 2020 +0100 Removed cache package dependency and implemented one more suitable for React Native commit efa346fea48414c98c1e577bf0d74a6e90a78044 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 14:57:21 2020 +0100 iOS: Added fonts to Info.plist although it was working without it commit 572b647bc0ff5b12ddd555ad7ca2bb18ccaeb512 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 14:56:49 2020 +0100 Specify content-type header for OneDrive to prevent network error commit bcedf6c7f0c35a428fd1c0800d4f17de662a49ff Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 12:45:01 2020 +0100 iOS: Disable long press menu since it is already built-in commit 7359dd61d1a609dbfce87b0deb169b8c5e2ace14 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 12:37:40 2020 +0100 Removed unused react-native-device-info commit 2d63ab36d32775f07236dae62f6cc7792dac435a Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 12:35:54 2020 +0100 iOS: Fixed taking a picture commit 8e2875a91c87b48ba3e230e9296d032cd05a267c Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 12:11:13 2020 +0100 iOS: Restored camera roll functionality commit 75f5edf2addfe3590d1a37bdac99680cb1a5c84c Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 11:40:13 2020 +0100 iOS: Fixed build settings commit b220c984198e78a2401387f4385bfdd331852d78 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 11:40:03 2020 +0100 iOS: Got images to work with WebKit commit c34b43e841b768104f19e86900133a1986b53af9 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 10:24:52 2020 +0100 iOS: Restore more settings commit 32997611e625f1775df05af966782ae763c1aa17 Author: Laurent Cozic <laurent@cozic.net> Date: Thu Oct 15 10:15:14 2020 +0100 iOS: Added back icons and other properties commit b5811d7f7cff227a30bb10ecad76f52cb212170a Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 23:53:14 2020 +0100 Got iOS build to work commit dc6d7c00e0048088cca653d5214d1cc4679ca005 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 18:40:06 2020 +0100 Imported old settings in gradle build commit dff59f560317d260b8540a9324bcdd5e749a0c0b Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 18:20:00 2020 +0100 Restored sharing commit 0bdb449e72ef1766bd5aac878f44106c36e662c2 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 17:25:40 2020 +0100 Updated NoteBodyViewer commit 0c0d228815251cfaf66ba25a276852d32192f106 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 16:54:42 2020 +0100 Fixed networking commit 6ff45ce485d59e3e0fe66a9658a678499c887058 Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 13:11:00 2020 +0100 Fixed document picker commit cc889182b66052b8dfad03b46121e6a14763a51a Author: Laurent Cozic <laurent@cozic.net> Date: Wed Oct 14 12:56:27 2020 +0100 Added back support for alarms commit 040261abfad89e5a58617d4c2d4f811d324ea488 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 22:04:49 2020 +0100 Fixed Clipboard and remove image-picker package commit 1077ad8f16481afcc63d92020e91cd37f077f207 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 21:54:52 2020 +0100 Fixed Select Alarm dialog and PoorManIntervals class commit 8296676fd52878b2f1cc2028a099f31909e6f286 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 21:32:52 2020 +0100 Fixed icons and warnings commit 3b0e3f6f43c83bb103132e8296d3887fccd386b5 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 17:02:59 2020 +0100 Got app to build again commit 89263ac7425bae5b03b60742ab186441217b37dc Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 15:41:17 2020 +0100 Disable git hook for now commit d6da162f674f94ba2c462268e39c161fa6126220 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 15:39:12 2020 +0100 Restored back all RN packages commit 7f8ce3732cf4c8ff6dcbcc0a8918c680adadd3f4 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 15:13:12 2020 +0100 Restored base packages commit ea59726eb3e0414afcdbe8af30a7765875239225 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Oct 13 15:05:17 2020 +0100 Started over from scratch
2020-10-16 17:26:19 +02:00
// this.logger_.addTarget(TargetType.Console, { level: Logger.LEVEL_DEBUG });
this.logger_.setLevel(initArgs.logLevel);
reg.setLogger(this.logger_);
reg.dispatch = () => {};
BaseService.logger_ = this.logger_;
2020-09-12 00:57:06 +02:00
// require('lib/ntpDate').setLogger(reg.logger());
this.dbLogger_.addTarget(TargetType.File, { path: `${profileDir}/log-database.txt` });
this.dbLogger_.setLevel(initArgs.logLevel);
if (Setting.value('appType') === 'desktop') {
this.logger_.addTarget(TargetType.Console, { level: Logger.LEVEL_WARN });
this.dbLogger_.addTarget(TargetType.Console, { level: Logger.LEVEL_WARN });
}
if (Setting.value('env') === 'dev') {
this.dbLogger_.setLevel(Logger.LEVEL_INFO);
}
2019-09-19 23:51:18 +02:00
this.logger_.info(`Profile directory: ${profileDir}`);
this.database_ = new JoplinDatabase(new DatabaseDriverNode());
this.database_.setLogExcludedQueryTypes(['SELECT']);
this.database_.setLogger(this.dbLogger_);
2020-09-06 14:07:00 +02:00
if (Setting.value('env') === 'dev') {
if (shim.isElectron()) {
this.database_.extensionToLoad = './lib/sql-extensions/spellfix';
}
} else {
if (shim.isElectron()) {
if (shim.isWindows()) {
const appDir = process.execPath.substring(0, process.execPath.lastIndexOf('\\'));
this.database_.extensionToLoad = `${appDir}/usr/lib/spellfix`;
} else {
const appDir = process.execPath.substring(0, process.execPath.lastIndexOf('/'));
this.database_.extensionToLoad = `${appDir}/usr/lib/spellfix`;
}
}
}
2019-09-19 23:51:18 +02:00
await this.database_.open({ name: `${profileDir}/database.sqlite` });
// if (Setting.value('env') === 'dev') await this.database_.clearForTesting();
reg.setDb(this.database_);
BaseModel.setDb(this.database_);
await loadKeychainServiceAndSettings(KeychainServiceDriver);
this.logger_.info(`Client ID: ${Setting.value('clientId')}`);
if (Setting.value('firstStart')) {
const locale = shim.detectAndSetLocale(Setting);
2019-09-19 23:51:18 +02:00
reg.logger().info(`First start: detected locale as ${locale}`);
2018-03-26 19:33:55 +02:00
if (Setting.value('env') === 'dev') {
Setting.setValue('showTrayIcon', 0);
Setting.setValue('autoUpdateEnabled', 0);
Setting.setValue('sync.interval', 3600);
}
2018-03-26 19:33:55 +02:00
Setting.setValue('firstStart', 0);
} else {
setLocale(Setting.value('locale'));
}
// if (Setting.value('db.fuzzySearchEnabled') === -1) {
// const fuzzySearchEnabled = await this.database_.fuzzySearchEnabled();
// Setting.setValue('db.fuzzySearchEnabled', fuzzySearchEnabled ? 1 : 0);
// }
// // Always disable on CLI because building and packaging the extension is not working
// // and is too error-prone - requires gcc on the machine, or we should package the .so
// // and dylib files, but it's not sure it would work everywhere if not built from
// // source on the target machine.
// if (Setting.value('appType') !== 'desktop') {
// Setting.setValue('db.fuzzySearchEnabled', 0);
// }
// For now always disable fuzzy search due to performance issues:
// https://discourse.joplinapp.org/t/1-1-4-keyboard-locks-up-while-typing/11231/11
// https://discourse.joplinapp.org/t/serious-lagging-when-there-are-tens-of-thousands-of-notes/11215/23
Setting.setValue('db.fuzzySearchEnabled', 0);
if (Setting.value('encryption.shouldReencrypt') < 0) {
2020-03-14 02:52:28 +02:00
// We suggest re-encryption if the user has at least one notebook
// and if encryption is enabled. This code runs only when shouldReencrypt = -1
// which can be set by a maintenance script for example.
const folderCount = await Folder.count();
const itShould = Setting.value('encryption.enabled') && !!folderCount ? Setting.SHOULD_REENCRYPT_YES : Setting.SHOULD_REENCRYPT_NO;
Setting.setValue('encryption.shouldReencrypt', itShould);
}
if ('welcomeDisabled' in initArgs) Setting.setValue('welcome.enabled', !initArgs.welcomeDisabled);
2018-09-28 20:24:57 +02:00
if (!Setting.value('api.token')) {
2019-07-29 15:43:53 +02:00
EncryptionService.instance()
.randomHexString(64)
.then((token:string) => {
2019-07-29 15:43:53 +02:00
Setting.setValue('api.token', token);
});
2018-09-28 20:24:57 +02:00
}
time.setDateFormat(Setting.value('dateFormat'));
time.setTimeFormat(Setting.value('timeFormat'));
BaseItem.revisionService_ = RevisionService.instance();
KvStore.instance().setDb(reg.db());
EncryptionService.instance().setLogger(this.logger_);
BaseItem.encryptionService_ = EncryptionService.instance();
DecryptionWorker.instance().setLogger(this.logger_);
DecryptionWorker.instance().setEncryptionService(EncryptionService.instance());
DecryptionWorker.instance().setKvStore(KvStore.instance());
await EncryptionService.instance().loadMasterKeysFromSettings();
DecryptionWorker.instance().on('resourceMetadataButNotBlobDecrypted', this.decryptionWorker_resourceMetadataButNotBlobDecrypted);
2019-07-29 15:43:53 +02:00
ResourceFetcher.instance().setFileApi(() => {
return reg.syncTarget().fileApi();
});
2018-10-08 20:11:53 +02:00
ResourceFetcher.instance().setLogger(this.logger_);
ResourceFetcher.instance().on('downloadComplete', this.resourceFetcher_downloadComplete);
2018-10-08 20:11:53 +02:00
ResourceFetcher.instance().start();
SearchEngine.instance().setDb(reg.db());
SearchEngine.instance().setLogger(reg.logger());
SearchEngine.instance().scheduleSyncTables();
const currentFolderId = Setting.value('activeFolderId');
let currentFolder = null;
if (currentFolderId) currentFolder = await Folder.load(currentFolderId);
if (!currentFolder) currentFolder = await Folder.defaultFolder();
Setting.setValue('activeFolderId', currentFolder ? currentFolder.id : '');
await MigrationService.instance().run();
return argv;
}
}