2018-07-21 14:55:24 +08:00
|
|
|
const optionService = require('./options');
|
|
|
|
const passwordEncryptionService = require('./password_encryption');
|
|
|
|
const myScryptService = require('./my_scrypt');
|
|
|
|
const appInfo = require('./app_info');
|
|
|
|
const utils = require('./utils');
|
2019-11-03 18:43:04 +08:00
|
|
|
const log = require('./log');
|
2018-07-21 14:55:24 +08:00
|
|
|
const dateUtils = require('./date_utils');
|
2019-11-19 06:01:31 +08:00
|
|
|
const keyboardActions = require('./keyboard_actions');
|
2018-07-21 14:55:24 +08:00
|
|
|
|
2018-07-24 03:15:32 +08:00
|
|
|
async function initDocumentOptions() {
|
2018-07-21 14:55:24 +08:00
|
|
|
await optionService.createOption('documentId', utils.randomSecureToken(16), false);
|
|
|
|
await optionService.createOption('documentSecret', utils.randomSecureToken(16), false);
|
2018-07-24 03:15:32 +08:00
|
|
|
}
|
2018-07-21 14:55:24 +08:00
|
|
|
|
2018-07-24 03:15:32 +08:00
|
|
|
async function initSyncedOptions(username, password) {
|
2018-08-18 00:11:03 +08:00
|
|
|
await optionService.createOption('username', username, true);
|
2018-07-21 14:55:24 +08:00
|
|
|
|
2018-08-18 00:11:03 +08:00
|
|
|
await optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true);
|
|
|
|
await optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true);
|
2018-07-21 14:55:24 +08:00
|
|
|
|
2018-08-18 00:11:03 +08:00
|
|
|
const passwordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(password), true);
|
|
|
|
await optionService.createOption('passwordVerificationHash', passwordVerificationKey, true);
|
2018-07-21 14:55:24 +08:00
|
|
|
|
|
|
|
// passwordEncryptionService expects these options to already exist
|
2018-08-18 00:11:03 +08:00
|
|
|
await optionService.createOption('encryptedDataKey', '', true);
|
2018-07-21 14:55:24 +08:00
|
|
|
|
2018-08-18 00:11:03 +08:00
|
|
|
await passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true);
|
2018-07-24 03:15:32 +08:00
|
|
|
}
|
|
|
|
|
2019-08-11 16:28:49 +08:00
|
|
|
async function initNotSyncedOptions(initialized, startNotePath = 'root', opts = {}) {
|
2019-05-11 03:43:40 +08:00
|
|
|
await optionService.createOption('openTabs', JSON.stringify([
|
|
|
|
{
|
|
|
|
notePath: startNotePath,
|
2019-08-30 04:32:53 +08:00
|
|
|
active: true,
|
|
|
|
sidebar: {
|
|
|
|
widgets: []
|
|
|
|
}
|
2019-05-11 03:43:40 +08:00
|
|
|
}
|
|
|
|
]), false);
|
2019-11-03 17:43:40 +08:00
|
|
|
|
2019-03-14 05:43:59 +08:00
|
|
|
await optionService.createOption('lastDailyBackupDate', dateUtils.utcNowDateTime(), false);
|
|
|
|
await optionService.createOption('lastWeeklyBackupDate', dateUtils.utcNowDateTime(), false);
|
|
|
|
await optionService.createOption('lastMonthlyBackupDate', dateUtils.utcNowDateTime(), false);
|
2018-07-24 03:15:32 +08:00
|
|
|
await optionService.createOption('dbVersion', appInfo.dbVersion, false);
|
|
|
|
|
2019-11-03 17:43:40 +08:00
|
|
|
await optionService.createOption('initialized', initialized ? 'true' : 'false', false);
|
|
|
|
|
|
|
|
await optionService.createOption('lastSyncedPull', '0', false);
|
|
|
|
await optionService.createOption('lastSyncedPush', '0', false);
|
2018-07-24 03:15:32 +08:00
|
|
|
|
2019-08-11 16:28:49 +08:00
|
|
|
await optionService.createOption('theme', opts.theme || 'white', false);
|
2018-07-23 04:21:16 +08:00
|
|
|
|
2019-08-11 16:28:49 +08:00
|
|
|
await optionService.createOption('syncServerHost', opts.syncServerHost || '', false);
|
2019-11-03 17:43:40 +08:00
|
|
|
await optionService.createOption('syncServerTimeout', '5000', false);
|
2019-08-11 16:28:49 +08:00
|
|
|
await optionService.createOption('syncProxy', opts.syncProxy || '', false);
|
2019-11-03 17:43:40 +08:00
|
|
|
}
|
2018-07-24 14:12:36 +08:00
|
|
|
|
2019-11-03 17:43:40 +08:00
|
|
|
const defaultOptions = [
|
2019-11-17 00:03:18 +08:00
|
|
|
{ name: 'noteRevisionSnapshotTimeInterval', value: '600', isSynced: true },
|
|
|
|
{ name: 'protectedSessionTimeout', value: '600', isSynced: true },
|
2019-11-03 17:43:40 +08:00
|
|
|
{ name: 'hoistedNoteId', value: 'root', isSynced: false },
|
|
|
|
{ name: 'zoomFactor', value: '1.0', isSynced: false },
|
|
|
|
{ name: 'mainFontSize', value: '100', isSynced: false },
|
|
|
|
{ name: 'treeFontSize', value: '100', isSynced: false },
|
|
|
|
{ name: 'detailFontSize', value: '110', isSynced: false },
|
|
|
|
{ name: 'calendarWidget', value: '{"enabled":true,"expanded":true,"position":20}', isSynced: false },
|
|
|
|
{ name: 'editedNotesWidget', value: '{"enabled":true,"expanded":true,"position":50}', isSynced: false },
|
|
|
|
{ name: 'noteInfoWidget', value: '{"enabled":true,"expanded":true,"position":100}', isSynced: false },
|
|
|
|
{ name: 'attributesWidget', value: '{"enabled":true,"expanded":true,"position":200}', isSynced: false },
|
|
|
|
{ name: 'linkMapWidget', value: '{"enabled":true,"expanded":true,"position":300}', isSynced: false },
|
|
|
|
{ name: 'noteRevisionsWidget', value: '{"enabled":true,"expanded":true,"position":400}', isSynced: false },
|
|
|
|
{ name: 'whatLinksHereWidget', value: '{"enabled":false,"expanded":true,"position":500}', isSynced: false },
|
|
|
|
{ name: 'similarNotesWidget', value: '{"enabled":true,"expanded":true,"position":600}', isSynced: false },
|
|
|
|
{ name: 'spellCheckEnabled', value: 'true', isSynced: false },
|
|
|
|
{ name: 'spellCheckLanguageCode', value: 'en-US', isSynced: false },
|
2019-11-03 18:43:04 +08:00
|
|
|
{ name: 'imageMaxWidthHeight', value: '1200', isSynced: true },
|
2019-11-10 18:25:41 +08:00
|
|
|
{ name: 'imageJpegQuality', value: '75', isSynced: true },
|
2019-12-08 16:12:42 +08:00
|
|
|
{ name: 'autoFixConsistencyIssues', value: 'true', isSynced: false },
|
2019-12-24 03:34:29 +08:00
|
|
|
{ name: 'codeNotesMimeTypes', value: '["text/x-csrc","text/x-c++src","text/x-csharp","text/css","text/x-go","text/x-groovy","text/x-haskell","text/html","message/http","text/x-java","application/javascript;env=frontend","application/javascript;env=backend","application/json","text/x-kotlin","text/x-markdown","text/x-perl","text/x-php","text/x-python","text/x-ruby",null,"text/x-sql","text/x-swift","text/xml","text/x-yaml"]', isSynced: true },
|
|
|
|
{ name: 'leftPaneWidth', value: '25', isSynced: false },
|
|
|
|
{ name: 'rightPaneWidth', value: '25', isSynced: false },
|
2019-12-24 19:10:32 +08:00
|
|
|
{ name: 'rightPaneVisible', value: 'true', isSynced: false },
|
2020-01-04 05:32:49 +08:00
|
|
|
{ name: 'nativeTitleBarVisible', value: 'false', isSynced: false },
|
|
|
|
{ name: 'eraseNotesAfterTimeInSeconds', value: '604800', isSynced: true } // default is 7 days
|
2019-11-03 17:43:40 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
async function initStartupOptions() {
|
|
|
|
const optionsMap = await optionService.getOptionsMap();
|
|
|
|
|
2019-11-19 06:01:31 +08:00
|
|
|
const allDefaultOptions = defaultOptions.concat(getKeyboardDefaultOptions());
|
|
|
|
|
|
|
|
for (const {name, value, isSynced} of allDefaultOptions) {
|
2019-11-03 17:43:40 +08:00
|
|
|
if (!(name in optionsMap)) {
|
|
|
|
await optionService.createOption(name, value, isSynced);
|
2019-11-03 18:43:04 +08:00
|
|
|
|
|
|
|
log.info(`Created missing option "${name}" with default value "${value}"`);
|
2019-11-03 17:43:40 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-21 14:55:24 +08:00
|
|
|
}
|
|
|
|
|
2019-11-19 06:01:31 +08:00
|
|
|
function getKeyboardDefaultOptions() {
|
2019-11-22 04:12:07 +08:00
|
|
|
return keyboardActions.DEFAULT_KEYBOARD_ACTIONS
|
|
|
|
.filter(ka => !!ka.actionName)
|
|
|
|
.map(ka => {
|
|
|
|
return {
|
|
|
|
name: "keyboardShortcuts" + ka.actionName,
|
|
|
|
value: JSON.stringify(ka.defaultShortcuts),
|
|
|
|
isSynced: false
|
|
|
|
};
|
|
|
|
});
|
2019-11-19 06:01:31 +08:00
|
|
|
}
|
|
|
|
|
2018-07-21 14:55:24 +08:00
|
|
|
module.exports = {
|
2018-07-24 03:15:32 +08:00
|
|
|
initDocumentOptions,
|
|
|
|
initSyncedOptions,
|
2019-11-03 17:43:40 +08:00
|
|
|
initNotSyncedOptions,
|
|
|
|
initStartupOptions
|
2018-07-21 14:55:24 +08:00
|
|
|
};
|