From 6b45763095e7023b9c21ca5ddfa1fa48bd72e243 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 30 May 2018 11:38:38 +0200 Subject: [PATCH] MOBILE-2404 config: Don't support booleans in config provider --- src/addon/notifications/pages/settings/settings.ts | 4 ++-- src/core/settings/pages/general/general.ts | 4 ++-- src/core/settings/pages/synchronization/synchronization.ts | 4 ++-- src/providers/config.ts | 4 ++-- src/providers/utils/dom.ts | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/addon/notifications/pages/settings/settings.ts b/src/addon/notifications/pages/settings/settings.ts index cf1d19ee3..ed4cabc45 100644 --- a/src/addon/notifications/pages/settings/settings.ts +++ b/src/addon/notifications/pages/settings/settings.ts @@ -58,7 +58,7 @@ export class AddonNotificationsSettingsPage implements OnDestroy { this.canChangeSound = localNotificationsProvider.isAvailable() && !appProvider.isDesktop(); if (this.canChangeSound) { configProvider.get(CoreConstants.SETTINGS_NOTIFICATION_SOUND, true).then((enabled) => { - this.notificationSound = enabled; + this.notificationSound = !!enabled; }); } } @@ -245,7 +245,7 @@ export class AddonNotificationsSettingsPage implements OnDestroy { * @param {enabled} enabled True to enable the notification sound, false to disable it. */ changeNotificationSound(enabled: boolean): void { - this.configProvider.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled).finally(() => { + this.configProvider.set(CoreConstants.SETTINGS_NOTIFICATION_SOUND, enabled ? 1 : 0).finally(() => { const siteId = this.sitesProvider.getCurrentSiteId(); this.eventsProvider.trigger(CoreEventsProvider.NOTIFICATION_SOUND_CHANGED, {enabled}, siteId); this.localNotificationsProvider.rescheduleAll(); diff --git a/src/core/settings/pages/general/general.ts b/src/core/settings/pages/general/general.ts index 27c7d1e7e..ab493b501 100644 --- a/src/core/settings/pages/general/general.ts +++ b/src/core/settings/pages/general/general.ts @@ -56,7 +56,7 @@ export class CoreSettingsGeneralPage { this.rteSupported = this.domUtils.isRichTextEditorSupported(); if (this.rteSupported) { this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true).then((richTextEditorEnabled) => { - this.richTextEditor = richTextEditorEnabled; + this.richTextEditor = !!richTextEditorEnabled; }); } @@ -81,7 +81,7 @@ export class CoreSettingsGeneralPage { * Called when the rich text editor is enabled or disabled. */ richTextEditorChanged(): void { - this.configProvider.set(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, this.richTextEditor); + this.configProvider.set(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, this.richTextEditor ? 1 : 0); } /** diff --git a/src/core/settings/pages/synchronization/synchronization.ts b/src/core/settings/pages/synchronization/synchronization.ts index 19be97a5d..48c7299ab 100644 --- a/src/core/settings/pages/synchronization/synchronization.ts +++ b/src/core/settings/pages/synchronization/synchronization.ts @@ -68,7 +68,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy { }); this.configProvider.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, true).then((syncOnlyOnWifi) => { - this.syncOnlyOnWifi = syncOnlyOnWifi; + this.syncOnlyOnWifi = !!syncOnlyOnWifi; }); } @@ -76,7 +76,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy { * Called when sync only on wifi setting is enabled or disabled. */ syncOnlyOnWifiChanged(): void { - this.configProvider.set(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, this.syncOnlyOnWifi); + this.configProvider.set(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, this.syncOnlyOnWifi ? 1 : 0); } /** diff --git a/src/providers/config.ts b/src/providers/config.ts index c34166080..05e9a6a0e 100644 --- a/src/providers/config.ts +++ b/src/providers/config.ts @@ -77,10 +77,10 @@ export class CoreConfigProvider { * Set an app setting. * * @param {string} name The config name. - * @param {boolean|number|string} value The config value. Can only store primitive values, not objects. + * @param {number|string} value The config value. Can only store number or strings. * @return {Promise} Promise resolved when done. */ - set(name: string, value: boolean | number | string): Promise { + set(name: string, value: number | string): Promise { return this.appDB.insertRecord(this.TABLE_NAME, { name: name, value: value }); } } diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 510c7876d..a7b961e9b 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -548,7 +548,9 @@ export class CoreDomUtilsProvider { */ isRichTextEditorEnabled(): Promise { if (this.isRichTextEditorSupported()) { - return this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true); + return this.configProvider.get(CoreConstants.SETTINGS_RICH_TEXT_EDITOR, true).then((enabled) => { + return !!enabled; + }); } return Promise.resolve(false);