mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	server-ts: Port services/options_init
This commit is contained in:
		| @@ -3,19 +3,11 @@ | |||||||
| import optionService = require('./options'); | import optionService = require('./options'); | ||||||
| import log = require('./log'); | import log = require('./log'); | ||||||
| import utils = require('./utils'); | import utils = require('./utils'); | ||||||
|  | import { KeyboardShortcut } from './keyboard_actions_interface'; | ||||||
|  |  | ||||||
| const isMac = process.platform === "darwin"; | const isMac = process.platform === "darwin"; | ||||||
| const isElectron = utils.isElectron(); | const isElectron = utils.isElectron(); | ||||||
|  |  | ||||||
| interface KeyboardShortcut { |  | ||||||
|     separator?: string; |  | ||||||
|     actionName?: string; |  | ||||||
|     description?: string; |  | ||||||
|     defaultShortcuts?: string[]; |  | ||||||
|     effectiveShortcuts?: string[]; |  | ||||||
|     scope?: string; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Scope here means on which element the keyboard shortcuts are attached - this means that for the shortcut to work, |  * Scope here means on which element the keyboard shortcuts are attached - this means that for the shortcut to work, | ||||||
|  * the focus has to be inside the element. |  * the focus has to be inside the element. | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								src/services/keyboard_actions_interface.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/services/keyboard_actions_interface.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | export interface KeyboardShortcut { | ||||||
|  |     separator?: string; | ||||||
|  |     actionName?: string; | ||||||
|  |     description?: string; | ||||||
|  |     defaultShortcuts?: string[]; | ||||||
|  |     effectiveShortcuts?: string[]; | ||||||
|  |     scope?: string; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface KeyboardShortcutWithRequiredActionName extends KeyboardShortcut { | ||||||
|  |     actionName: string; | ||||||
|  | } | ||||||
| @@ -1,16 +1,22 @@ | |||||||
| const optionService = require('./options'); | import optionService = require('./options'); | ||||||
| const appInfo = require('./app_info'); | import appInfo = require('./app_info'); | ||||||
| const utils = require('./utils'); | import utils = require('./utils'); | ||||||
| const log = require('./log'); | import log = require('./log'); | ||||||
| const dateUtils = require('./date_utils'); | import dateUtils = require('./date_utils'); | ||||||
| const keyboardActions = require('./keyboard_actions'); | import keyboardActions = require('./keyboard_actions'); | ||||||
|  | import { KeyboardShortcutWithRequiredActionName } from './keyboard_actions_interface'; | ||||||
| 
 | 
 | ||||||
| function initDocumentOptions() { | function initDocumentOptions() { | ||||||
|     optionService.createOption('documentId', utils.randomSecureToken(16), false); |     optionService.createOption('documentId', utils.randomSecureToken(16), false); | ||||||
|     optionService.createOption('documentSecret', utils.randomSecureToken(16), false); |     optionService.createOption('documentSecret', utils.randomSecureToken(16), false); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function initNotSyncedOptions(initialized, opts = {}) { | interface NotSyncedOpts { | ||||||
|  |     syncServerHost?: string; | ||||||
|  |     syncProxy?: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) { | ||||||
|     optionService.createOption('openNoteContexts', JSON.stringify([ |     optionService.createOption('openNoteContexts', JSON.stringify([ | ||||||
|         { |         { | ||||||
|             notePath: 'root', |             notePath: 'root', | ||||||
| @@ -21,7 +27,7 @@ function initNotSyncedOptions(initialized, opts = {}) { | |||||||
|     optionService.createOption('lastDailyBackupDate', dateUtils.utcNowDateTime(), false); |     optionService.createOption('lastDailyBackupDate', dateUtils.utcNowDateTime(), false); | ||||||
|     optionService.createOption('lastWeeklyBackupDate', dateUtils.utcNowDateTime(), false); |     optionService.createOption('lastWeeklyBackupDate', dateUtils.utcNowDateTime(), false); | ||||||
|     optionService.createOption('lastMonthlyBackupDate', dateUtils.utcNowDateTime(), false); |     optionService.createOption('lastMonthlyBackupDate', dateUtils.utcNowDateTime(), false); | ||||||
|     optionService.createOption('dbVersion', appInfo.dbVersion, false); |     optionService.createOption('dbVersion', appInfo.dbVersion.toString(), false); | ||||||
| 
 | 
 | ||||||
|     optionService.createOption('initialized', initialized ? 'true' : 'false', false); |     optionService.createOption('initialized', initialized ? 'true' : 'false', false); | ||||||
| 
 | 
 | ||||||
| @@ -117,8 +123,8 @@ function initStartupOptions() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getKeyboardDefaultOptions() { | function getKeyboardDefaultOptions() { | ||||||
|     return keyboardActions.DEFAULT_KEYBOARD_ACTIONS |     return (keyboardActions.DEFAULT_KEYBOARD_ACTIONS | ||||||
|         .filter(ka => !!ka.actionName) |         .filter(ka => !!ka.actionName) as KeyboardShortcutWithRequiredActionName[]) | ||||||
|         .map(ka => ({ |         .map(ka => ({ | ||||||
|             name: `keyboardShortcuts${ka.actionName.charAt(0).toUpperCase()}${ka.actionName.slice(1)}`, |             name: `keyboardShortcuts${ka.actionName.charAt(0).toUpperCase()}${ka.actionName.slice(1)}`, | ||||||
|             value: JSON.stringify(ka.defaultShortcuts), |             value: JSON.stringify(ka.defaultShortcuts), | ||||||
| @@ -126,7 +132,7 @@ function getKeyboardDefaultOptions() { | |||||||
|         })); |         })); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| module.exports = { | export = { | ||||||
|     initDocumentOptions, |     initDocumentOptions, | ||||||
|     initNotSyncedOptions, |     initNotSyncedOptions, | ||||||
|     initStartupOptions |     initStartupOptions | ||||||
| @@ -84,7 +84,7 @@ async function createInitialDatabase() { | |||||||
|             notePosition: 10 |             notePosition: 10 | ||||||
|         }).save(); |         }).save(); | ||||||
|  |  | ||||||
|         const optionsInitService = require('./options_init.js'); |         const optionsInitService = require('./options_init'); | ||||||
|  |  | ||||||
|         optionsInitService.initDocumentOptions(); |         optionsInitService.initDocumentOptions(); | ||||||
|         optionsInitService.initNotSyncedOptions(true, {}); |         optionsInitService.initNotSyncedOptions(true, {}); | ||||||
| @@ -132,7 +132,7 @@ function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncPr | |||||||
|     sql.transactional(() => { |     sql.transactional(() => { | ||||||
|         sql.executeScript(schema); |         sql.executeScript(schema); | ||||||
|  |  | ||||||
|         require('./options_init.js').initNotSyncedOptions(false,  { syncServerHost, syncProxy }); |         require('./options_init').initNotSyncedOptions(false,  { syncServerHost, syncProxy }); | ||||||
|  |  | ||||||
|         // document options required for sync to kick off |         // document options required for sync to kick off | ||||||
|         for (const opt of options) { |         for (const opt of options) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user