-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Setting.ts
2898 lines (2577 loc) · 103 KB
/
Setting.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import shim from '../shim';
import { _, supportedLocalesToLanguages, defaultLocale } from '../locale';
import eventManager, { EventName } from '../eventManager';
import BaseModel from '../BaseModel';
import Database from '../database';
import SyncTargetRegistry from '../SyncTargetRegistry';
import time from '../time';
import FileHandler, { SettingValues } from './settings/FileHandler';
import Logger from '@joplin/utils/Logger';
import mergeGlobalAndLocalSettings from '../services/profileConfig/mergeGlobalAndLocalSettings';
import splitGlobalAndLocalSettings from '../services/profileConfig/splitGlobalAndLocalSettings';
import JoplinError from '../JoplinError';
import { defaultListColumns } from '../services/plugins/api/noteListType';
const { sprintf } = require('sprintf-js');
const ObjectUtils = require('../ObjectUtils');
const { toTitleCase } = require('../string-utils.js');
const { rtrimSlashes, toSystemSlashes } = require('../path-utils');
const logger = Logger.create('models/Setting');
export enum SettingItemType {
Int = 1,
String = 2,
Bool = 3,
Array = 4,
Object = 5,
Button = 6,
}
interface OptionsToValueLabelsOptions {
valueKey: string;
labelKey: string;
}
export enum SettingItemSubType {
FilePathAndArgs = 'file_path_and_args',
FilePath = 'file_path', // Not supported on mobile!
DirectoryPath = 'directory_path', // Not supported on mobile!
FontFamily = 'font_family',
MonospaceFontFamily = 'monospace_font_family',
}
interface KeysOptions {
secureOnly?: boolean;
}
export enum SettingStorage {
Database = 1,
File = 2,
}
// This is the definition of a setting item
export interface SettingItem {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
value: any;
type: SettingItemType;
public: boolean;
subType?: string;
key?: string;
isEnum?: boolean;
section?: string;
label?(): string;
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
description?: Function;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
options?(): any;
optionsOrder?(): string[];
appTypes?: AppType[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show?(settings: any): boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
filter?(value: any): any;
secure?: boolean;
advanced?: boolean;
minimum?: number;
maximum?: number;
step?: number;
onClick?(): void;
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
unitLabel?: Function;
needRestart?: boolean;
autoSave?: boolean;
storage?: SettingStorage;
hideLabel?: boolean;
// In a multi-profile context, all settings are by default local - they take
// their value from the current profile. This flag can be set to specify
// that the setting is global and that its value should come from the root
// profile. This flag only applies to sub-profiles.
//
// At the moment, all global settings must be saved to file (have the
// storage attribute set to "file") because it's simpler to load the root
// profile settings.json than load the whole SQLite database. This
// restriction is not an issue normally since all settings that are
// considered global are also the user-facing ones.
isGlobal?: boolean;
}
export interface SettingItems {
[key: string]: SettingItem;
}
// This is where the actual setting values are stored.
// They are saved to database at regular intervals.
interface CacheItem {
key: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
value: any;
}
export enum SettingSectionSource {
Default = 1,
Plugin = 2,
}
export interface SettingSection {
label: string;
iconName?: string;
description?: string;
name?: string;
source?: SettingSectionSource;
}
export enum SyncStartupOperation {
None = 0,
ClearLocalSyncState = 1,
ClearLocalData = 2,
}
export enum Env {
Undefined = 'SET_ME',
Dev = 'dev',
Prod = 'prod',
}
export enum AppType {
Desktop = 'desktop',
Mobile = 'mobile',
Cli = 'cli',
}
export interface Constants {
env: Env;
isDemo: boolean;
appName: string;
appId: string;
appType: AppType;
resourceDirName: string;
resourceDir: string;
profileDir: string;
rootProfileDir: string;
tempDir: string;
pluginDataDir: string;
cacheDir: string;
pluginDir: string;
homeDir: string;
flagOpenDevTools: boolean;
syncVersion: number;
startupDevPlugins: string[];
isSubProfile: boolean;
}
interface SettingSections {
[key: string]: SettingSection;
}
// "Default migrations" are used to migrate previous setting defaults to new
// values. If we simply change the default in the metadata, it might cause
// problems if the user has never previously set the value.
//
// It happened for example when changing the "sync.target" from 7 (Dropbox) to 0
// (None). Users who had never explicitly set the sync target and were using
// Dropbox would suddenly have their sync target set to "none".
//
// So the technique is like this:
//
// - If the app has previously been executed, we run the migrations, which do
// something like this:
// - If the setting has never been set, set it to the previous default
// value. For example, for sync.target, it would set it to "7".
// - If the setting has been explicitly set, keep the current value.
// - If the app runs for the first time, skip all the migrations. So
// "sync.target" would be set to 0.
//
// A default migration runs only once (or never, if it is skipped).
//
// The handlers to either apply or skip the migrations must be called from the
// application, in the initialization code.
interface DefaultMigration {
name: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
previousDefault: any;
}
// To create a default migration:
//
// - Set the new default value in the setting metadata
// - Add an entry below with the name of the setting and the **previous**
// default value.
//
// **Never** removes an item from this array, as the array index is essentially
// the migration ID.
const defaultMigrations: DefaultMigration[] = [
{
name: 'sync.target',
previousDefault: 7,
},
{
name: 'style.editor.contentMaxWidth',
previousDefault: 600,
},
];
// "UserSettingMigration" are used to migrate existing user setting to a new setting. With a way
// to transform existing value of the old setting to value and type of the new setting.
interface UserSettingMigration {
oldName: string;
newName: string;
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
transformValue: Function;
}
const userSettingMigration: UserSettingMigration[] = [
{
oldName: 'spellChecker.language',
newName: 'spellChecker.languages',
transformValue: (value: string) => { return [value]; },
},
];
export type SettingMetadataSection = {
name: string;
isScreen?: boolean;
metadatas: SettingItem[];
source?: SettingSectionSource;
};
export type MetadataBySection = SettingMetadataSection[];
class Setting extends BaseModel {
public static schemaUrl = 'https://joplinapp.org/schema/settings.json';
// 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';
public static DATE_FORMAT_8 = 'YYMMDD';
public static DATE_FORMAT_9 = 'YYYY/MM/DD';
public static TIME_FORMAT_1 = 'HH:mm';
public static TIME_FORMAT_2 = 'h:mm A';
public static TIME_FORMAT_3 = 'HH.mm';
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 customCssFilenames = {
JOPLIN_APP: 'userchrome.css',
RENDERED_MARKDOWN: 'userstyle.css',
};
// Contains constants that are set by the application and
// cannot be modified by the user:
public static constants_: Constants = {
env: Env.Undefined,
isDemo: false,
appName: 'joplin',
appId: 'SET_ME', // Each app should set this identifier
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
appType: 'SET_ME' as any, // 'cli' or 'mobile'
resourceDirName: '',
resourceDir: '',
profileDir: '',
rootProfileDir: '',
tempDir: '',
pluginDataDir: '',
cacheDir: '',
pluginDir: '',
homeDir: '',
flagOpenDevTools: false,
syncVersion: 3,
startupDevPlugins: [],
isSubProfile: false,
};
public static autoSaveEnabled = true;
public static allowFileStorage = true;
private static metadata_: SettingItems = null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
private static keychainService_: any = null;
private static keys_: string[] = null;
private static cache_: CacheItem[] = [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
private static saveTimeoutId_: any = null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
private static changeEventTimeoutId_: any = null;
private static customMetadata_: SettingItems = {};
private static customSections_: SettingSections = {};
private static changedKeys_: string[] = [];
private static fileHandler_: FileHandler = null;
private static rootFileHandler_: FileHandler = null;
private static settingFilename_ = 'settings.json';
private static buildInMetadata_: SettingItems = null;
public static tableName() {
return 'settings';
}
public static modelType() {
return BaseModel.TYPE_SETTING;
}
public static async reset() {
if (this.saveTimeoutId_) shim.clearTimeout(this.saveTimeoutId_);
if (this.changeEventTimeoutId_) shim.clearTimeout(this.changeEventTimeoutId_);
this.saveTimeoutId_ = null;
this.changeEventTimeoutId_ = null;
this.metadata_ = null;
this.keys_ = null;
this.cache_ = [];
this.customMetadata_ = {};
this.fileHandler_ = null;
this.rootFileHandler_ = null;
}
public static get settingFilePath(): string {
return `${this.value('profileDir')}/${this.settingFilename_}`;
}
public static get rootSettingFilePath(): string {
return `${this.value('rootProfileDir')}/${this.settingFilename_}`;
}
public static get settingFilename(): string {
return this.settingFilename_;
}
public static set settingFilename(v: string) {
this.settingFilename_ = v;
}
public static get fileHandler(): FileHandler {
if (!this.fileHandler_) {
this.fileHandler_ = new FileHandler(this.settingFilePath);
}
return this.fileHandler_;
}
public static get rootFileHandler(): FileHandler {
if (!this.rootFileHandler_) {
this.rootFileHandler_ = new FileHandler(this.rootSettingFilePath);
}
return this.rootFileHandler_;
}
public static keychainService() {
if (!this.keychainService_) throw new Error('keychainService has not been set!!');
return this.keychainService_;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
public static setKeychainService(s: any) {
this.keychainService_ = s;
}
public static metadata(): SettingItems {
if (this.metadata_) return this.metadata_;
const platform = shim.platformName();
const mobilePlatform = shim.mobilePlatform();
let wysiwygYes = '';
let wysiwygNo = '';
if (shim.isElectron()) {
wysiwygYes = ` ${_('(wysiwyg: %s)', _('yes'))}`;
wysiwygNo = ` ${_('(wysiwyg: %s)', _('no'))}`;
}
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/help/faq');
// 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.
const themeOptions = () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const output: any = {};
output[Setting.THEME_LIGHT] = _('Light');
output[Setting.THEME_DARK] = _('Dark');
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');
return output;
};
this.buildInMetadata_ = {
'clientId': {
value: '',
type: SettingItemType.String,
public: false,
},
'editor.codeView': {
value: true,
type: SettingItemType.Bool,
public: false,
appTypes: [AppType.Desktop],
storage: SettingStorage.File,
isGlobal: true,
},
'sync.openSyncWizard': {
value: null,
type: SettingItemType.Button,
public: true,
appTypes: [AppType.Desktop],
label: () => _('Open Sync Wizard...'),
hideLabel: true,
section: 'sync',
},
'sync.target': {
value: 0,
type: SettingItemType.Int,
isEnum: true,
public: true,
section: 'sync',
label: () => _('Synchronisation target'),
description: (appType: AppType) => {
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).');
},
options: () => {
return SyncTargetRegistry.idAndLabelPlainObject(platform);
},
optionsOrder: () => {
return SyncTargetRegistry.optionsOrder();
},
storage: SettingStorage.File,
},
'sync.upgradeState': {
value: Setting.SYNC_UPGRADE_STATE_IDLE,
type: SettingItemType.Int,
public: false,
},
'sync.startupOperation': {
value: SyncStartupOperation.None,
type: SettingItemType.Int,
public: false,
},
'sync.2.path': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
try {
return settings['sync.target'] === SyncTargetRegistry.nameToId('filesystem');
} catch (error) {
return false;
}
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
filter: (value: any) => {
return value ? rtrimSlashes(value) : '';
},
public: true,
label: () => _('Directory to synchronise with (absolute path)'),
description: () => emptyDirWarning,
storage: SettingStorage.File,
},
'sync.5.path': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('nextcloud');
},
public: true,
label: () => _('Nextcloud WebDAV URL'),
description: () => emptyDirWarning,
storage: SettingStorage.File,
},
'sync.5.username': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('nextcloud');
},
public: true,
label: () => _('Nextcloud username'),
storage: SettingStorage.File,
},
'sync.5.password': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('nextcloud');
},
public: true,
label: () => _('Nextcloud password'),
secure: true,
},
'sync.6.path': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('webdav');
},
public: true,
label: () => _('WebDAV URL'),
description: () => emptyDirWarning,
storage: SettingStorage.File,
},
'sync.6.username': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('webdav');
},
public: true,
label: () => _('WebDAV username'),
storage: SettingStorage.File,
},
'sync.6.password': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('webdav');
},
public: true,
label: () => _('WebDAV password'),
secure: true,
},
'sync.8.path': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
try {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
} catch (error) {
return false;
}
},
filter: value => {
return value ? rtrimSlashes(value) : '';
},
public: true,
label: () => _('S3 bucket'),
description: () => emptyDirWarning,
storage: SettingStorage.File,
},
'sync.8.url': {
value: 'https://s3.amazonaws.com/',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
},
filter: value => {
return value ? value.trim() : '';
},
public: true,
label: () => _('S3 URL'),
storage: SettingStorage.File,
},
'sync.8.region': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
},
filter: value => {
return value ? value.trim() : '';
},
public: true,
label: () => _('S3 region'),
storage: SettingStorage.File,
},
'sync.8.username': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
},
public: true,
label: () => _('S3 access key'),
storage: SettingStorage.File,
},
'sync.8.password': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
},
public: true,
label: () => _('S3 secret key'),
secure: true,
},
'sync.8.forcePathStyle': {
value: false,
type: SettingItemType.Bool,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('amazon_s3');
},
public: true,
label: () => _('Force path style'),
storage: SettingStorage.File,
},
'sync.9.path': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('joplinServer');
},
public: true,
label: () => _('Joplin Server URL'),
description: () => emptyDirWarning,
storage: SettingStorage.File,
},
'sync.9.userContentPath': {
value: '',
type: SettingItemType.String,
public: false,
storage: SettingStorage.Database,
},
'sync.9.username': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('joplinServer');
},
public: true,
label: () => _('Joplin Server email'),
storage: SettingStorage.File,
},
'sync.9.password': {
value: '',
type: SettingItemType.String,
section: 'sync',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
show: (settings: any) => {
return settings['sync.target'] === SyncTargetRegistry.nameToId('joplinServer');
},
public: true,
label: () => _('Joplin Server password'),
secure: true,
},
// 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,
},
'sync.10.userContentPath': {
value: 'https://joplinusercontent.com',
type: SettingItemType.String,
public: false,
storage: SettingStorage.Database,
},
'sync.10.website': {
value: 'https://joplincloud.com',
type: SettingItemType.String,
public: false,
storage: SettingStorage.Database,
},
'sync.10.username': {
value: '',
type: SettingItemType.String,
public: false,
storage: SettingStorage.File,
},
'sync.10.password': {
value: '',
type: SettingItemType.String,
public: false,
secure: true,
},
'sync.10.inboxEmail': { value: '', type: SettingItemType.String, public: false },
'sync.10.inboxId': { value: '', type: SettingItemType.String, public: false },
'sync.10.canUseSharePermissions': { value: false, type: SettingItemType.Bool, public: false },
'sync.10.accountType': { value: 0, type: SettingItemType.Int, public: false },
'sync.5.syncTargets': { value: {}, type: SettingItemType.Object, public: false },
'sync.resourceDownloadMode': {
value: 'always',
type: SettingItemType.String,
section: 'sync',
public: true,
advanced: true,
isEnum: true,
appTypes: [AppType.Mobile, AppType.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'),
};
},
storage: SettingStorage.File,
isGlobal: true,
},
'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 },
'sync.9.auth': { value: '', type: SettingItemType.String, public: false },
'sync.10.auth': { value: '', type: SettingItemType.String, public: false },
'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 },
'sync.9.context': { value: '', type: SettingItemType.String, public: false },
'sync.10.context': { value: '', type: SettingItemType.String, public: false },
'sync.maxConcurrentConnections': { value: 5, type: SettingItemType.Int, storage: SettingStorage.File, isGlobal: true, public: true, advanced: true, section: 'sync', label: () => _('Max concurrent connections'), minimum: 1, maximum: 20, step: 1 },
// 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.
activeFolderId: { value: '', type: SettingItemType.String, public: false },
notesParent: { value: '', type: SettingItemType.String, public: false },
richTextBannerDismissed: { value: false, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, public: false },
firstStart: { value: true, type: SettingItemType.Bool, public: false },
locale: {
value: defaultLocale(),
type: SettingItemType.String,
isEnum: true,
public: true,
label: () => _('Language'),
options: () => {
return ObjectUtils.sortByValue(supportedLocalesToLanguages({ includeStats: true }));
},
storage: SettingStorage.File,
isGlobal: true,
},
dateFormat: {
value: Setting.DATE_FORMAT_1,
type: SettingItemType.String,
isEnum: true,
public: true,
label: () => _('Date format'),
options: () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const options: any = {};
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);
options[Setting.DATE_FORMAT_7] = time.formatMsToLocal(now, Setting.DATE_FORMAT_7);
options[Setting.DATE_FORMAT_8] = time.formatMsToLocal(now, Setting.DATE_FORMAT_8);
options[Setting.DATE_FORMAT_9] = time.formatMsToLocal(now, Setting.DATE_FORMAT_9);
return options;
},
storage: SettingStorage.File,
isGlobal: true,
},
timeFormat: {
value: Setting.TIME_FORMAT_1,
type: SettingItemType.String,
isEnum: true,
public: true,
label: () => _('Time format'),
options: () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const options: any = {};
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);
options[Setting.TIME_FORMAT_3] = time.formatMsToLocal(now, Setting.TIME_FORMAT_3);
return options;
},
storage: SettingStorage.File,
isGlobal: true,
},
'ocr.enabled': {
value: false,
type: SettingItemType.Bool,
public: true,
appTypes: [AppType.Desktop],
label: () => _('Enable optical character recognition (OCR)'),
description: () => _('When enabled, the application will scan your attachments and extract the text from it. This will allow you to search for text in these attachments.'),
storage: SettingStorage.File,
isGlobal: true,
},
theme: {
value: Setting.THEME_LIGHT,
type: SettingItemType.Int,
public: true,
appTypes: [AppType.Mobile, AppType.Desktop],
show: (settings) => {
return !settings['themeAutoDetect'];
},
isEnum: true,
label: () => _('Theme'),
section: 'appearance',
options: () => themeOptions(),
storage: SettingStorage.File,
isGlobal: true,
},
themeAutoDetect: {
value: false,
type: SettingItemType.Bool,
section: 'appearance',
appTypes: [AppType.Mobile, AppType.Desktop],
public: true,
label: () => _('Automatically switch theme to match system theme'),
storage: SettingStorage.File,
isGlobal: true,
},
preferredLightTheme: {
value: Setting.THEME_LIGHT,
type: SettingItemType.Int,
public: true,
show: (settings) => {
return settings['themeAutoDetect'];
},
appTypes: [AppType.Mobile, AppType.Desktop],
isEnum: true,
label: () => _('Preferred light theme'),
section: 'appearance',
options: () => themeOptions(),
storage: SettingStorage.File,
isGlobal: true,
},
preferredDarkTheme: {
value: Setting.THEME_DARK,
type: SettingItemType.Int,
public: true,
show: (settings) => {
return settings['themeAutoDetect'];
},
appTypes: [AppType.Mobile, AppType.Desktop],
isEnum: true,
label: () => _('Preferred dark theme'),
section: 'appearance',
options: () => themeOptions(),
storage: SettingStorage.File,
isGlobal: true,
},
notificationPermission: {
value: '',
type: SettingItemType.String,
public: false,
},
showNoteCounts: { value: true, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, public: false, advanced: true, appTypes: [AppType.Desktop, AppType.Cli], label: () => _('Show note counts') },
layoutButtonSequence: {
value: Setting.LAYOUT_ALL,
type: SettingItemType.Int,
public: false,
appTypes: [AppType.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')),
}),
storage: SettingStorage.File,
isGlobal: true,
},
uncompletedTodosOnTop: { value: true, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, section: 'note', public: true, appTypes: [AppType.Cli], label: () => _('Uncompleted to-dos on top') },
showCompletedTodos: { value: true, type: SettingItemType.Bool, storage: SettingStorage.File, isGlobal: true, section: 'note', public: true, appTypes: [AppType.Cli], label: () => _('Show completed to-dos') },
'notes.sortOrder.field': {
value: 'user_updated_time',
type: SettingItemType.String,
section: 'note',
isEnum: true,
public: true,
appTypes: [AppType.Cli],
label: () => _('Sort notes by'),
options: () => {
const Note = require('./Note').default;
const noteSortFields = ['user_updated_time', 'user_created_time', 'title', 'order', 'todo_due', 'todo_completed'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
const options: any = {};
for (let i = 0; i < noteSortFields.length; i++) {
options[noteSortFields[i]] = toTitleCase(Note.fieldToLabel(noteSortFields[i]));
}
return options;
},
storage: SettingStorage.File,
isGlobal: true,
},
'editor.autoMatchingBraces': {
value: true,
type: SettingItemType.Bool,
public: true,
section: 'note',
appTypes: [AppType.Desktop],
label: () => _('Auto-pair braces, parenthesis, quotations, etc.'),
storage: SettingStorage.File,
isGlobal: true,
},
'notes.columns': {