2020-11-05 18:58:23 +02:00
import shim from '../shim' ;
import { _ , supportedLocalesToLanguages , defaultLocale } from '../locale' ;
2021-01-09 00:20:59 +02:00
import eventManager from '../eventManager' ;
2021-01-22 19:41:11 +02:00
import BaseModel from '../BaseModel' ;
2021-01-29 20:45:11 +02:00
import Database from '../database' ;
2020-11-05 18:58:23 +02:00
const SyncTargetRegistry = require ( '../SyncTargetRegistry.js' ) ;
2021-01-22 19:41:11 +02:00
import time from '../time' ;
2021-02-09 19:54:29 +02:00
import FileHandler , { SettingValues } from './settings/FileHandler' ;
2017-11-03 02:09:34 +02:00
const { sprintf } = require ( 'sprintf-js' ) ;
2020-11-05 18:58:23 +02:00
const ObjectUtils = require ( '../ObjectUtils' ) ;
const { toTitleCase } = require ( '../string-utils.js' ) ;
const { rtrimSlashes , toSystemSlashes } = require ( '../path-utils' ) ;
2020-10-09 19:35:46 +02:00
export enum SettingItemType {
Int = 1 ,
String = 2 ,
Bool = 3 ,
Array = 4 ,
Object = 5 ,
Button = 6 ,
}
interface KeysOptions {
2020-11-12 21:29:22 +02:00
secureOnly? : boolean ;
2020-10-09 19:35:46 +02:00
}
2021-02-09 19:54:29 +02:00
export enum SettingStorage {
Database = 1 ,
File = 2 ,
}
2020-10-09 19:35:46 +02:00
// This is the definition of a setting item
export interface SettingItem {
2020-11-12 21:29:22 +02:00
value : any ;
type : SettingItemType ;
public : boolean ;
subType? : string ;
key? : string ;
isEnum? : boolean ;
section? : string ;
label ? ( ) : string ;
2020-11-19 14:34:49 +02:00
description? : Function ;
2020-11-12 21:29:22 +02:00
options ? ( ) : any ;
appTypes? : string [ ] ;
show ? ( settings : any ) : boolean ;
filter ? ( value : any ) : any ;
secure? : boolean ;
advanced? : boolean ;
minimum? : number ;
maximum? : number ;
step? : number ;
onClick ? ( ) : void ;
2020-11-19 14:34:49 +02:00
unitLabel? : Function ;
needRestart? : boolean ;
autoSave? : boolean ;
2021-02-09 19:54:29 +02:00
storage? : SettingStorage ;
2020-10-09 19:35:46 +02:00
}
interface SettingItems {
2020-11-12 21:29:22 +02:00
[ key : string ] : SettingItem ;
2020-10-09 19:35:46 +02:00
}
// This is where the actual setting values are stored.
// They are saved to database at regular intervals.
interface CacheItem {
2020-11-12 21:29:22 +02:00
key : string ;
value : any ;
2020-10-09 19:35:46 +02:00
}
2021-01-22 00:40:14 +02:00
export enum SettingSectionSource {
Default = 1 ,
Plugin = 2 ,
}
2020-10-09 19:35:46 +02:00
export interface SettingSection {
2020-11-12 21:29:22 +02:00
label : string ;
iconName? : string ;
description? : string ;
name? : string ;
2021-01-22 00:40:14 +02:00
source? : SettingSectionSource ;
2020-10-09 19:35:46 +02:00
}
2021-05-03 12:55:38 +02:00
export enum SyncStartupOperation {
None = 0 ,
ClearLocalSyncState = 1 ,
ClearLocalData = 2 ,
}
2021-05-13 18:57:37 +02:00
export enum Env {
Undefined = 'SET_ME' ,
Dev = 'dev' ,
Prod = 'prod' ,
}
export interface Constants {
env : Env ;
isDemo : boolean ;
appName : string ;
appId : string ;
appType : string ;
resourceDirName : string ;
resourceDir : string ;
profileDir : string ;
templateDir : string ;
tempDir : string ;
pluginDataDir : string ;
cacheDir : string ;
pluginDir : string ;
flagOpenDevTools : boolean ;
syncVersion : number ;
startupDevPlugins : string [ ] ;
}
2020-10-09 19:35:46 +02:00
interface SettingSections {
2020-11-12 21:29:22 +02:00
[ key : string ] : SettingSection ;
2020-10-09 19:35:46 +02:00
}
2017-05-12 22:17:23 +02:00
class Setting extends BaseModel {
2020-10-09 19:35:46 +02:00
2021-02-09 19:54:29 +02:00
public static schemaUrl = 'https://joplinapp.org/schema/settings.json' ;
2021-01-22 19:41:11 +02:00
// For backward compatibility
public static TYPE_INT = SettingItemType . Int ;
public static TYPE_STRING = SettingItemType . String ;
public static TYPE_BOOL = SettingItemType . Bool ;
public static TYPE_ARRAY = SettingItemType . Array ;
public static TYPE_OBJECT = SettingItemType . Object ;
public static TYPE_BUTTON = SettingItemType . Button ;
public static THEME_LIGHT = 1 ;
public static THEME_DARK = 2 ;
public static THEME_OLED_DARK = 22 ;
public static THEME_SOLARIZED_LIGHT = 3 ;
public static THEME_SOLARIZED_DARK = 4 ;
public static THEME_DRACULA = 5 ;
public static THEME_NORD = 6 ;
public static THEME_ARITIM_DARK = 7 ;
public static FONT_DEFAULT = 0 ;
public static FONT_MENLO = 1 ;
public static FONT_COURIER_NEW = 2 ;
public static FONT_AVENIR = 3 ;
public static FONT_MONOSPACE = 4 ;
public static LAYOUT_ALL = 0 ;
public static LAYOUT_EDITOR_VIEWER = 1 ;
public static LAYOUT_EDITOR_SPLIT = 2 ;
public static LAYOUT_VIEWER_SPLIT = 3 ;
public static DATE_FORMAT_1 = 'DD/MM/YYYY' ;
public static DATE_FORMAT_2 = 'DD/MM/YY' ;
public static DATE_FORMAT_3 = 'MM/DD/YYYY' ;
public static DATE_FORMAT_4 = 'MM/DD/YY' ;
public static DATE_FORMAT_5 = 'YYYY-MM-DD' ;
public static DATE_FORMAT_6 = 'DD.MM.YYYY' ;
public static DATE_FORMAT_7 = 'YYYY.MM.DD' ;
2021-05-13 09:55:41 +02:00
public static DATE_FORMAT_8 = 'YYMMDD' ;
2021-01-22 19:41:11 +02:00
public static TIME_FORMAT_1 = 'HH:mm' ;
public static TIME_FORMAT_2 = 'h:mm A' ;
public static SHOULD_REENCRYPT_NO = 0 ; // Data doesn't need to be re-encrypted
public static SHOULD_REENCRYPT_YES = 1 ; // Data should be re-encrypted
public static SHOULD_REENCRYPT_NOTIFIED = 2 ; // Data should be re-encrypted, and user has been notified
public static SYNC_UPGRADE_STATE_IDLE = 0 ; // Doesn't need to be upgraded
public static SYNC_UPGRADE_STATE_SHOULD_DO = 1 ; // Should be upgraded, but waiting for user to confirm
public static SYNC_UPGRADE_STATE_MUST_DO = 2 ; // Must be upgraded - on next restart, the upgrade will start
public static custom_css_files = {
JOPLIN_APP : 'userchrome.css' ,
RENDERED_MARKDOWN : 'userstyle.css' ,
} ;
// Contains constants that are set by the application and
// cannot be modified by the user:
2021-05-13 18:57:37 +02:00
public static constants_ : Constants = {
env : Env.Undefined ,
2021-01-22 19:41:11 +02:00
isDemo : false ,
appName : 'joplin' ,
appId : 'SET_ME' , // Each app should set this identifier
appType : 'SET_ME' , // 'cli' or 'mobile'
resourceDirName : '' ,
resourceDir : '' ,
profileDir : '' ,
templateDir : '' ,
tempDir : '' ,
2021-01-24 17:51:35 +02:00
pluginDataDir : '' ,
2021-01-22 19:41:11 +02:00
cacheDir : '' ,
pluginDir : '' ,
flagOpenDevTools : false ,
syncVersion : 2 ,
startupDevPlugins : [ ] ,
} ;
public static autoSaveEnabled = true ;
2020-11-12 21:13:28 +02:00
private static metadata_ : SettingItems = null ;
private static keychainService_ : any = null ;
private static keys_ : string [ ] = null ;
private static cache_ : CacheItem [ ] = [ ] ;
private static saveTimeoutId_ : any = null ;
2021-01-09 00:20:59 +02:00
private static changeEventTimeoutId_ : any = null ;
2020-11-12 21:13:28 +02:00
private static customMetadata_ : SettingItems = { } ;
private static customSections_ : SettingSections = { } ;
2021-01-09 00:20:59 +02:00
private static changedKeys_ : string [ ] = [ ] ;
2021-02-09 19:54:29 +02:00
private static fileHandler_ : FileHandler = null ;
2020-10-09 19:35:46 +02:00
2017-05-12 22:17:23 +02:00
static tableName() {
return 'settings' ;
}
2017-07-03 21:50:45 +02:00
static modelType() {
return BaseModel . TYPE_SETTING ;
2017-06-19 21:26:27 +02:00
}
2020-10-09 19:35:46 +02:00
static async reset() {
if ( this . saveTimeoutId_ ) shim . clearTimeout ( this . saveTimeoutId_ ) ;
2021-01-09 00:20:59 +02:00
if ( this . changeEventTimeoutId_ ) shim . clearTimeout ( this . changeEventTimeoutId_ ) ;
2020-10-09 19:35:46 +02:00
this . saveTimeoutId_ = null ;
2021-01-09 00:20:59 +02:00
this . changeEventTimeoutId_ = null ;
2020-10-09 19:35:46 +02:00
this . metadata_ = null ;
this . keys_ = null ;
this . cache_ = [ ] ;
this . customMetadata_ = { } ;
2021-02-09 19:54:29 +02:00
this . fileHandler_ = null ;
}
public static get settingFilePath ( ) : string {
return ` ${ this . value ( 'profileDir' ) } /settings.json ` ;
}
2021-06-16 19:22:32 +02:00
public static get fileHandler ( ) : FileHandler {
2021-02-09 19:54:29 +02:00
if ( ! this . fileHandler_ ) {
this . fileHandler_ = new FileHandler ( this . settingFilePath ) ;
}
return this . fileHandler_ ;
2020-10-09 19:35:46 +02:00
}
2020-06-03 18:07:50 +02:00
static keychainService() {
if ( ! this . keychainService_ ) throw new Error ( 'keychainService has not been set!!' ) ;
return this . keychainService_ ;
}
2020-11-12 21:13:28 +02:00
static setKeychainService ( s : any ) {
2020-06-03 18:07:50 +02:00
this . keychainService_ = s ;
}
2020-11-12 21:13:28 +02:00
static metadata ( ) : SettingItems {
2017-11-24 21:21:30 +02:00
if ( this . metadata_ ) return this . metadata_ ;
2018-04-16 19:18:28 +02:00
const platform = shim . platformName ( ) ;
2019-09-17 22:32:00 +02:00
const mobilePlatform = shim . mobilePlatform ( ) ;
2018-04-16 19:18:28 +02:00
2020-04-10 20:16:18 +02:00
let wysiwygYes = '' ;
let wysiwygNo = '' ;
if ( shim . isElectron ( ) ) {
wysiwygYes = ` ${ _ ( '(wysiwyg: %s)' , _ ( 'yes' ) ) } ` ;
wysiwygNo = ` ${ _ ( '(wysiwyg: %s)' , _ ( 'no' ) ) } ` ;
}
2019-04-18 15:59:17 +02:00
const emptyDirWarning = _ ( 'Attention: If you change this location, make sure you copy all your content to it before syncing, otherwise all files will be removed! See the FAQ for more details: %s' , 'https://joplinapp.org/faq/' ) ;
2019-03-29 10:01:58 +02:00
2018-02-22 20:58:15 +02:00
// A "public" setting means that it will show up in the various config screens (or config command for the CLI tool), however
// if if private a setting might still be handled and modified by the app. For instance, the settings related to sorting notes are not
// public for the mobile and desktop apps because they are handled separately in menus.
2020-05-21 01:47:38 +02:00
const themeOptions = ( ) = > {
2020-11-12 21:13:28 +02:00
const output : any = { } ;
2020-05-21 01:47:38 +02:00
output [ Setting . THEME_LIGHT ] = _ ( 'Light' ) ;
output [ Setting . THEME_DARK ] = _ ( 'Dark' ) ;
2020-06-10 23:08:59 +02:00
output [ Setting . THEME_DRACULA ] = _ ( 'Dracula' ) ;
output [ Setting . THEME_SOLARIZED_LIGHT ] = _ ( 'Solarised Light' ) ;
output [ Setting . THEME_SOLARIZED_DARK ] = _ ( 'Solarised Dark' ) ;
output [ Setting . THEME_NORD ] = _ ( 'Nord' ) ;
output [ Setting . THEME_ARITIM_DARK ] = _ ( 'Aritim Dark' ) ;
output [ Setting . THEME_OLED_DARK ] = _ ( 'OLED Dark' ) ;
2020-05-21 01:47:38 +02:00
return output ;
} ;
2017-11-24 21:21:30 +02:00
this . metadata_ = {
2019-10-10 23:23:11 +02:00
'clientId' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-10-10 23:23:11 +02:00
public : false ,
} ,
2020-05-02 17:41:07 +02:00
'editor.codeView' : {
2020-05-20 01:59:12 +02:00
value : true ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2020-05-02 17:41:07 +02:00
public : false ,
2019-11-06 23:51:08 +02:00
appTypes : [ 'desktop' ] ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-11-06 23:51:08 +02:00
} ,
2019-07-29 15:43:53 +02:00
'sync.target' : {
value : SyncTargetRegistry.nameToId ( 'dropbox' ) ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
public : true ,
section : 'sync' ,
label : ( ) = > _ ( 'Synchronisation target' ) ,
2020-11-12 21:13:28 +02:00
description : ( appType : string ) = > {
2020-12-29 19:10:52 +02:00
return appType !== 'cli' ? null : _ ( 'The target to synchronise to. Each sync target may have additional parameters which are named as `sync.NUM.NAME` (all documented below).' ) ;
2019-07-29 15:43:53 +02:00
} ,
options : ( ) = > {
2020-02-08 13:59:19 +02:00
return SyncTargetRegistry . idAndLabelPlainObject ( platform ) ;
2019-07-29 15:43:53 +02:00
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-08-02 13:28:50 +02:00
'sync.upgradeState' : {
value : Setting.SYNC_UPGRADE_STATE_IDLE ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-08-02 13:28:50 +02:00
public : false ,
} ,
2021-05-03 12:55:38 +02:00
'sync.startupOperation' : {
value : SyncStartupOperation.None ,
type : SettingItemType . Int ,
public : false ,
} ,
2019-07-29 15:43:53 +02:00
'sync.2.path' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
try {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'filesystem' ) ;
} catch ( error ) {
return false ;
}
} ,
2020-11-12 21:13:28 +02:00
filter : ( value : any ) = > {
2019-07-29 15:43:53 +02:00
return value ? rtrimSlashes ( value ) : '' ;
} ,
public : true ,
label : ( ) = > _ ( 'Directory to synchronise with (absolute path)' ) ,
description : ( ) = > emptyDirWarning ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'sync.5.path' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'nextcloud' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'Nextcloud WebDAV URL' ) ,
description : ( ) = > emptyDirWarning ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'sync.5.username' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'nextcloud' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'Nextcloud username' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'sync.5.password' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'nextcloud' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'Nextcloud password' ) ,
secure : true ,
} ,
'sync.6.path' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'webdav' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'WebDAV URL' ) ,
description : ( ) = > emptyDirWarning ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'sync.6.username' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'webdav' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'WebDAV username' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'sync.6.password' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2019-07-29 15:43:53 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'webdav' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'WebDAV password' ) ,
secure : true ,
} ,
2019-06-08 01:23:17 +02:00
2020-07-15 11:22:55 +02:00
'sync.8.path' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2020-07-15 11:22:55 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2020-07-15 11:22:55 +02:00
try {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'amazon_s3' ) ;
} catch ( error ) {
return false ;
}
} ,
filter : value = > {
return value ? rtrimSlashes ( value ) : '' ;
} ,
public : true ,
label : ( ) = > _ ( 'AWS S3 bucket' ) ,
description : ( ) = > emptyDirWarning ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-07-15 11:22:55 +02:00
} ,
2020-10-20 12:44:11 +02:00
'sync.8.url' : {
value : 'https://s3.amazonaws.com/' ,
type : SettingItemType . String ,
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2020-10-20 12:44:11 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'amazon_s3' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'AWS S3 URL' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-10-20 12:44:11 +02:00
} ,
2020-07-15 11:22:55 +02:00
'sync.8.username' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2020-07-15 11:22:55 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2020-07-15 11:22:55 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'amazon_s3' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'AWS key' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-07-15 11:22:55 +02:00
} ,
'sync.8.password' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2020-07-15 11:22:55 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2020-07-15 11:22:55 +02:00
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'amazon_s3' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'AWS secret' ) ,
secure : true ,
} ,
2019-06-08 01:23:17 +02:00
2020-12-28 13:48:47 +02:00
'sync.9.path' : {
value : '' ,
type : SettingItemType . String ,
section : 'sync' ,
show : ( settings : any ) = > {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'joplinServer' ) ;
} ,
public : true ,
2021-06-02 09:56:24 +02:00
label : ( ) = > _ ( 'Joplin Server URL' ) ,
2020-12-28 13:48:47 +02:00
description : ( ) = > emptyDirWarning ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-12-28 13:48:47 +02:00
} ,
2021-06-06 19:14:12 +02:00
'sync.9.userContentPath' : {
value : '' ,
type : SettingItemType . String ,
public : false ,
storage : SettingStorage.Database ,
} ,
2020-12-28 13:48:47 +02:00
'sync.9.username' : {
value : '' ,
type : SettingItemType . String ,
section : 'sync' ,
show : ( settings : any ) = > {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'joplinServer' ) ;
} ,
public : true ,
2021-06-02 09:56:24 +02:00
label : ( ) = > _ ( 'Joplin Server email' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-12-28 13:48:47 +02:00
} ,
'sync.9.password' : {
value : '' ,
type : SettingItemType . String ,
section : 'sync' ,
show : ( settings : any ) = > {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'joplinServer' ) ;
} ,
public : true ,
2021-06-02 09:56:24 +02:00
label : ( ) = > _ ( 'Joplin Server password' ) ,
2020-12-28 13:48:47 +02:00
secure : true ,
} ,
2021-06-03 17:12:07 +02:00
// Although sync.10.path is essentially a constant, we still define
// it here so that both Joplin Server and Joplin Cloud can be
// handled in the same consistent way. Also having it a setting
// means it can be set to something else for development.
'sync.10.path' : {
value : 'https://api.joplincloud.com' ,
type : SettingItemType . String ,
public : false ,
storage : SettingStorage.Database ,
} ,
2021-06-06 19:14:12 +02:00
'sync.10.userContentPath' : {
value : 'https://joplinusercontent.com' ,
type : SettingItemType . String ,
public : false ,
storage : SettingStorage.Database ,
} ,
2021-06-03 17:12:07 +02:00
'sync.10.username' : {
value : '' ,
type : SettingItemType . String ,
section : 'sync' ,
show : ( settings : any ) = > {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'joplinCloud' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'Joplin Cloud email' ) ,
storage : SettingStorage.File ,
} ,
'sync.10.password' : {
value : '' ,
type : SettingItemType . String ,
section : 'sync' ,
show : ( settings : any ) = > {
return settings [ 'sync.target' ] == SyncTargetRegistry . nameToId ( 'joplinCloud' ) ;
} ,
public : true ,
label : ( ) = > _ ( 'Joplin Cloud password' ) ,
secure : true ,
} ,
2020-10-09 19:35:46 +02:00
'sync.5.syncTargets' : { value : { } , type : SettingItemType . Object , public : false } ,
2019-12-13 03:16:34 +02:00
2019-07-29 15:43:53 +02:00
'sync.resourceDownloadMode' : {
value : 'always' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
public : true ,
2019-12-13 03:16:34 +02:00
advanced : true ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
appTypes : [ 'mobile' , 'desktop' ] ,
label : ( ) = > _ ( 'Attachment download behaviour' ) ,
description : ( ) = > _ ( 'In "Manual" mode, attachments are downloaded only when you click on them. In "Auto", they are downloaded when you open the note. In "Always", all the attachments are downloaded whether you open the note or not.' ) ,
options : ( ) = > {
return {
always : _ ( 'Always' ) ,
manual : _ ( 'Manual' ) ,
auto : _ ( 'Auto' ) ,
} ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-10-09 19:35:46 +02:00
'sync.3.auth' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.4.auth' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.7.auth' : { value : '' , type : SettingItemType . String , public : false } ,
2020-12-28 13:48:47 +02:00
'sync.9.auth' : { value : '' , type : SettingItemType . String , public : false } ,
2021-06-03 17:12:07 +02:00
'sync.10.auth' : { value : '' , type : SettingItemType . String , public : false } ,
2020-10-09 19:35:46 +02:00
'sync.1.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.2.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.3.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.4.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.5.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.6.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.7.context' : { value : '' , type : SettingItemType . String , public : false } ,
'sync.8.context' : { value : '' , type : SettingItemType . String , public : false } ,
2020-12-28 13:48:47 +02:00
'sync.9.context' : { value : '' , type : SettingItemType . String , public : false } ,
2021-06-03 17:12:07 +02:00
'sync.10.context' : { value : '' , type : SettingItemType . String , public : false } ,
2020-07-15 11:22:55 +02:00
2021-02-09 19:54:29 +02:00
'sync.maxConcurrentConnections' : { value : 5 , type : SettingItemType . Int , storage : SettingStorage.File , public : true , advanced : true , section : 'sync' , label : ( ) = > _ ( 'Max concurrent connections' ) , minimum : 1 , maximum : 20 , step : 1 } ,
2019-07-29 15:43:53 +02:00
2020-09-07 18:42:16 +02:00
// The active folder ID is guaranteed to be valid as long as there's at least one
// existing folder, so it is a good default in contexts where there's no currently
// selected folder. It corresponds in general to the currently selected folder or
// to the last folder that was selected.
2020-10-09 19:35:46 +02:00
activeFolderId : { value : '' , type : SettingItemType . String , public : false } ,
2020-09-07 18:42:16 +02:00
2020-12-09 17:58:15 +02:00
richTextBannerDismissed : { value : false , type : SettingItemType . Bool , public : false } ,
2020-10-09 19:35:46 +02:00
firstStart : { value : true , type : SettingItemType . Bool , public : false } ,
2019-07-29 15:43:53 +02:00
locale : {
value : defaultLocale ( ) ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
public : true ,
label : ( ) = > _ ( 'Language' ) ,
options : ( ) = > {
return ObjectUtils . sortByValue ( supportedLocalesToLanguages ( { includeStats : true } ) ) ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
dateFormat : {
value : Setting.DATE_FORMAT_1 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
public : true ,
label : ( ) = > _ ( 'Date format' ) ,
options : ( ) = > {
2020-11-12 21:13:28 +02:00
const options : any = { } ;
2019-07-29 15:43:53 +02:00
const now = new Date ( '2017-01-30T12:00:00' ) . getTime ( ) ;
options [ Setting . DATE_FORMAT_1 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_1 ) ;
options [ Setting . DATE_FORMAT_2 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_2 ) ;
options [ Setting . DATE_FORMAT_3 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_3 ) ;
options [ Setting . DATE_FORMAT_4 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_4 ) ;
options [ Setting . DATE_FORMAT_5 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_5 ) ;
options [ Setting . DATE_FORMAT_6 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_6 ) ;
2020-01-26 19:26:50 +02:00
options [ Setting . DATE_FORMAT_7 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_7 ) ;
2021-05-13 09:55:41 +02:00
options [ Setting . DATE_FORMAT_8 ] = time . formatMsToLocal ( now , Setting . DATE_FORMAT_8 ) ;
2019-07-29 15:43:53 +02:00
return options ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
timeFormat : {
value : Setting.TIME_FORMAT_1 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
public : true ,
label : ( ) = > _ ( 'Time format' ) ,
options : ( ) = > {
2020-11-12 21:13:28 +02:00
const options : any = { } ;
2019-07-29 15:43:53 +02:00
const now = new Date ( '2017-01-30T20:30:00' ) . getTime ( ) ;
options [ Setting . TIME_FORMAT_1 ] = time . formatMsToLocal ( now , Setting . TIME_FORMAT_1 ) ;
options [ Setting . TIME_FORMAT_2 ] = time . formatMsToLocal ( now , Setting . TIME_FORMAT_2 ) ;
return options ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-05-21 01:47:38 +02:00
2019-07-29 15:43:53 +02:00
theme : {
value : Setting.THEME_LIGHT ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2019-07-29 15:43:53 +02:00
public : true ,
appTypes : [ 'mobile' , 'desktop' ] ,
2020-05-21 01:47:38 +02:00
show : ( settings ) = > {
return ! settings [ 'themeAutoDetect' ] ;
} ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
label : ( ) = > _ ( 'Theme' ) ,
section : 'appearance' ,
2020-05-21 01:47:38 +02:00
options : ( ) = > themeOptions ( ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-21 01:47:38 +02:00
} ,
themeAutoDetect : {
value : false ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2020-05-21 01:47:38 +02:00
section : 'appearance' ,
appTypes : [ 'desktop' ] ,
public : true ,
label : ( ) = > _ ( 'Automatically switch theme to match system theme' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-21 01:47:38 +02:00
} ,
preferredLightTheme : {
value : Setting.THEME_LIGHT ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-05-21 01:47:38 +02:00
public : true ,
show : ( settings ) = > {
return settings [ 'themeAutoDetect' ] ;
2019-07-29 15:43:53 +02:00
} ,
2020-05-21 01:47:38 +02:00
appTypes : [ 'desktop' ] ,
isEnum : true ,
label : ( ) = > _ ( 'Preferred light theme' ) ,
section : 'appearance' ,
options : ( ) = > themeOptions ( ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-05-21 01:47:38 +02:00
preferredDarkTheme : {
value : Setting.THEME_DARK ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-05-21 01:47:38 +02:00
public : true ,
show : ( settings ) = > {
return settings [ 'themeAutoDetect' ] ;
} ,
appTypes : [ 'desktop' ] ,
isEnum : true ,
label : ( ) = > _ ( 'Preferred dark theme' ) ,
section : 'appearance' ,
options : ( ) = > themeOptions ( ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-21 01:47:38 +02:00
} ,
2020-11-28 14:02:26 +02:00
notificationPermission : {
value : '' ,
type : SettingItemType . String ,
public : false ,
} ,
2021-02-09 19:54:29 +02:00
showNoteCounts : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , public : false , advanced : true , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Show note counts' ) } ,
2020-06-03 18:07:50 +02:00
2019-10-31 10:47:45 +02:00
layoutButtonSequence : {
2019-10-31 10:42:17 +02:00
value : Setting.LAYOUT_ALL ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2019-10-31 10:42:17 +02:00
public : false ,
appTypes : [ 'desktop' ] ,
isEnum : true ,
options : ( ) = > ( {
[ Setting . LAYOUT_ALL ] : _ ( '%s / %s / %s' , _ ( 'Editor' ) , _ ( 'Viewer' ) , _ ( 'Split View' ) ) ,
[ Setting . LAYOUT_EDITOR_VIEWER ] : _ ( '%s / %s' , _ ( 'Editor' ) , _ ( 'Viewer' ) ) ,
[ Setting . LAYOUT_EDITOR_SPLIT ] : _ ( '%s / %s' , _ ( 'Editor' ) , _ ( 'Split View' ) ) ,
[ Setting . LAYOUT_VIEWER_SPLIT ] : _ ( '%s / %s' , _ ( 'Viewer' ) , _ ( 'Split View' ) ) ,
} ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-10-31 10:42:17 +02:00
} ,
2021-02-09 19:54:29 +02:00
uncompletedTodosOnTop : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , section : 'note' , public : true , appTypes : [ 'cli' ] , label : ( ) = > _ ( 'Uncompleted to-dos on top' ) } ,
showCompletedTodos : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , section : 'note' , public : true , appTypes : [ 'cli' ] , label : ( ) = > _ ( 'Show completed to-dos' ) } ,
2019-07-29 15:43:53 +02:00
'notes.sortOrder.field' : {
value : 'user_updated_time' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'note' ,
isEnum : true ,
public : true ,
appTypes : [ 'cli' ] ,
label : ( ) = > _ ( 'Sort notes by' ) ,
options : ( ) = > {
2021-01-22 19:41:11 +02:00
const Note = require ( './Note' ) . default ;
2020-05-27 18:21:46 +02:00
const noteSortFields = [ 'user_updated_time' , 'user_created_time' , 'title' , 'order' ] ;
2020-11-12 21:13:28 +02:00
const options : any = { } ;
2019-07-29 15:43:53 +02:00
for ( let i = 0 ; i < noteSortFields . length ; i ++ ) {
options [ noteSortFields [ i ] ] = toTitleCase ( Note . fieldToLabel ( noteSortFields [ i ] ) ) ;
}
return options ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-01-07 00:27:37 +02:00
'editor.autoMatchingBraces' : {
value : true ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2020-01-07 00:27:37 +02:00
public : true ,
section : 'note' ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Auto-pair braces, parenthesis, quotations, etc.' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-01-07 00:27:37 +02:00
} ,
2021-02-09 19:54:29 +02:00
'notes.sortOrder.reverse' : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , section : 'note' , public : true , label : ( ) = > _ ( 'Reverse sort order' ) , appTypes : [ 'cli' ] } ,
2019-07-29 15:43:53 +02:00
'folders.sortOrder.field' : {
value : 'title' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
isEnum : true ,
public : true ,
appTypes : [ 'cli' ] ,
label : ( ) = > _ ( 'Sort notebooks by' ) ,
options : ( ) = > {
2021-01-22 19:41:11 +02:00
const Folder = require ( './Folder' ) . default ;
2019-07-29 15:43:53 +02:00
const folderSortFields = [ 'title' , 'last_note_user_updated_time' ] ;
2020-11-12 21:13:28 +02:00
const options : any = { } ;
2019-07-29 15:43:53 +02:00
for ( let i = 0 ; i < folderSortFields . length ; i ++ ) {
options [ folderSortFields [ i ] ] = toTitleCase ( Folder . fieldToLabel ( folderSortFields [ i ] ) ) ;
}
return options ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2021-02-09 19:54:29 +02:00
'folders.sortOrder.reverse' : { value : false , type : SettingItemType . Bool , storage : SettingStorage.File , public : true , label : ( ) = > _ ( 'Reverse sort order' ) , appTypes : [ 'cli' ] } ,
trackLocation : { value : true , type : SettingItemType . Bool , section : 'note' , storage : SettingStorage.File , public : true , label : ( ) = > _ ( 'Save geo-location with notes' ) } ,
2020-03-25 12:50:45 +02:00
2020-10-29 18:42:47 +02:00
// 2020-10-29: For now disable the beta editor due to
// underlying bugs in the TextInput component which we cannot
// fix. Also the editor crashes in Android and in some cases in
// iOS.
// https://discourse.joplinapp.org/t/anyone-using-the-beta-editor-on-ios/11658/9
2020-03-25 12:50:45 +02:00
'editor.beta' : {
value : false ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2020-03-25 12:50:45 +02:00
section : 'note' ,
2020-10-29 18:42:47 +02:00
public : false , // mobilePlatform === 'ios',
2020-03-25 12:50:45 +02:00
appTypes : [ 'mobile' ] ,
label : ( ) = > 'Opt-in to the editor beta' ,
description : ( ) = > 'This beta adds list continuation, Markdown preview, and Markdown shortcuts. If you find bugs, please report them in the Discourse forum.' ,
} ,
2019-07-29 15:43:53 +02:00
newTodoFocus : {
value : 'title' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'note' ,
isEnum : true ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'When creating a new to-do:' ) ,
options : ( ) = > {
return {
title : _ ( 'Focus title' ) ,
body : _ ( 'Focus body' ) ,
} ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
newNoteFocus : {
value : 'body' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'note' ,
isEnum : true ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'When creating a new note:' ) ,
options : ( ) = > {
return {
title : _ ( 'Focus title' ) ,
body : _ ( 'Focus body' ) ,
} ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2019-12-29 19:58:40 +02:00
2020-11-19 14:34:49 +02:00
'plugins.states' : {
value : '' ,
type : SettingItemType . Object ,
section : 'plugins' ,
public : true ,
appTypes : [ 'desktop' ] ,
needRestart : true ,
autoSave : true ,
} ,
2020-10-09 19:35:46 +02:00
'plugins.devPluginPaths' : {
value : '' ,
type : SettingItemType . String ,
section : 'plugins' ,
public : true ,
2021-01-07 18:30:53 +02:00
advanced : true ,
2020-10-09 19:35:46 +02:00
appTypes : [ 'desktop' ] ,
label : ( ) = > 'Development plugins' ,
description : ( ) = > 'You may add multiple plugin paths, each separated by a comma. You will need to restart the application for the changes to take effect.' ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-10-09 19:35:46 +02:00
} ,
2019-12-29 19:58:40 +02:00
// Deprecated - use markdown.plugin.*
2021-02-09 19:54:29 +02:00
'markdown.softbreaks' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , public : false , appTypes : [ 'mobile' , 'desktop' ] } ,
'markdown.typographer' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , public : false , appTypes : [ 'mobile' , 'desktop' ] } ,
2019-12-29 19:58:40 +02:00
// Deprecated
2021-02-09 19:54:29 +02:00
'markdown.plugin.softbreaks' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable soft breaks' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.typographer' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable typographer support' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.linkify' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable Linkify' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.katex' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable math expressions' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.fountain' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable Fountain syntax support' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.mermaid' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable Mermaid diagrams support' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.audioPlayer' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable audio player' ) } ${ wysiwygNo } ` } ,
'markdown.plugin.videoPlayer' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable video player' ) } ${ wysiwygNo } ` } ,
'markdown.plugin.pdfViewer' : { storage : SettingStorage.File , value : ! mobilePlatform , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable PDF viewer' ) } ${ wysiwygNo } ` } ,
2021-03-16 21:39:35 +02:00
'markdown.plugin.mark' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable ==mark== syntax' ) } ${ wysiwygYes } ` } ,
2021-02-09 19:54:29 +02:00
'markdown.plugin.footnote' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable footnotes' ) } ${ wysiwygNo } ` } ,
'markdown.plugin.toc' : { storage : SettingStorage.File , value : true , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable table of contents extension' ) } ${ wysiwygNo } ` } ,
2021-03-17 11:48:01 +02:00
'markdown.plugin.sub' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable ~sub~ syntax' ) } ${ wysiwygYes } ` } ,
'markdown.plugin.sup' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable ^sup^ syntax' ) } ${ wysiwygYes } ` } ,
2021-02-09 19:54:29 +02:00
'markdown.plugin.deflist' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable deflist syntax' ) } ${ wysiwygNo } ` } ,
'markdown.plugin.abbr' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable abbreviation syntax' ) } ${ wysiwygNo } ` } ,
'markdown.plugin.emoji' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable markdown emoji' ) } ${ wysiwygNo } ` } ,
2021-03-17 11:48:01 +02:00
'markdown.plugin.insert' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable ++insert++ syntax' ) } ${ wysiwygYes } ` } ,
2021-02-09 19:54:29 +02:00
'markdown.plugin.multitable' : { storage : SettingStorage.File , value : false , type : SettingItemType . Bool , section : 'markdownPlugins' , public : true , appTypes : [ 'mobile' , 'desktop' ] , label : ( ) = > ` ${ _ ( 'Enable multimarkdown table extension' ) } ${ wysiwygNo } ` } ,
2018-04-16 19:18:28 +02:00
// Tray icon (called AppIndicator) doesn't work in Ubuntu
// http://www.webupd8.org/2017/04/fix-appindicator-not-working-for.html
// Might be fixed in Electron 18.x but no non-beta release yet. So for now
// by default we disable it on Linux.
2019-07-29 15:43:53 +02:00
showTrayIcon : {
value : platform !== 'linux' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2019-07-29 15:43:53 +02:00
section : 'application' ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Show tray icon' ) ,
description : ( ) = > {
return platform === 'linux' ? _ ( 'Note: Does not work in all desktop environments.' ) : _ ( 'This will allow Joplin to run in the background. It is recommended to enable this setting so that your notes are constantly being synchronised, thus reducing the number of conflicts.' ) ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2021-02-09 19:54:29 +02:00
startMinimized : { value : false , type : SettingItemType . Bool , storage : SettingStorage.File , section : 'application' , public : true , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Start application minimised in the tray icon' ) } ,
2019-07-29 15:43:53 +02:00
2020-10-09 19:35:46 +02:00
collapsedFolderIds : { value : [ ] , type : SettingItemType . Array , public : false } ,
2019-01-09 19:25:44 +02:00
2020-10-09 19:35:46 +02:00
'keychain.supported' : { value : - 1 , type : SettingItemType . Int , public : false } ,
'db.ftsEnabled' : { value : - 1 , type : SettingItemType . Int , public : false } ,
'db.fuzzySearchEnabled' : { value : - 1 , type : SettingItemType . Int , public : false } ,
'encryption.enabled' : { value : false , type : SettingItemType . Bool , public : false } ,
'encryption.activeMasterKeyId' : { value : '' , type : SettingItemType . String , public : false } ,
'encryption.passwordCache' : { value : { } , type : SettingItemType . Object , public : false , secure : true } ,
2020-03-13 19:42:50 +02:00
'encryption.shouldReencrypt' : {
value : - 1 , // will be set on app startup
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-03-13 19:42:50 +02:00
public : false ,
} ,
2020-02-12 14:41:32 +02:00
2021-05-13 18:57:37 +02:00
'sync.userId' : {
value : '' ,
type : SettingItemType . String ,
public : false ,
} ,
2020-02-12 14:41:32 +02:00
// Deprecated in favour of windowContentZoomFactor
2021-02-09 19:54:29 +02:00
'style.zoom' : { value : 100 , type : SettingItemType . Int , public : false , storage : SettingStorage.File , appTypes : [ 'desktop' ] , section : 'appearance' , label : ( ) = > '' , minimum : 50 , maximum : 500 , step : 10 } ,
2020-02-12 14:41:32 +02:00
2021-02-09 19:54:29 +02:00
'style.editor.fontSize' : { value : 13 , type : SettingItemType . Int , public : true , storage : SettingStorage.File , appTypes : [ 'desktop' ] , section : 'appearance' , label : ( ) = > _ ( 'Editor font size' ) , minimum : 4 , maximum : 50 , step : 1 } ,
2019-09-17 22:32:00 +02:00
'style.editor.fontFamily' :
2019-09-19 23:51:18 +02:00
( mobilePlatform ) ?
2019-09-17 22:32:00 +02:00
( {
value : Setting.FONT_DEFAULT ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-09-17 22:32:00 +02:00
isEnum : true ,
public : true ,
label : ( ) = > _ ( 'Editor font' ) ,
appTypes : [ 'mobile' ] ,
section : 'appearance' ,
options : ( ) = > {
// IMPORTANT: The font mapping must match the one in global-styles.js::editorFont()
if ( mobilePlatform === 'ios' ) {
return {
2021-01-21 20:23:32 +02:00
[ Setting . FONT_DEFAULT ] : _ ( 'Default' ) ,
2019-09-17 22:32:00 +02:00
[ Setting . FONT_MENLO ] : 'Menlo' ,
[ Setting . FONT_COURIER_NEW ] : 'Courier New' ,
[ Setting . FONT_AVENIR ] : 'Avenir' ,
} ;
}
return {
2021-01-21 20:23:32 +02:00
[ Setting . FONT_DEFAULT ] : _ ( 'Default' ) ,
2019-09-17 22:32:00 +02:00
[ Setting . FONT_MONOSPACE ] : 'Monospace' ,
} ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-09-17 22:32:00 +02:00
} ) : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-09-17 22:32:00 +02:00
public : true ,
appTypes : [ 'desktop' ] ,
section : 'appearance' ,
label : ( ) = > _ ( 'Editor font family' ) ,
description : ( ) = >
2021-04-08 11:14:17 +02:00
_ ( 'Used for most text in the markdown editor. If not found, a generic proportional (variable width) font is used.' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-09-17 22:32:00 +02:00
} ,
2021-03-26 11:08:22 +02:00
'style.editor.monospaceFontFamily' : {
value : '' ,
type : SettingItemType . String ,
public : true ,
appTypes : [ 'desktop' ] ,
section : 'appearance' ,
label : ( ) = > _ ( 'Editor monospace font family' ) ,
description : ( ) = >
2021-04-08 11:14:17 +02:00
_ ( 'Used where a fixed width font is needed to lay out text legibly (e.g. tables, checkboxes, code). If not found, a generic monospace (fixed width) font is used.' ) ,
2021-03-26 11:08:22 +02:00
storage : SettingStorage.File ,
} ,
2020-10-09 19:35:46 +02:00
2021-02-09 19:54:29 +02:00
'ui.layout' : { value : { } , type : SettingItemType . Object , storage : SettingStorage.File , public : false , appTypes : [ 'desktop' ] } ,
2020-10-09 19:35:46 +02:00
2019-12-13 02:40:58 +02:00
// TODO: Is there a better way to do this? The goal here is to simply have
// a way to display a link to the customizable stylesheets, not for it to
// serve as a customizable Setting. But because the Setting page is auto-
// generated from this list of settings, there wasn't a really elegant way
// to do that directly in the React markup.
'style.customCss.renderedMarkdown' : {
2020-10-09 19:35:46 +02:00
value : null ,
2019-12-13 02:40:58 +02:00
onClick : ( ) = > {
const dir = Setting . value ( 'profileDir' ) ;
const filename = Setting . custom_css_files . RENDERED_MARKDOWN ;
const filepath = ` ${ dir } / ${ filename } ` ;
const defaultContents = '/* For styling the rendered Markdown */' ;
shim . openOrCreateFile ( filepath , defaultContents ) ;
} ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Button ,
2019-12-13 02:40:58 +02:00
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Custom stylesheet for rendered Markdown' ) ,
section : 'appearance' ,
2020-03-06 20:22:40 +02:00
advanced : true ,
2019-12-13 02:40:58 +02:00
} ,
'style.customCss.joplinApp' : {
2020-10-09 19:35:46 +02:00
value : null ,
2019-12-13 02:40:58 +02:00
onClick : ( ) = > {
const dir = Setting . value ( 'profileDir' ) ;
const filename = Setting . custom_css_files . JOPLIN_APP ;
const filepath = ` ${ dir } / ${ filename } ` ;
const defaultContents = ` /* For styling the entire Joplin app (except the rendered Markdown, which is defined in \` ${ Setting . custom_css_files . RENDERED_MARKDOWN } \` ) */ ` ;
shim . openOrCreateFile ( filepath , defaultContents ) ;
} ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Button ,
2019-12-13 02:40:58 +02:00
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Custom stylesheet for Joplin-wide app styles' ) ,
section : 'appearance' ,
2020-03-06 20:22:40 +02:00
advanced : true ,
description : ( ) = > 'CSS file support is provided for your convenience, but they are advanced settings, and styles you define may break from one version to the next. If you want to use them, please know that it might require regular development work from you to keep them working. The Joplin team cannot make a commitment to keep the application HTML structure stable.' ,
2019-12-13 02:40:58 +02:00
} ,
2021-05-03 12:55:38 +02:00
'sync.clearLocalSyncStateButton' : {
value : null ,
type : SettingItemType . Button ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Re-upload local data to sync target' ) ,
section : 'sync' ,
advanced : true ,
description : ( ) = > 'If the data on the sync target is incorrect or empty, you can use this button to force a re-upload of your data to the sync target. Application will have to be restarted' ,
} ,
'sync.clearLocalDataButton' : {
value : null ,
type : SettingItemType . Button ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > _ ( 'Delete local data and re-download from sync target' ) ,
section : 'sync' ,
advanced : true ,
description : ( ) = > 'If the data on the sync target is correct but your local data is not, you can use this button to clear your local data and force re-downloading everything from the sync target. As your local data will be deleted first, it is recommended to export your data as JEX first. Application will have to be restarted' ,
} ,
2021-05-14 11:29:06 +02:00
autoUpdateEnabled : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , section : 'application' , public : platform !== 'linux' , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Automatically update the application' ) } ,
2021-02-09 19:54:29 +02:00
'autoUpdate.includePreReleases' : { value : false , type : SettingItemType . Bool , section : 'application' , storage : SettingStorage.File , public : true , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Get pre-releases when checking for updates' ) , description : ( ) = > _ ( 'See the pre-release page for more details: %s' , 'https://joplinapp.org/prereleases' ) } ,
'clipperServer.autoStart' : { value : false , type : SettingItemType . Bool , storage : SettingStorage.File , public : false } ,
2019-07-29 15:43:53 +02:00
'sync.interval' : {
value : 300 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
isEnum : true ,
public : true ,
label : ( ) = > _ ( 'Synchronisation interval' ) ,
options : ( ) = > {
return {
0 : _ ( 'Disabled' ) ,
300 : _ ( '%d minutes' , 5 ) ,
600 : _ ( '%d minutes' , 10 ) ,
1800 : _ ( '%d minutes' , 30 ) ,
3600 : _ ( '%d hour' , 1 ) ,
43200 : _ ( '%d hours' , 12 ) ,
86400 : _ ( '%d hours' , 24 ) ,
} ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2021-03-29 10:35:39 +02:00
'sync.mobileWifiOnly' : {
value : false ,
type : SettingItemType . Bool ,
section : 'sync' ,
public : true ,
label : ( ) = > _ ( 'Synchronise only over WiFi connection' ) ,
storage : SettingStorage.File ,
appTypes : [ 'mobile' ] ,
} ,
2021-02-09 19:54:29 +02:00
noteVisiblePanes : { value : [ 'editor' , 'viewer' ] , type : SettingItemType . Array , storage : SettingStorage.File , public : false , appTypes : [ 'desktop' ] } ,
2020-10-09 19:35:46 +02:00
tagHeaderIsExpanded : { value : true , type : SettingItemType . Bool , public : false , appTypes : [ 'desktop' ] } ,
folderHeaderIsExpanded : { value : true , type : SettingItemType . Bool , public : false , appTypes : [ 'desktop' ] } ,
2021-02-09 19:54:29 +02:00
editor : { value : '' , type : SettingItemType . String , subType : 'file_path_and_args' , storage : SettingStorage.File , public : true , appTypes : [ 'cli' , 'desktop' ] , label : ( ) = > _ ( 'Text editor command' ) , description : ( ) = > _ ( 'The editor command (may include arguments) that will be used to open a note. If none is provided it will try to auto-detect the default editor.' ) } ,
'export.pdfPageSize' : { value : 'A4' , type : SettingItemType . String , advanced : true , storage : SettingStorage.File , isEnum : true , public : true , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Page size for PDF export' ) , options : ( ) = > {
2019-10-12 01:21:19 +02:00
return {
'A4' : _ ( 'A4' ) ,
'Letter' : _ ( 'Letter' ) ,
'A3' : _ ( 'A3' ) ,
'A5' : _ ( 'A5' ) ,
'Tabloid' : _ ( 'Tabloid' ) ,
'Legal' : _ ( 'Legal' ) ,
} ;
2020-02-05 00:09:34 +02:00
} } ,
2021-02-09 19:54:29 +02:00
'export.pdfPageOrientation' : { value : 'portrait' , type : SettingItemType . String , storage : SettingStorage.File , advanced : true , isEnum : true , public : true , appTypes : [ 'desktop' ] , label : ( ) = > _ ( 'Page orientation for PDF export' ) , options : ( ) = > {
2019-10-12 01:21:19 +02:00
return {
'portrait' : _ ( 'Portrait' ) ,
'landscape' : _ ( 'Landscape' ) ,
} ;
2020-02-05 00:09:34 +02:00
} } ,
2019-10-12 01:21:19 +02:00
2020-05-02 17:41:07 +02:00
'editor.keyboardMode' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2020-05-02 17:41:07 +02:00
public : true ,
appTypes : [ 'desktop' ] ,
isEnum : true ,
advanced : true ,
label : ( ) = > _ ( 'Keyboard Mode' ) ,
options : ( ) = > {
2020-11-12 21:13:28 +02:00
const output : any = { } ;
2020-05-02 17:41:07 +02:00
output [ '' ] = _ ( 'Default' ) ;
output [ 'emacs' ] = _ ( 'Emacs' ) ;
output [ 'vim' ] = _ ( 'Vim' ) ;
return output ;
} ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-02 17:41:07 +02:00
} ,
2019-07-29 15:43:53 +02:00
2020-11-19 19:14:44 +02:00
'editor.spellcheckBeta' : {
value : false ,
type : SettingItemType . Bool ,
public : true ,
appTypes : [ 'desktop' ] ,
label : ( ) = > 'Enable spell checking in Markdown editor? (WARNING BETA feature)' ,
description : ( ) = > 'Spell checker in the Markdown editor was previously unstable (cursor location was not stable, sometimes edits would not be saved or reflected in the viewer, etc.) however it appears to be more reliable now. If you notice any issue, please report it on GitHub or the Joplin Forum (Help -> Joplin Forum)' ,
} ,
2019-07-29 15:43:53 +02:00
'net.customCertificates' : {
value : '' ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . String ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2019-12-13 03:16:34 +02:00
advanced : true ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2021-01-22 02:31:10 +02:00
return [ SyncTargetRegistry . nameToId ( 'nextcloud' ) , SyncTargetRegistry . nameToId ( 'webdav' ) , SyncTargetRegistry . nameToId ( 'joplinServer' ) ] . indexOf ( settings [ 'sync.target' ] ) >= 0 ;
2019-07-29 15:43:53 +02:00
} ,
public : true ,
appTypes : [ 'desktop' , 'cli' ] ,
label : ( ) = > _ ( 'Custom TLS certificates' ) ,
description : ( ) = > _ ( 'Comma-separated list of paths to directories to load the certificates from, or path to individual cert files. For example: /my/cert_dir, /other/custom.pem. Note that if you make changes to the TLS settings, you must save your changes before clicking on "Check synchronisation configuration".' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
'net.ignoreTlsErrors' : {
value : false ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2019-12-13 03:16:34 +02:00
advanced : true ,
2019-07-29 15:43:53 +02:00
section : 'sync' ,
2020-11-12 21:13:28 +02:00
show : ( settings : any ) = > {
2021-04-25 10:50:52 +02:00
return ( shim . isNode ( ) || shim . mobilePlatform ( ) === 'android' ) &&
[ SyncTargetRegistry . nameToId ( 'nextcloud' ) , SyncTargetRegistry . nameToId ( 'webdav' ) , SyncTargetRegistry . nameToId ( 'joplinServer' ) ] . indexOf ( settings [ 'sync.target' ] ) >= 0 ;
2019-07-29 15:43:53 +02:00
} ,
public : true ,
2021-04-25 10:50:52 +02:00
appTypes : [ 'desktop' , 'cli' , 'mobile' ] ,
2019-07-29 15:43:53 +02:00
label : ( ) = > _ ( 'Ignore TLS certificate errors' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2019-01-09 19:25:44 +02:00
2020-03-25 12:50:45 +02:00
'sync.wipeOutFailSafe' : {
value : true ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Bool ,
2020-03-25 12:50:45 +02:00
advanced : true ,
public : true ,
section : 'sync' ,
label : ( ) = > _ ( 'Fail-safe' ) ,
description : ( ) = > _ ( 'Fail-safe: Do not wipe out local data when sync target is empty (often the result of a misconfiguration or bug)' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-03-25 12:50:45 +02:00
} ,
2019-09-25 20:40:04 +02:00
2021-02-09 19:54:29 +02:00
'api.token' : { value : null , type : SettingItemType . String , public : false , storage : SettingStorage.File } ,
'api.port' : { value : null , type : SettingItemType . Int , storage : SettingStorage.File , public : true , appTypes : [ 'cli' ] , description : ( ) = > _ ( 'Specify the port that should be used by the API server. If not set, a default will be used.' ) } ,
2018-12-10 02:39:31 +02:00
2020-10-09 19:35:46 +02:00
'resourceService.lastProcessedChangeId' : { value : 0 , type : SettingItemType . Int , public : false } ,
'searchEngine.lastProcessedChangeId' : { value : 0 , type : SettingItemType . Int , public : false } ,
'revisionService.lastProcessedChangeId' : { value : 0 , type : SettingItemType . Int , public : false } ,
2019-07-29 15:43:53 +02:00
2020-10-09 19:35:46 +02:00
'searchEngine.initialIndexingDone' : { value : false , type : SettingItemType . Bool , public : false } ,
2019-05-06 22:35:29 +02:00
2021-02-09 19:54:29 +02:00
'revisionService.enabled' : { section : 'revisionService' , storage : SettingStorage.File , value : true , type : SettingItemType . Bool , public : true , label : ( ) = > _ ( 'Enable note history' ) } ,
2019-07-29 15:43:53 +02:00
'revisionService.ttlDays' : {
section : 'revisionService' ,
value : 90 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2019-07-29 15:43:53 +02:00
public : true ,
minimum : 1 ,
maximum : 365 * 2 ,
step : 1 ,
2020-11-19 14:34:49 +02:00
unitLabel : ( value : number = null ) = > {
2019-07-29 15:43:53 +02:00
return value === null ? _ ( 'days' ) : _ ( '%d days' , value ) ;
} ,
label : ( ) = > _ ( 'Keep note history for' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2019-07-29 15:43:53 +02:00
} ,
2020-10-09 19:35:46 +02:00
'revisionService.intervalBetweenRevisions' : { section : 'revisionService' , value : 1000 * 60 * 10 , type : SettingItemType . Int , public : false } ,
'revisionService.oldNoteInterval' : { section : 'revisionService' , value : 1000 * 60 * 60 * 24 * 7 , type : SettingItemType . Int , public : false } ,
2019-05-06 22:35:29 +02:00
2020-10-09 19:35:46 +02:00
'welcome.wasBuilt' : { value : false , type : SettingItemType . Bool , public : false } ,
'welcome.enabled' : { value : true , type : SettingItemType . Bool , public : false } ,
2019-10-16 23:52:22 +02:00
2020-10-09 19:35:46 +02:00
'camera.type' : { value : 0 , type : SettingItemType . Int , public : false , appTypes : [ 'mobile' ] } ,
'camera.ratio' : { value : '4:3' , type : SettingItemType . String , public : false , appTypes : [ 'mobile' ] } ,
2020-02-12 14:41:32 +02:00
2021-02-09 19:54:29 +02:00
'spellChecker.enabled' : { value : true , type : SettingItemType . Bool , storage : SettingStorage.File , public : false } ,
'spellChecker.language' : { value : '' , type : SettingItemType . String , storage : SettingStorage.File , public : false } ,
2020-11-05 18:58:23 +02:00
2020-02-12 14:41:32 +02:00
windowContentZoomFactor : {
value : 100 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-02-12 14:41:32 +02:00
public : false ,
appTypes : [ 'desktop' ] ,
minimum : 30 ,
maximum : 300 ,
step : 10 ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-02-12 14:41:32 +02:00
} ,
2020-05-09 17:12:09 +02:00
'layout.folderList.factor' : {
value : 1 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-05-09 17:12:09 +02:00
section : 'appearance' ,
public : true ,
appTypes : [ 'cli' ] ,
label : ( ) = > _ ( 'Notebook list growth factor' ) ,
description : ( ) = >
_ ( 'The factor property sets how the item will grow or shrink ' +
'to fit the available space in its container with respect to the other items. ' +
'Thus an item with a factor of 2 will take twice as much space as an item with a factor of 1.' +
'Restart app to see changes.' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-09 17:12:09 +02:00
} ,
'layout.noteList.factor' : {
value : 1 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-05-09 17:12:09 +02:00
section : 'appearance' ,
public : true ,
appTypes : [ 'cli' ] ,
label : ( ) = > _ ( 'Note list growth factor' ) ,
description : ( ) = >
_ ( 'The factor property sets how the item will grow or shrink ' +
'to fit the available space in its container with respect to the other items. ' +
'Thus an item with a factor of 2 will take twice as much space as an item with a factor of 1.' +
'Restart app to see changes.' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-09 17:12:09 +02:00
} ,
'layout.note.factor' : {
value : 2 ,
2020-10-09 19:35:46 +02:00
type : SettingItemType . Int ,
2020-05-09 17:12:09 +02:00
section : 'appearance' ,
public : true ,
appTypes : [ 'cli' ] ,
label : ( ) = > _ ( 'Note area growth factor' ) ,
description : ( ) = >
_ ( 'The factor property sets how the item will grow or shrink ' +
'to fit the available space in its container with respect to the other items. ' +
'Thus an item with a factor of 2 will take twice as much space as an item with a factor of 1.' +
'Restart app to see changes.' ) ,
2021-02-09 19:54:29 +02:00
storage : SettingStorage.File ,
2020-05-09 17:12:09 +02:00
} ,
2021-04-24 20:23:33 +02:00
isSafeMode : {
value : false ,
type : SettingItemType . Bool ,
public : false ,
appTypes : [ 'desktop' ] ,
storage : SettingStorage.Database ,
} ,
2021-06-19 15:22:53 +02:00
'featureFlag.syncAccurateTimestamps' : {
value : false ,
type : SettingItemType . Bool ,
public : false ,
storage : SettingStorage.File ,
} ,
'featureFlag.syncMultiPut' : {
value : false ,
type : SettingItemType . Bool ,
public : false ,
storage : SettingStorage.File ,
} ,
2017-11-24 21:21:30 +02:00
} ;
2020-10-09 19:35:46 +02:00
this . metadata_ = Object . assign ( this . metadata_ , this . customMetadata_ ) ;
2017-11-24 21:21:30 +02:00
return this . metadata_ ;
}
2020-11-12 21:13:28 +02:00
private static validateKey ( key : string ) {
2020-10-09 19:35:46 +02:00
if ( ! key ) throw new Error ( 'Cannot register empty key' ) ;
if ( key . length > 128 ) throw new Error ( ` Key length cannot be longer than 128 characters: ${ key } ` ) ;
if ( ! key . match ( /^[a-zA-Z0-9_\-.]+$/ ) ) throw new Error ( ` Key must only contain characters /a-zA-Z0-9_-./ : ${ key } ` ) ;
}
2020-11-12 21:13:28 +02:00
static async registerSetting ( key : string , metadataItem : SettingItem ) {
2021-04-11 11:51:40 +02:00
if ( metadataItem . isEnum && ! metadataItem . options ) throw new Error ( 'The `options` property is required for enum types' ) ;
2020-10-09 19:35:46 +02:00
this . validateKey ( key ) ;
this . customMetadata_ [ key ] = metadataItem ;
// Clear cache
this . metadata_ = null ;
this . keys_ = null ;
// Reload the value from the database, if it was already present
const valueRow = await this . loadOne ( key ) ;
if ( valueRow ) {
this . cache_ . push ( {
key : key ,
value : this.formatValue ( key , valueRow . value ) ,
} ) ;
}
this . dispatch ( {
type : 'SETTING_UPDATE_ONE' ,
key : key ,
value : this.value ( key ) ,
} ) ;
}
2021-01-22 00:40:14 +02:00
static async registerSection ( name : string , source : SettingSectionSource , section : SettingSection ) {
this . customSections_ [ name ] = { . . . section , name : name , source : source } ;
2020-10-09 19:35:46 +02:00
}
2020-11-12 21:13:28 +02:00
static settingMetadata ( key : string ) : SettingItem {
2017-11-24 21:21:30 +02:00
const metadata = this . metadata ( ) ;
2019-09-19 23:51:18 +02:00
if ( ! ( key in metadata ) ) throw new Error ( ` Unknown key: ${ key } ` ) ;
2020-03-14 01:46:14 +02:00
const output = Object . assign ( { } , metadata [ key ] ) ;
2017-05-12 22:17:23 +02:00
output . key = key ;
return output ;
}
2021-05-03 12:55:38 +02:00
// Resets the key to its default value.
public static resetKey ( key : string ) {
const md = this . settingMetadata ( key ) ;
this . setValue ( key , md . value ) ;
}
public static keyExists ( key : string ) {
2017-11-24 21:21:30 +02:00
return key in this . metadata ( ) ;
2017-10-30 02:29:10 +02:00
}
2020-11-12 21:13:28 +02:00
static keyDescription ( key : string , appType : string = null ) {
2018-03-02 20:16:48 +02:00
const md = this . settingMetadata ( key ) ;
if ( ! md . description ) return null ;
return md . description ( appType ) ;
}
2020-11-12 21:13:28 +02:00
static isSecureKey ( key : string ) {
2020-06-03 18:07:50 +02:00
return this . metadata ( ) [ key ] && this . metadata ( ) [ key ] . secure === true ;
}
2020-11-12 21:13:28 +02:00
static keys ( publicOnly : boolean = false , appType : string = null , options : KeysOptions = null ) {
2020-06-03 18:07:50 +02:00
options = Object . assign ( { } , {
secureOnly : false ,
} , options ) ;
2017-08-22 19:57:35 +02:00
if ( ! this . keys_ ) {
2017-11-24 21:21:30 +02:00
const metadata = this . metadata ( ) ;
2017-08-22 19:57:35 +02:00
this . keys_ = [ ] ;
2020-03-14 01:46:14 +02:00
for ( const n in metadata ) {
2017-11-24 21:21:30 +02:00
if ( ! metadata . hasOwnProperty ( n ) ) continue ;
2017-08-22 19:57:35 +02:00
this . keys_ . push ( n ) ;
}
2017-05-16 23:46:21 +02:00
}
2020-06-03 18:07:50 +02:00
if ( appType || publicOnly || options . secureOnly ) {
2020-03-14 01:46:14 +02:00
const output = [ ] ;
2017-08-22 19:57:35 +02:00
for ( let i = 0 ; i < this . keys_ . length ; i ++ ) {
const md = this . settingMetadata ( this . keys_ [ i ] ) ;
if ( publicOnly && ! md . public ) continue ;
if ( appType && md . appTypes && md . appTypes . indexOf ( appType ) < 0 ) continue ;
2020-06-03 18:07:50 +02:00
if ( options . secureOnly && ! md . secure ) continue ;
2017-08-22 19:57:35 +02:00
output . push ( md . key ) ;
}
return output ;
} else {
return this . keys_ ;
2017-06-27 22:16:03 +02:00
}
}
2020-11-12 21:13:28 +02:00
static isPublic ( key : string ) {
2017-08-22 19:57:35 +02:00
return this . keys ( true ) . indexOf ( key ) >= 0 ;
2017-07-31 22:51:24 +02:00
}
2020-06-03 18:07:50 +02:00
// Low-level method to load a setting directly from the database. Should not be used in most cases.
2021-06-19 16:56:37 +02:00
public static async loadOne ( key : string ) : Promise < CacheItem > {
2021-02-09 19:54:29 +02:00
if ( this . keyStorage ( key ) === SettingStorage . File ) {
const fromFile = await this . fileHandler . load ( ) ;
2021-06-19 16:56:37 +02:00
return {
key ,
value : fromFile [ key ] ,
} ;
} else if ( this . settingMetadata ( key ) . secure ) {
return {
key ,
value : await this . keychainService ( ) . password ( ` setting. ${ key } ` ) ,
} ;
2021-02-09 19:54:29 +02:00
} else {
return this . modelSelectOne ( 'SELECT * FROM settings WHERE key = ?' , [ key ] ) ;
}
2020-06-03 18:07:50 +02:00
}
2017-05-12 22:17:23 +02:00
static load() {
2017-07-26 19:49:01 +02:00
this . cancelScheduleSave ( ) ;
2021-01-09 00:20:59 +02:00
this . cancelScheduleChangeEvent ( ) ;
2017-05-12 22:17:23 +02:00
this . cache_ = [ ] ;
2021-02-09 19:54:29 +02:00
return this . modelSelectAll ( 'SELECT * FROM settings' ) . then ( async ( rows : CacheItem [ ] ) = > {
2017-07-26 20:36:16 +02:00
this . cache_ = [ ] ;
2017-07-24 22:36:49 +02:00
2021-02-09 19:54:29 +02:00
const pushItemsToCache = ( items : CacheItem [ ] ) = > {
2020-06-03 18:07:50 +02:00
for ( let i = 0 ; i < items . length ; i ++ ) {
const c = items [ i ] ;
if ( ! this . keyExists ( c . key ) ) continue ;
2017-07-26 20:36:16 +02:00
2020-06-03 18:07:50 +02:00
c . value = this . formatValue ( c . key , c . value ) ;
c . value = this . filterValue ( c . key , c . value ) ;
2017-07-25 23:55:26 +02:00
2020-06-03 18:07:50 +02:00
this . cache_ . push ( c ) ;
}
} ;
// Keys in the database takes precedence over keys in the keychain because
// they are more likely to be up to date (saving to keychain can fail, but
// saving to database shouldn't). When the keychain works, the secure keys
// are deleted from the database and transfered to the keychain in saveAll().
2020-11-12 21:13:28 +02:00
const rowKeys = rows . map ( ( r : any ) = > r . key ) ;
2020-06-03 18:07:50 +02:00
const secureKeys = this . keys ( false , null , { secureOnly : true } ) ;
2021-02-09 19:54:29 +02:00
const secureItems : CacheItem [ ] = [ ] ;
2020-06-03 18:07:50 +02:00
for ( const key of secureKeys ) {
if ( rowKeys . includes ( key ) ) continue ;
const password = await this . keychainService ( ) . password ( ` setting. ${ key } ` ) ;
if ( password ) {
secureItems . push ( {
key : key ,
value : password ,
} ) ;
}
2017-07-24 22:36:49 +02:00
}
2017-07-26 19:49:01 +02:00
2021-02-09 19:54:29 +02:00
const itemsFromFile : CacheItem [ ] = [ ] ;
if ( this . canUseFileStorage ( ) ) {
const fromFile = await this . fileHandler . load ( ) ;
for ( const k of Object . keys ( fromFile ) ) {
itemsFromFile . push ( {
key : k ,
2021-06-16 19:22:32 +02:00
value : fromFile [ k ] ,
2021-02-09 19:54:29 +02:00
} ) ;
}
}
2020-06-03 18:07:50 +02:00
pushItemsToCache ( rows ) ;
pushItemsToCache ( secureItems ) ;
2021-02-09 19:54:29 +02:00
pushItemsToCache ( itemsFromFile ) ;
2020-06-03 18:07:50 +02:00
2017-10-21 18:53:43 +02:00
this . dispatchUpdateAll ( ) ;
} ) ;
}
2021-02-09 19:54:29 +02:00
private static canUseFileStorage ( ) : boolean {
return ! shim . mobilePlatform ( ) ;
}
private static keyStorage ( key : string ) : SettingStorage {
if ( ! this . canUseFileStorage ( ) ) return SettingStorage . Database ;
const md = this . settingMetadata ( key ) ;
return md . storage || SettingStorage . Database ;
}
2017-11-24 01:10:55 +02:00
static toPlainObject() {
2017-10-21 18:53:43 +02:00
const keys = this . keys ( ) ;
2020-11-12 21:13:28 +02:00
const keyToValues : any = { } ;
2017-10-21 18:53:43 +02:00
for ( let i = 0 ; i < keys . length ; i ++ ) {
keyToValues [ keys [ i ] ] = this . value ( keys [ i ] ) ;
}
2017-11-24 01:10:55 +02:00
return keyToValues ;
}
2017-07-26 19:49:01 +02:00
2017-11-24 01:10:55 +02:00
static dispatchUpdateAll() {
2017-10-21 18:53:43 +02:00
this . dispatch ( {
2017-11-08 23:22:24 +02:00
type : 'SETTING_UPDATE_ALL' ,
2017-11-24 01:10:55 +02:00
settings : this.toPlainObject ( ) ,
2017-05-12 22:17:23 +02:00
} ) ;
}
2020-11-12 21:13:28 +02:00
static setConstant ( key : string , value : any ) {
2019-09-19 23:51:18 +02:00
if ( ! ( key in this . constants_ ) ) throw new Error ( ` Unknown constant key: ${ key } ` ) ;
2021-05-13 18:57:37 +02:00
( this . constants_ as any ) [ key ] = value ;
2017-06-24 20:51:43 +02:00
}
2021-05-03 12:55:38 +02:00
public static setValue ( key : string , value : any ) {
2017-06-19 20:58:49 +02:00
if ( ! this . cache_ ) throw new Error ( 'Settings have not been initialized!' ) ;
2017-07-31 22:51:24 +02:00
value = this . formatValue ( key , value ) ;
2018-05-08 12:29:25 +02:00
value = this . filterValue ( key , value ) ;
2018-04-15 17:50:39 +02:00
2017-05-12 22:17:23 +02:00
for ( let i = 0 ; i < this . cache_ . length ; i ++ ) {
2020-03-14 01:46:14 +02:00
const c = this . cache_ [ i ] ;
2017-07-24 20:58:11 +02:00
if ( c . key == key ) {
const md = this . settingMetadata ( key ) ;
2017-07-25 23:55:26 +02:00
if ( md . isEnum === true ) {
2017-07-24 20:58:11 +02:00
if ( ! this . isAllowedEnumOption ( key , value ) ) {
throw new Error ( _ ( 'Invalid option value: "%s". Possible values are: %s.' , value , this . enumOptionsDoc ( key ) ) ) ;
}
}
if ( c . value === value ) return ;
2017-07-25 23:55:26 +02:00
2021-01-09 00:20:59 +02:00
this . changedKeys_ . push ( key ) ;
2018-01-17 23:17:40 +02:00
// Don't log this to prevent sensitive info (passwords, auth tokens...) to end up in logs
// this.logger().info('Setting: ' + key + ' = ' + c.value + ' => ' + value);
2017-07-25 23:55:26 +02:00
2019-07-29 15:43:53 +02:00
if ( 'minimum' in md && value < md . minimum ) value = md . minimum ;
if ( 'maximum' in md && value > md . maximum ) value = md . maximum ;
2019-02-16 03:12:43 +02:00
2017-11-14 20:02:58 +02:00
c . value = value ;
2017-07-26 19:49:01 +02:00
this . dispatch ( {
2017-11-08 23:22:24 +02:00
type : 'SETTING_UPDATE_ONE' ,
2017-07-26 19:49:01 +02:00
key : key ,
value : c.value ,
} ) ;
this . scheduleSave ( ) ;
2021-01-09 00:20:59 +02:00
this . scheduleChangeEvent ( ) ;
2017-05-12 22:17:23 +02:00
return ;
}
}
2017-07-25 23:55:26 +02:00
this . cache_ . push ( {
key : key ,
value : this.formatValue ( key , value ) ,
} ) ;
2017-07-26 19:49:01 +02:00
this . dispatch ( {
2017-11-08 23:22:24 +02:00
type : 'SETTING_UPDATE_ONE' ,
2017-07-26 19:49:01 +02:00
key : key ,
value : this.formatValue ( key , value ) ,
} ) ;
2021-01-09 00:20:59 +02:00
this . changedKeys_ . push ( key ) ;
2017-07-26 19:49:01 +02:00
this . scheduleSave ( ) ;
2021-01-09 00:20:59 +02:00
this . scheduleChangeEvent ( ) ;
2017-07-26 19:49:01 +02:00
}
2020-11-12 21:13:28 +02:00
static incValue ( key : string , inc : any ) {
2020-02-12 14:41:32 +02:00
return this . setValue ( key , this . value ( key ) + inc ) ;
}
2020-11-12 21:13:28 +02:00
static toggle ( key : string ) {
2020-05-02 17:41:07 +02:00
return this . setValue ( key , ! this . value ( key ) ) ;
}
2020-11-12 21:13:28 +02:00
static objectValue ( settingKey : string , objectKey : string , defaultValue : any = null ) {
2020-10-09 19:35:46 +02:00
const o = this . value ( settingKey ) ;
if ( ! o || ! ( objectKey in o ) ) return defaultValue ;
return o [ objectKey ] ;
}
2020-11-12 21:13:28 +02:00
static setObjectValue ( settingKey : string , objectKey : string , value : any ) {
2017-12-28 21:57:21 +02:00
let o = this . value ( settingKey ) ;
2017-12-17 21:51:45 +02:00
if ( typeof o !== 'object' ) o = { } ;
o [ objectKey ] = value ;
this . setValue ( settingKey , o ) ;
}
2020-11-12 21:13:28 +02:00
static deleteObjectValue ( settingKey : string , objectKey : string ) {
2017-12-17 21:51:45 +02:00
const o = this . value ( settingKey ) ;
if ( typeof o !== 'object' ) return ;
delete o [ objectKey ] ;
this . setValue ( settingKey , o ) ;
}
2020-06-03 18:07:50 +02:00
static async deleteKeychainPasswords() {
const secureKeys = this . keys ( false , null , { secureOnly : true } ) ;
for ( const key of secureKeys ) {
await this . keychainService ( ) . deletePassword ( ` setting. ${ key } ` ) ;
}
}
2020-11-12 21:13:28 +02:00
static valueToString ( key : string , value : any ) {
2017-07-26 19:49:01 +02:00
const md = this . settingMetadata ( key ) ;
value = this . formatValue ( key , value ) ;
2020-10-09 19:35:46 +02:00
if ( md . type == SettingItemType . Int ) return value . toFixed ( 0 ) ;
if ( md . type == SettingItemType . Bool ) return value ? '1' : '0' ;
if ( md . type == SettingItemType . Array ) return value ? JSON . stringify ( value ) : '[]' ;
if ( md . type == SettingItemType . Object ) return value ? JSON . stringify ( value ) : '{}' ;
if ( md . type == SettingItemType . String ) return value ? ` ${ value } ` : '' ;
2018-01-07 21:20:10 +02:00
2019-09-19 23:51:18 +02:00
throw new Error ( ` Unhandled value type: ${ md . type } ` ) ;
2017-05-12 22:17:23 +02:00
}
2020-11-12 21:13:28 +02:00
static filterValue ( key : string , value : any ) {
2018-05-08 12:29:25 +02:00
const md = this . settingMetadata ( key ) ;
return md . filter ? md . filter ( value ) : value ;
}
2020-11-12 21:13:28 +02:00
static formatValue ( key : string , value : any ) {
2017-07-25 23:55:26 +02:00
const md = this . settingMetadata ( key ) ;
2017-11-12 19:02:20 +02:00
2020-10-09 19:35:46 +02:00
if ( md . type == SettingItemType . Int ) return ! value ? 0 : Math.floor ( Number ( value ) ) ;
2017-11-12 19:02:20 +02:00
2020-10-09 19:35:46 +02:00
if ( md . type == SettingItemType . Bool ) {
2017-07-26 23:07:27 +02:00
if ( typeof value === 'string' ) {
value = value . toLowerCase ( ) ;
if ( value === 'true' ) return true ;
if ( value === 'false' ) return false ;
value = Number ( value ) ;
}
2017-07-26 19:49:01 +02:00
return ! ! value ;
}
2017-11-12 19:02:20 +02:00
2020-10-09 19:35:46 +02:00
if ( md . type === SettingItemType . Array ) {
2017-11-14 20:02:58 +02:00
if ( ! value ) return [ ] ;
2017-11-12 19:02:20 +02:00
if ( Array . isArray ( value ) ) return value ;
if ( typeof value === 'string' ) return JSON . parse ( value ) ;
return [ ] ;
}
2020-10-09 19:35:46 +02:00
if ( md . type === SettingItemType . Object ) {
2017-11-14 20:02:58 +02:00
if ( ! value ) return { } ;
if ( typeof value === 'object' ) return value ;
if ( typeof value === 'string' ) return JSON . parse ( value ) ;
return { } ;
}
2020-10-09 19:35:46 +02:00
if ( md . type === SettingItemType . String ) {
2018-01-07 21:20:10 +02:00
if ( ! value ) return '' ;
2019-09-19 23:51:18 +02:00
return ` ${ value } ` ;
2018-01-07 21:20:10 +02:00
}
2019-09-19 23:51:18 +02:00
throw new Error ( ` Unhandled value type: ${ md . type } ` ) ;
2017-07-25 20:57:06 +02:00
}
2020-11-12 21:13:28 +02:00
static value ( key : string ) {
2017-12-14 21:39:13 +02:00
// Need to copy arrays and objects since in setValue(), the old value and new one is compared
// with strict equality and the value is updated only if changed. However if the caller acquire
// and object and change a key, the objects will be detected as equal. By returning a copy
// we avoid this problem.
2020-11-12 21:13:28 +02:00
function copyIfNeeded ( value : any ) {
2018-01-07 21:20:10 +02:00
if ( value === null || value === undefined ) return value ;
2017-12-14 21:39:13 +02:00
if ( Array . isArray ( value ) ) return value . slice ( ) ;
if ( typeof value === 'object' ) return Object . assign ( { } , value ) ;
return value ;
}
2017-07-07 00:15:31 +02:00
if ( key in this . constants_ ) {
2021-05-13 18:57:37 +02:00
const v = ( this . constants_ as any ) [ key ] ;
2017-11-20 00:08:58 +02:00
const output = typeof v === 'function' ? v ( ) : v ;
2020-06-03 18:07:50 +02:00
if ( output == 'SET_ME' ) throw new Error ( ` SET_ME constant has not been set: ${ key } ` ) ;
2017-07-07 00:15:31 +02:00
return output ;
}
2017-06-24 20:51:43 +02:00
2017-06-19 20:58:49 +02:00
if ( ! this . cache_ ) throw new Error ( 'Settings have not been initialized!' ) ;
2017-05-12 22:17:23 +02:00
for ( let i = 0 ; i < this . cache_ . length ; i ++ ) {
if ( this . cache_ [ i ] . key == key ) {
2017-12-14 21:39:13 +02:00
return copyIfNeeded ( this . cache_ [ i ] . value ) ;
2017-05-12 22:17:23 +02:00
}
}
2017-07-25 23:55:26 +02:00
const md = this . settingMetadata ( key ) ;
2017-12-14 21:39:13 +02:00
return copyIfNeeded ( md . value ) ;
2017-05-12 22:17:23 +02:00
}
2020-11-12 21:13:28 +02:00
static isEnum ( key : string ) {
2017-07-24 20:58:11 +02:00
const md = this . settingMetadata ( key ) ;
2017-07-25 23:55:26 +02:00
return md . isEnum === true ;
2017-07-24 20:58:11 +02:00
}
2020-11-12 21:13:28 +02:00
static enumOptionValues ( key : string ) {
2017-07-24 20:58:11 +02:00
const options = this . enumOptions ( key ) ;
2020-03-14 01:46:14 +02:00
const output = [ ] ;
for ( const n in options ) {
2017-07-24 20:58:11 +02:00
if ( ! options . hasOwnProperty ( n ) ) continue ;
output . push ( n ) ;
}
return output ;
}
2020-11-12 21:13:28 +02:00
static enumOptionLabel ( key : string , value : any ) {
2017-07-24 20:58:11 +02:00
const options = this . enumOptions ( key ) ;
2020-03-14 01:46:14 +02:00
for ( const n in options ) {
2017-07-24 20:58:11 +02:00
if ( n == value ) return options [ n ] ;
}
return '' ;
}
2020-11-12 21:13:28 +02:00
static enumOptions ( key : string ) {
2017-11-24 21:21:30 +02:00
const metadata = this . metadata ( ) ;
2019-09-19 23:51:18 +02:00
if ( ! metadata [ key ] ) throw new Error ( ` Unknown key: ${ key } ` ) ;
if ( ! metadata [ key ] . options ) throw new Error ( ` No options for: ${ key } ` ) ;
2017-11-24 21:21:30 +02:00
return metadata [ key ] . options ( ) ;
2017-07-24 20:58:11 +02:00
}
2020-11-12 21:13:28 +02:00
static enumOptionsDoc ( key : string , templateString : string = null ) {
2017-10-20 00:02:13 +02:00
if ( templateString === null ) templateString = '%s: %s' ;
2017-07-24 20:58:11 +02:00
const options = this . enumOptions ( key ) ;
2020-03-14 01:46:14 +02:00
const output = [ ] ;
for ( const n in options ) {
2017-07-24 20:58:11 +02:00
if ( ! options . hasOwnProperty ( n ) ) continue ;
2017-10-20 00:02:13 +02:00
output . push ( sprintf ( templateString , n , options [ n ] ) ) ;
2017-07-24 20:58:11 +02:00
}
return output . join ( ', ' ) ;
}
2020-11-12 21:13:28 +02:00
static isAllowedEnumOption ( key : string , value : any ) {
2017-07-24 20:58:11 +02:00
const options = this . enumOptions ( key ) ;
return ! ! options [ value ] ;
}
2018-02-06 20:59:36 +02:00
// For example, if settings is:
// { sync.5.path: 'http://example', sync.5.username: 'testing' }
// and baseKey is 'sync.5', the function will return
// { path: 'http://example', username: 'testing' }
2020-11-12 21:13:28 +02:00
static subValues ( baseKey : string , settings : any , options : any = null ) {
2019-12-29 19:58:40 +02:00
const includeBaseKeyInName = ! ! options && ! ! options . includeBaseKeyInName ;
2020-11-12 21:13:28 +02:00
const output : any = { } ;
2020-03-14 01:46:14 +02:00
for ( const key in settings ) {
2018-02-06 20:59:36 +02:00
if ( ! settings . hasOwnProperty ( key ) ) continue ;
if ( key . indexOf ( baseKey ) === 0 ) {
2019-12-29 19:58:40 +02:00
const subKey = includeBaseKeyInName ? key : key.substr ( baseKey . length + 1 ) ;
2018-02-06 20:59:36 +02:00
output [ subKey ] = settings [ key ] ;
2017-05-16 23:46:21 +02:00
}
}
return output ;
}
2021-05-03 12:55:38 +02:00
public static async saveAll() {
2020-06-03 18:07:50 +02:00
if ( Setting . autoSaveEnabled && ! this . saveTimeoutId_ ) return Promise . resolve ( ) ;
2017-05-19 21:12:09 +02:00
2021-01-21 11:57:53 +02:00
this . logger ( ) . debug ( 'Saving settings...' ) ;
2020-10-09 19:35:46 +02:00
shim . clearTimeout ( this . saveTimeoutId_ ) ;
2017-07-26 19:49:01 +02:00
this . saveTimeoutId_ = null ;
2017-05-19 21:12:09 +02:00
2020-10-09 19:35:46 +02:00
const keys = this . keys ( ) ;
2021-02-09 19:54:29 +02:00
const valuesForFile : SettingValues = { } ;
2020-03-14 01:46:14 +02:00
const queries = [ ] ;
2020-10-09 19:35:46 +02:00
queries . push ( ` DELETE FROM settings WHERE key IN (" ${ keys . join ( '","' ) } ") ` ) ;
2017-06-11 23:11:14 +02:00
for ( let i = 0 ; i < this . cache_ . length ; i ++ ) {
2020-03-14 01:46:14 +02:00
const s = Object . assign ( { } , this . cache_ [ i ] ) ;
2021-02-09 19:54:29 +02:00
const valueAsString = this . valueToString ( s . key , s . value ) ;
2020-06-03 18:07:50 +02:00
if ( this . isSecureKey ( s . key ) ) {
// We need to be careful here because there's a bug in the macOS keychain that can
// make it fail to save a password. https://github.com/desktop/desktop/issues/3263
// So we try to set it and if it fails, we set it on the database instead. This is not
// ideal because they won't be crypted, but better than losing all the user's passwords.
// The passwords would be set again on the keychain once it starts working again (probably
// after the user switch their computer off and on again).
//
// Also we don't control what happens on the keychain - the values can be edited or deleted
// outside the application. For that reason, we rewrite it every time the values are saved,
// even if, internally, they haven't changed.
// As an optimisation, we check if the value exists on the keychain before writing it again.
try {
const passwordName = ` setting. ${ s . key } ` ;
const currentValue = await this . keychainService ( ) . password ( passwordName ) ;
2021-02-09 19:54:29 +02:00
if ( currentValue !== valueAsString ) {
const wasSet = await this . keychainService ( ) . setPassword ( passwordName , valueAsString ) ;
2020-06-03 18:07:50 +02:00
if ( wasSet ) continue ;
2020-10-20 17:37:14 +02:00
} else {
// The value is already in the keychain - so nothing to do
// Make sure to `continue` here otherwise it will save the password
// in clear text in the database.
continue ;
2020-06-03 18:07:50 +02:00
}
} catch ( error ) {
this . logger ( ) . error ( ` Could not set setting on the keychain. Will be saved to database instead: ${ s . key } : ` , error ) ;
}
}
2021-02-09 19:54:29 +02:00
if ( this . keyStorage ( s . key ) === SettingStorage . File ) {
valuesForFile [ s . key ] = s . value ;
} else {
queries . push ( Database . insertQuery ( this . tableName ( ) , {
key : s.key ,
value : valueAsString ,
} ) ) ;
}
2017-06-11 23:11:14 +02:00
}
2018-02-15 19:12:09 +02:00
await BaseModel . db ( ) . transactionExecBatch ( queries ) ;
2018-04-15 17:50:39 +02:00
2021-02-09 19:54:29 +02:00
if ( this . canUseFileStorage ( ) ) await this . fileHandler . save ( valuesForFile ) ;
2021-01-21 11:57:53 +02:00
this . logger ( ) . debug ( 'Settings have been saved.' ) ;
2017-05-19 21:12:09 +02:00
}
2021-01-09 00:20:59 +02:00
static scheduleChangeEvent() {
if ( this . changeEventTimeoutId_ ) shim . clearTimeout ( this . changeEventTimeoutId_ ) ;
this . changeEventTimeoutId_ = shim . setTimeout ( ( ) = > {
this . emitScheduledChangeEvent ( ) ;
} , 1000 ) ;
}
static cancelScheduleChangeEvent() {
if ( this . changeEventTimeoutId_ ) shim . clearTimeout ( this . changeEventTimeoutId_ ) ;
this . changeEventTimeoutId_ = null ;
}
public static emitScheduledChangeEvent() {
if ( ! this . changeEventTimeoutId_ ) return ;
shim . clearTimeout ( this . changeEventTimeoutId_ ) ;
this . changeEventTimeoutId_ = null ;
if ( ! this . changedKeys_ . length ) {
// Sanity check - shouldn't happen
this . logger ( ) . warn ( 'Trying to dispatch a change event without any changed keys' ) ;
return ;
}
const keys = this . changedKeys_ . slice ( ) ;
this . changedKeys_ = [ ] ;
eventManager . emit ( 'settingsChange' , { keys } ) ;
}
2017-07-26 19:49:01 +02:00
static scheduleSave() {
2018-02-15 19:12:09 +02:00
if ( ! Setting . autoSaveEnabled ) return ;
2020-10-09 19:35:46 +02:00
if ( this . saveTimeoutId_ ) shim . clearTimeout ( this . saveTimeoutId_ ) ;
2017-05-19 21:12:09 +02:00
2020-10-09 19:35:46 +02:00
this . saveTimeoutId_ = shim . setTimeout ( async ( ) = > {
2020-06-03 18:07:50 +02:00
try {
await this . saveAll ( ) ;
} catch ( error ) {
this . logger ( ) . error ( 'Could not save settings' , error ) ;
}
2017-05-12 22:17:23 +02:00
} , 500 ) ;
}
2017-07-26 19:49:01 +02:00
static cancelScheduleSave() {
2020-10-09 19:35:46 +02:00
if ( this . saveTimeoutId_ ) shim . clearTimeout ( this . saveTimeoutId_ ) ;
2017-07-26 19:49:01 +02:00
this . saveTimeoutId_ = null ;
2017-06-19 21:26:27 +02:00
}
2020-11-12 21:13:28 +02:00
static publicSettings ( appType : string ) {
2017-07-23 20:26:50 +02:00
if ( ! appType ) throw new Error ( 'appType is required' ) ;
2017-11-24 21:21:30 +02:00
const metadata = this . metadata ( ) ;
2020-11-12 21:13:28 +02:00
const output : any = { } ;
2020-03-14 01:46:14 +02:00
for ( const key in metadata ) {
2017-11-24 21:21:30 +02:00
if ( ! metadata . hasOwnProperty ( key ) ) continue ;
2020-03-14 01:46:14 +02:00
const s = Object . assign ( { } , metadata [ key ] ) ;
2017-07-23 20:26:50 +02:00
if ( ! s . public ) continue ;
if ( s . appTypes && s . appTypes . indexOf ( appType ) < 0 ) continue ;
s . value = this . value ( key ) ;
output [ key ] = s ;
}
return output ;
}
2020-11-12 21:13:28 +02:00
static typeToString ( typeId : number ) {
2020-10-09 19:35:46 +02:00
if ( typeId === SettingItemType . Int ) return 'int' ;
if ( typeId === SettingItemType . String ) return 'string' ;
if ( typeId === SettingItemType . Bool ) return 'bool' ;
if ( typeId === SettingItemType . Array ) return 'array' ;
if ( typeId === SettingItemType . Object ) return 'object' ;
throw new Error ( ` Invalid type ID: ${ typeId } ` ) ;
2017-10-20 00:02:13 +02:00
}
2021-01-22 00:40:14 +02:00
private static sectionSource ( sectionName : string ) : SettingSectionSource {
if ( this . customSections_ [ sectionName ] ) return this . customSections_ [ sectionName ] . source || SettingSectionSource . Default ;
return SettingSectionSource . Default ;
}
2020-11-12 21:13:28 +02:00
static groupMetadatasBySections ( metadatas : SettingItem [ ] ) {
2020-03-14 01:46:14 +02:00
const sections = [ ] ;
2020-11-12 21:13:28 +02:00
const generalSection : any = { name : 'general' , metadatas : [ ] } ;
const nameToSections : any = { } ;
2019-01-28 01:15:56 +02:00
nameToSections [ 'general' ] = generalSection ;
sections . push ( generalSection ) ;
for ( let i = 0 ; i < metadatas . length ; i ++ ) {
const md = metadatas [ i ] ;
if ( ! md . section ) {
generalSection . metadatas . push ( md ) ;
} else {
if ( ! nameToSections [ md . section ] ) {
2021-01-22 00:40:14 +02:00
nameToSections [ md . section ] = {
name : md.section ,
metadatas : [ ] ,
source : this.sectionSource ( md . section ) ,
} ;
2019-01-28 01:15:56 +02:00
sections . push ( nameToSections [ md . section ] ) ;
}
nameToSections [ md . section ] . metadatas . push ( md ) ;
}
}
2020-10-09 19:35:46 +02:00
2021-01-22 00:40:14 +02:00
// for (const name in this.customSections_) {
// nameToSections[name] = {
// name: name,
// source: this.customSections_[name].source,
// metadatas: [],
// };
// }
2020-10-09 19:35:46 +02:00
2019-07-29 15:43:53 +02:00
return sections ;
2019-01-28 01:15:56 +02:00
}
2020-11-12 21:13:28 +02:00
static sectionNameToLabel ( name : string ) {
2019-01-28 01:15:56 +02:00
if ( name === 'general' ) return _ ( 'General' ) ;
if ( name === 'sync' ) return _ ( 'Synchronisation' ) ;
if ( name === 'appearance' ) return _ ( 'Appearance' ) ;
if ( name === 'note' ) return _ ( 'Note' ) ;
2020-10-09 19:35:46 +02:00
if ( name === 'markdownPlugins' ) return _ ( 'Markdown' ) ;
2021-01-07 18:30:53 +02:00
if ( name === 'plugins' ) return _ ( 'Plugins' ) ;
2019-01-28 01:15:56 +02:00
if ( name === 'application' ) return _ ( 'Application' ) ;
2019-05-06 22:35:29 +02:00
if ( name === 'revisionService' ) return _ ( 'Note History' ) ;
2019-09-11 01:53:01 +02:00
if ( name === 'encryption' ) return _ ( 'Encryption' ) ;
if ( name === 'server' ) return _ ( 'Web Clipper' ) ;
2020-09-06 14:00:25 +02:00
if ( name === 'keymap' ) return _ ( 'Keyboard Shortcuts' ) ;
2020-10-09 19:35:46 +02:00
if ( this . customSections_ [ name ] && this . customSections_ [ name ] . label ) return this . customSections_ [ name ] . label ;
2019-09-11 01:53:01 +02:00
return name ;
}
2020-11-12 21:13:28 +02:00
static sectionDescription ( name : string ) {
2020-10-09 19:35:46 +02:00
if ( name === 'markdownPlugins' ) return _ ( 'These plugins enhance the Markdown renderer with additional features. Please note that, while these features might be useful, they are not standard Markdown and thus most of them will only work in Joplin. Additionally, some of them are *incompatible* with the WYSIWYG editor. If you open a note that uses one of these plugins in that editor, you will lose the plugin formatting. It is indicated below which plugins are compatible or not with the WYSIWYG editor.' ) ;
2020-04-10 19:33:09 +02:00
if ( name === 'general' ) return _ ( 'Notes and settings are stored in: %s' , toSystemSlashes ( this . value ( 'profileDir' ) , process . platform ) ) ;
2020-10-09 19:35:46 +02:00
if ( this . customSections_ [ name ] && this . customSections_ [ name ] . description ) return this . customSections_ [ name ] . description ;
2020-04-10 19:33:09 +02:00
return '' ;
}
2020-11-12 21:13:28 +02:00
static sectionNameToIcon ( name : string ) {
2020-09-15 15:01:07 +02:00
if ( name === 'general' ) return 'icon-general' ;
if ( name === 'sync' ) return 'icon-sync' ;
if ( name === 'appearance' ) return 'icon-appearance' ;
if ( name === 'note' ) return 'icon-note' ;
if ( name === 'plugins' ) return 'icon-plugins' ;
2020-10-09 19:35:46 +02:00
if ( name === 'markdownPlugins' ) return 'fab fa-markdown' ;
2020-09-15 15:01:07 +02:00
if ( name === 'application' ) return 'icon-application' ;
if ( name === 'revisionService' ) return 'icon-note-history' ;
if ( name === 'encryption' ) return 'icon-encryption' ;
2020-05-17 16:34:42 +02:00
if ( name === 'server' ) return 'far fa-hand-scissors' ;
2020-09-06 14:00:25 +02:00
if ( name === 'keymap' ) return 'fa fa-keyboard' ;
2020-10-09 19:35:46 +02:00
if ( this . customSections_ [ name ] && this . customSections_ [ name ] . iconName ) return this . customSections_ [ name ] . iconName ;
2021-02-07 14:59:58 +02:00
return 'fas fa-cog' ;
2019-01-28 01:15:56 +02:00
}
2020-11-12 21:13:28 +02:00
static appTypeToLabel ( name : string ) {
2019-02-23 17:53:14 +02:00
// Not translated for now because only used on Welcome notes (which are not translated)
if ( name === 'cli' ) return 'CLI' ;
return name [ 0 ] . toUpperCase ( ) + name . substr ( 1 ) . toLowerCase ( ) ;
}
2017-05-12 22:17:23 +02:00
}
2020-10-09 19:35:46 +02:00
export default Setting ;