1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-06 23:56:13 +02:00

Desktop: Fixes #10382: Fix default values for plugin settings stored in settings.json not applied (#10383)

This commit is contained in:
Henry Heino
2024-05-02 07:00:12 -07:00
committed by GitHub
parent 85f890e7c5
commit 569b567f21
2 changed files with 16 additions and 6 deletions

View File

@ -65,15 +65,20 @@ describe('models/Setting', () => {
await expectThrow(async () => Setting.value('itsgone'), 'unknown_key'); await expectThrow(async () => Setting.value('itsgone'), 'unknown_key');
})); }));
it('should allow registering new settings dynamically', (async () => { it.each([
SettingStorage.Database, SettingStorage.File,
])('should allow registering new settings dynamically (storage: %d)', (async (storage) => {
await expectThrow(async () => Setting.setValue('myCustom', '123'), 'unknown_key'); await expectThrow(async () => Setting.setValue('myCustom', '123'), 'unknown_key');
await Setting.registerSetting('myCustom', { await Setting.registerSetting('myCustom', {
public: true, public: true,
value: 'default', value: 'default',
type: Setting.TYPE_STRING, type: Setting.TYPE_STRING,
storage,
}); });
expect(Setting.value('myCustom')).toBe('default');
await expectNotThrow(async () => Setting.setValue('myCustom', '123')); await expectNotThrow(async () => Setting.setValue('myCustom', '123'));
expect(Setting.value('myCustom')).toBe('123'); expect(Setting.value('myCustom')).toBe('123');
@ -328,7 +333,7 @@ describe('models/Setting', () => {
expect((await Setting.loadOne('locale')).value).toBe('fr_FR'); expect((await Setting.loadOne('locale')).value).toBe('fr_FR');
expect((await Setting.loadOne('theme')).value).toBe(Setting.THEME_DARK); expect((await Setting.loadOne('theme')).value).toBe(Setting.THEME_DARK);
expect((await Setting.loadOne('sync.target')).value).toBe(undefined); expect((await Setting.loadOne('sync.target'))).toBe(null);
}); });
it('should save sub-profile settings', async () => { it('should save sub-profile settings', async () => {

View File

@ -2116,6 +2116,7 @@ class Setting extends BaseModel {
} }
// Low-level method to load a setting directly from the database. Should not be used in most cases. // Low-level method to load a setting directly from the database. Should not be used in most cases.
// Does not apply setting default values.
public static async loadOne(key: string): Promise<CacheItem | null> { public static async loadOne(key: string): Promise<CacheItem | null> {
if (this.keyStorage(key) === SettingStorage.File) { if (this.keyStorage(key) === SettingStorage.File) {
let fileSettings = await this.fileHandler.load(); let fileSettings = await this.fileHandler.load();
@ -2126,10 +2127,14 @@ class Setting extends BaseModel {
fileSettings = mergeGlobalAndLocalSettings(rootFileSettings, fileSettings); fileSettings = mergeGlobalAndLocalSettings(rootFileSettings, fileSettings);
} }
if (key in fileSettings) {
return { return {
key, key,
value: fileSettings[key], value: fileSettings[key],
}; };
} else {
return null;
}
} }
// Always check in the database first, including for secure settings, // Always check in the database first, including for secure settings,