mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/develop' into feature/MFA
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| import optionService from "./options.js"; | ||||
| import type { OptionMap } from "./options.js"; | ||||
| import appInfo from "./app_info.js"; | ||||
| import utils from "./utils.js"; | ||||
| import log from "./log.js"; | ||||
| @@ -11,18 +12,35 @@ function initDocumentOptions() { | ||||
|     optionService.createOption('documentSecret', utils.randomSecureToken(16), false); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Contains additional options to be initialized for a new database, containing the information entered by the user. | ||||
|  */ | ||||
| interface NotSyncedOpts { | ||||
|     syncServerHost?: string; | ||||
|     syncProxy?: string; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Represents a correspondence between an option and its default value, to be initialized when the database is missing that particular option (after a migration from an older version, or when creating a new database). | ||||
|  */ | ||||
| interface DefaultOption { | ||||
|     name: string; | ||||
|     value: string; | ||||
|     /** | ||||
|     * The value to initialize the option with, if the option is not already present in the database. | ||||
|     * | ||||
|     * If a function is passed in instead, the function is called if the option does not exist (with access to the current options) and the return value is used instead. Useful to migrate a new option with a value depending on some other option that might be initialized. | ||||
|     */ | ||||
|     value: string | ((options: OptionMap) => string); | ||||
|     isSynced: boolean; | ||||
| } | ||||
|  | ||||
| async function initNotSyncedOptions(initialized: boolean, theme: string, opts: NotSyncedOpts = {}) { | ||||
| /** | ||||
|  * Initializes the default options for new databases only. | ||||
|  * | ||||
|  * @param initialized `true` if the database has been fully initialized (i.e. a new database was created), or `false` if the database is created for sync. | ||||
|  * @param opts additional options to be initialized, for example the sync configuration. | ||||
|  */ | ||||
| async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) { | ||||
|     optionService.createOption('openNoteContexts', JSON.stringify([ | ||||
|         { | ||||
|             notePath: 'root', | ||||
| @@ -38,17 +56,21 @@ async function initNotSyncedOptions(initialized: boolean, theme: string, opts: N | ||||
|     optionService.createOption('initialized', initialized ? 'true' : 'false', false); | ||||
|  | ||||
|     optionService.createOption('lastSyncedPull', '0', false); | ||||
|     optionService.createOption('lastSyncedPush', '0', false);     | ||||
|     optionService.createOption('lastSyncedPush', '0', false); | ||||
|  | ||||
|     optionService.createOption('theme', 'next', false); | ||||
|  | ||||
|     optionService.createOption('theme', theme, false); | ||||
|      | ||||
|     optionService.createOption('syncServerHost', opts.syncServerHost || '', false); | ||||
|     optionService.createOption('syncServerTimeout', '120000', false); | ||||
|     optionService.createOption('syncProxy', opts.syncProxy || '', false); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Contains all the default options that must be initialized on new and existing databases (at startup). The value can also be determined based on other options, provided they have already been initialized. | ||||
|  */ | ||||
| const defaultOptions: DefaultOption[] = [ | ||||
|     { name: 'revisionSnapshotTimeInterval', value: '600', isSynced: true }, | ||||
|     { name: 'revisionSnapshotNumberLimit', value: '-1', isSynced: true }, | ||||
|     { name: 'protectedSessionTimeout', value: '600', isSynced: true }, | ||||
|     { name: 'zoomFactor', value: process.platform === "win32" ? '0.9' : '1.0', isSynced: false }, | ||||
|     { name: 'overrideThemeFonts', value: 'false', isSynced: false }, | ||||
| @@ -102,9 +124,44 @@ const defaultOptions: DefaultOption[] = [ | ||||
|  | ||||
|     // Internationalization | ||||
|     { name: 'locale', value: 'en', isSynced: true }, | ||||
|     { name: 'firstDayOfWeek', value: '1', isSynced: true } | ||||
|     { name: 'firstDayOfWeek', value: '1', isSynced: true }, | ||||
|  | ||||
|     // Code block configuration | ||||
|     { name: "codeBlockTheme", value: (optionsMap) => { | ||||
|         if (optionsMap.theme === "light") { | ||||
|             return "default:stackoverflow-light"; | ||||
|         } else { | ||||
|             return "default:stackoverflow-dark"; | ||||
|         } | ||||
|     }, isSynced: false }, | ||||
|     { name: "codeBlockWordWrap", value: "false", isSynced: true }, | ||||
|  | ||||
|     // Text note configuration | ||||
|     { name: "textNoteEditorType", value: "ckeditor-balloon", isSynced: true }, | ||||
|     { name: "textNoteEditorMultilineToolbar", value: "false", isSynced: true }, | ||||
|  | ||||
|     // HTML import configuration | ||||
|     { name: "layoutOrientation", value: "vertical", isSynced: false }, | ||||
|     { name: "backgroundEffects", value: "false", isSynced: false }, | ||||
|     { name: "allowedHtmlTags", value: JSON.stringify([ | ||||
|         'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', | ||||
|         'li', 'b', 'i', 'strong', 'em', 'strike', 's', 'del', 'abbr', 'code', 'hr', 'br', 'div', | ||||
|         'table', 'thead', 'caption', 'tbody', 'tfoot', 'tr', 'th', 'td', 'pre', 'section', 'img', | ||||
|         'figure', 'figcaption', 'span', 'label', 'input', 'details', 'summary', 'address', 'aside', 'footer', | ||||
|         'header', 'hgroup', 'main', 'nav', 'dl', 'dt', 'menu', 'bdi', 'bdo', 'dfn', 'kbd', 'mark', 'q', 'time', | ||||
|         'var', 'wbr', 'area', 'map', 'track', 'video', 'audio', 'picture', 'del', 'ins', | ||||
|         'en-media', | ||||
|         'acronym', 'article', 'big', 'button', 'cite', 'col', 'colgroup', 'data', 'dd', | ||||
|         'fieldset', 'form', 'legend', 'meter', 'noscript', 'option', 'progress', 'rp', | ||||
|         'samp', 'small', 'sub', 'sup', 'template', 'textarea', 'tt' | ||||
|     ]), isSynced: true }, | ||||
| ]; | ||||
|  | ||||
| /** | ||||
|  * Initializes the options, by checking which options from {@link #allDefaultOptions()} are missing and registering them. It will also check some environment variables such as safe mode, to make any necessary adjustments. | ||||
|  * | ||||
|  * This method is called regardless of whether a new database is created, or an existing database is used. | ||||
|  */ | ||||
| function initStartupOptions() { | ||||
|     const optionsMap = optionService.getOptionMap(); | ||||
|  | ||||
| @@ -112,9 +169,15 @@ function initStartupOptions() { | ||||
|  | ||||
|     for (const {name, value, isSynced} of allDefaultOptions) { | ||||
|         if (!(name in optionsMap)) { | ||||
|             optionService.createOption(name, value, isSynced); | ||||
|             let resolvedValue; | ||||
|             if (typeof value === "function") { | ||||
|                 resolvedValue = value(optionsMap); | ||||
|             } else { | ||||
|                 resolvedValue = value; | ||||
|             } | ||||
|  | ||||
|             log.info(`Created option "${name}" with default value "${value}"`); | ||||
|             optionService.createOption(name, resolvedValue, isSynced); | ||||
|             log.info(`Created option "${name}" with default value "${resolvedValue}"`); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -129,7 +192,7 @@ function initStartupOptions() { | ||||
| } | ||||
|  | ||||
| function getKeyboardDefaultOptions() { | ||||
|     return (keyboardActions.DEFAULT_KEYBOARD_ACTIONS | ||||
|     return (keyboardActions.getDefaultKeyboardActions() | ||||
|         .filter(ka => !!ka.actionName) as KeyboardShortcutWithRequiredActionName[]) | ||||
|         .map(ka => ({ | ||||
|             name: `keyboardShortcuts${ka.actionName.charAt(0).toUpperCase()}${ka.actionName.slice(1)}`, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user