From d7e0af1af612ce9fcc1078b47273d8a5de14a16b Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 15 Nov 2020 12:32:06 +0100 Subject: [PATCH] Initialization updated --- core/constants.js | 2 -- core/main.js | 44 +++++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/core/constants.js b/core/constants.js index 3ca13859..33a58eb6 100644 --- a/core/constants.js +++ b/core/constants.js @@ -70,7 +70,6 @@ const Setting = { 'STRIP_METADATA': 'stripMetadata', 'LAST_MAPPING_UPDATE': 'lastMappingUpdate', 'ALLOWLISTED_DOMAINS': 'allowlistedDomains', - 'WHITELISTED_DOMAINS': 'whitelistedDomains', 'XHR_TEST_DOMAIN': 'xhrTestDomain', 'LOGGING': 'enableLogging', 'DOMAINS_MANIPULATE_DOM': 'domainsManipulateDOM', @@ -104,7 +103,6 @@ const SettingDefaults = { [Setting.STORAGE_TYPE]: 'local', [Setting.STRIP_METADATA]: true, [Setting.ALLOWLISTED_DOMAINS]: {}, - [Setting.WHITELISTED_DOMAINS]: {}, [Setting.XHR_TEST_DOMAIN]: Address.LOCALCDN, [Setting.BADGE_COLOR]: '#4A826C', [Setting.BADGE_TEXT_COLOR]: '#FFFFFF' diff --git a/core/main.js b/core/main.js index 5b10ee31..26c545b2 100644 --- a/core/main.js +++ b/core/main.js @@ -32,8 +32,31 @@ main._initializeSettings = function () { storageManager.checkStorageType(); storageManager.type.get(null, function (items) { - if (items === null) { - items = SettingDefaults; // Restore setting defaults. + // Delete old keys + if (typeof items.whitelistedDomains !== 'undefined') { + if (Object.keys(items.allowlistedDomains).length === 0) { + items.allowlistedDomains = items.whitelistedDomains; + } + delete items['whitelistedDomains']; + storageManager.type.remove('whitelistedDomains'); + } + + // Convert value of notifications + if (typeof items.hideReleaseNotes !== 'undefined') { + if (items.hideReleaseNotes === true) { + items.updateNotification = 0; + } else { + items.updateNotification = 2; + } + delete items['hideReleaseNotes']; + storageManager.type.remove('hideReleaseNotes'); + } + + // Use default if key is missing + for (const key of Object.keys(SettingDefaults)) { + if (items[key] === undefined) { + items[key] = SettingDefaults[key]; + } } if (items.disablePrefetch !== false) { @@ -42,23 +65,6 @@ main._initializeSettings = function () { }); } - // Copy old data - if (Object.keys(items.allowlistedDomains).length === 0) { - items.allowlistedDomains = items.whitelistedDomains; - } - - // Delete old key - if (typeof items.whitelistedDomains !== 'undefined') { - delete items['whitelistedDomains']; - storageManager.type.remove('whitelistedDomains'); - } - - // Convert value of notifications - if (typeof items.hideReleaseNotes !== 'undefined') { - items.updateNotification = items.hideReleaseNotes ? 0 : 2; - delete items['hideReleaseNotes']; - storageManager.type.remove('hideReleaseNotes'); - } stateManager.selectedIcon = items.selectedIcon; wrappers.setIcon({