From 19ef0c756eba1b6c554ce9892f503534e2bf0597 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sat, 16 Oct 2021 21:43:20 +0530 Subject: refactor: move service-defaults into the 'config' file for reuse --- src/config.ts | 23 +++++++++++++++++++ src/containers/settings/EditServiceScreen.js | 5 ++-- src/containers/settings/EditSettingsScreen.js | 4 ++-- src/models/Recipe.ts | 33 ++++++++------------------- src/stores/ServicesStore.js | 20 ++++++++-------- 5 files changed, 47 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/config.ts b/src/config.ts index 5f95a59f4..dfedbe6f5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -235,4 +235,27 @@ export const DEFAULT_APP_SETTINGS = { alwaysShowWorkspaces: false, liftSingleInstanceLock: false, enableLongPressServiceHint: false, + proxyFeatureEnabled: false, + onlyShowFavoritesInUnreadCount: false +}; + +export const DEFAULT_SERVICE_SETTINGS = { + isEnabled: true, + isHibernationEnabled: false, + isWakeUpEnabled: true, + isNotificationEnabled: true, + isBadgeEnabled: true, + isMuted: false, + customIcon: false, + isDarkModeEnabled: false, + // Note: Do NOT change these default values. If they change, then the corresponding changes in the recipes needs to be done + hasDirectMessages: true, + hasIndirectMessages: false, + hasNotificationSound: false, + hasTeamId: false, + hasCustomUrl: false, + hasHostedOption: false, + allowFavoritesDelineationInUnreadCount: false, + disablewebsecurity: false, + autoHibernate: false, }; diff --git a/src/containers/settings/EditServiceScreen.js b/src/containers/settings/EditServiceScreen.js index 972d3d251..43b461670 100644 --- a/src/containers/settings/EditServiceScreen.js +++ b/src/containers/settings/EditServiceScreen.js @@ -23,6 +23,7 @@ import { config as proxyFeature } from '../../features/serviceProxy'; import { SPELLCHECKER_LOCALES } from '../../i18n/languages'; import globalMessages from '../../i18n/globalMessages'; +import { DEFAULT_APP_SETTINGS } from '../../config'; const messages = defineMessages({ name: { @@ -307,7 +308,7 @@ class EditServiceScreen extends Component { onlyShowFavoritesInUnreadCount: { label: intl.formatMessage(messages.onlyShowFavoritesInUnreadCount), value: service.onlyShowFavoritesInUnreadCount, - default: false, + default: DEFAULT_APP_SETTINGS.onlyShowFavoritesInUnreadCount, }, }); } @@ -323,7 +324,7 @@ class EditServiceScreen extends Component { isEnabled: { label: intl.formatMessage(messages.enableProxy), value: serviceProxyConfig.isEnabled, - default: false, + default: DEFAULT_APP_SETTINGS.proxyFeatureEnabled, }, host: { label: intl.formatMessage(messages.proxyHost), diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index aea077a1e..de0714870 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js @@ -517,7 +517,7 @@ class EditSettingsScreen extends Component { lockingFeatureEnabled: { label: intl.formatMessage(messages.enableLock), value: settings.all.app.lockingFeatureEnabled || false, - default: false, + default: DEFAULT_APP_SETTINGS.lockingFeatureEnabled, }, lockedPassword: { label: intl.formatMessage(messages.lockPassword), @@ -539,7 +539,7 @@ class EditSettingsScreen extends Component { scheduledDNDEnabled: { label: intl.formatMessage(messages.scheduledDNDEnabled), value: settings.all.app.scheduledDNDEnabled || false, - default: false, + default: DEFAULT_APP_SETTINGS.scheduledDNDEnabled, }, scheduledDNDStart: { label: intl.formatMessage(messages.scheduledDNDStart), diff --git a/src/models/Recipe.ts b/src/models/Recipe.ts index e45977f24..e3efb2c4b 100644 --- a/src/models/Recipe.ts +++ b/src/models/Recipe.ts @@ -1,6 +1,7 @@ import semver from 'semver'; import { pathExistsSync } from 'fs-extra'; import { join } from 'path'; +import { DEFAULT_SERVICE_SETTINGS } from 'src/config'; import { ifUndefinedString, ifUndefinedBoolean } from '../jsUtils'; interface IRecipe { @@ -27,20 +28,6 @@ interface IRecipe { }; } -// Note: Do NOT change these default values. If they change, then the corresponding changes in the recipes needs to be done -// TODO: Need to reconcile other properties -const DEFAULT_RECIPE_SETTINGS = { - hasDirectMessages: true, - hasIndirectMessages: false, - hasNotificationSound: false, - hasTeamId: false, - hasCustomUrl: false, - hasHostedOption: false, - allowFavoritesDelineationInUnreadCount: false, - disablewebsecurity: false, - autoHibernate: false, -}; - export default class Recipe { id: string = ''; @@ -54,17 +41,17 @@ export default class Recipe { serviceURL: string = ''; - hasDirectMessages: boolean = DEFAULT_RECIPE_SETTINGS.hasDirectMessages; + hasDirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasDirectMessages; - hasIndirectMessages: boolean = DEFAULT_RECIPE_SETTINGS.hasIndirectMessages; + hasIndirectMessages: boolean = DEFAULT_SERVICE_SETTINGS.hasIndirectMessages; - hasNotificationSound: boolean = DEFAULT_RECIPE_SETTINGS.hasNotificationSound; + hasNotificationSound: boolean = DEFAULT_SERVICE_SETTINGS.hasNotificationSound; - hasTeamId: boolean = DEFAULT_RECIPE_SETTINGS.hasTeamId; + hasTeamId: boolean = DEFAULT_SERVICE_SETTINGS.hasTeamId; - hasCustomUrl: boolean = DEFAULT_RECIPE_SETTINGS.hasCustomUrl; + hasCustomUrl: boolean = DEFAULT_SERVICE_SETTINGS.hasCustomUrl; - hasHostedOption: boolean = DEFAULT_RECIPE_SETTINGS.hasHostedOption; + hasHostedOption: boolean = DEFAULT_SERVICE_SETTINGS.hasHostedOption; urlInputPrefix: string = ''; @@ -73,12 +60,12 @@ export default class Recipe { message: string = ''; allowFavoritesDelineationInUnreadCount: boolean = - DEFAULT_RECIPE_SETTINGS.allowFavoritesDelineationInUnreadCount; + DEFAULT_SERVICE_SETTINGS.allowFavoritesDelineationInUnreadCount; - disablewebsecurity: boolean = DEFAULT_RECIPE_SETTINGS.disablewebsecurity; + disablewebsecurity: boolean = DEFAULT_SERVICE_SETTINGS.disablewebsecurity; // TODO: Is this even used? - autoHibernate: boolean = DEFAULT_RECIPE_SETTINGS.autoHibernate; + autoHibernate: boolean = DEFAULT_SERVICE_SETTINGS.autoHibernate; path: string = ''; diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index c6baa4358..4f7ad7442 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js @@ -15,7 +15,7 @@ import { getDevRecipeDirectory, } from '../helpers/recipe-helpers'; import { workspaceStore } from '../features/workspaces'; -import { KEEP_WS_LOADED_USID } from '../config'; +import { DEFAULT_SERVICE_SETTINGS, KEEP_WS_LOADED_USID } from '../config'; import { SPELLCHECKER_LOCALES } from '../i18n/languages'; import { ferdiVersion } from '../environment-remote'; @@ -395,17 +395,15 @@ export default class ServicesStore extends Store { } // set default values for serviceData - - // TODO: How is this different from the defaults of the recipe in 'src/models/Recipe' file? serviceData = { - isEnabled: true, - isHibernationEnabled: false, - isWakeUpEnabled: true, - isNotificationEnabled: true, - isBadgeEnabled: true, - isMuted: false, - customIcon: false, - isDarkModeEnabled: false, + isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled, + isHibernationEnabled: DEFAULT_SERVICE_SETTINGS.isHibernationEnabled, + isWakeUpEnabled: DEFAULT_SERVICE_SETTINGS.isWakeUpEnabled, + isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled, + isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled, + isMuted: DEFAULT_SERVICE_SETTINGS.isMuted, + customIcon: DEFAULT_SERVICE_SETTINGS.customIcon, + isDarkModeEnabled: DEFAULT_SERVICE_SETTINGS.isDarkModeEnabled, spellcheckerLanguage: SPELLCHECKER_LOCALES[this.stores.settings.app.spellcheckerLanguage], userAgentPref: '', -- cgit v1.2.3-54-g00ecf