mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-06-05 21:49:31 +02:00
Fixed: Migrate extension settings (#92)
This commit is contained in:
35
core/main.js
35
core/main.js
@ -79,8 +79,40 @@ main._showReleaseNotes = function (details) {
|
|||||||
});
|
});
|
||||||
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
|
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
|
||||||
|
|
||||||
|
// ********************************************************************************
|
||||||
// TODO: Remove me in v2.4.1
|
// TODO: Remove me in v2.4.1
|
||||||
storageManager.migrateData('local');
|
let data = '';
|
||||||
|
|
||||||
|
chrome.storage.sync.get(null, function (items) {
|
||||||
|
data = items;
|
||||||
|
|
||||||
|
data['xhrTestDomain'] = 'localcdn.org';
|
||||||
|
data['storageType'] = 'local';
|
||||||
|
data['lastMappingUpdate'] = lastMappingUpdate;
|
||||||
|
|
||||||
|
chrome.storage.local.set({
|
||||||
|
[Setting.ALLOWED_DOMAINS_GOOGLE_FONTS]: data.allowedDomainsGoogleFonts,
|
||||||
|
[Setting.AMOUNT_INJECTED]: data.amountInjected,
|
||||||
|
[Setting.BLOCK_GOOGLE_FONTS]: data.blockGoogleFonts,
|
||||||
|
[Setting.BLOCK_MISSING]: data.blockMissing,
|
||||||
|
[Setting.DISABLE_PREFETCH]: data.disablePrefetch,
|
||||||
|
[Setting.DOMAINS_MANIPULATE_DOM]: data.domainsManipulateDOM,
|
||||||
|
[Setting.LOGGING]: data.logging,
|
||||||
|
[Setting.ENFORCE_STAGING]: data.enforceStaging,
|
||||||
|
[Setting.HIDE_RELEASE_NOTES]: data.hideReleaseNotes,
|
||||||
|
[Setting.INTERNAL_STATISTICS]: data.internalStatistics,
|
||||||
|
[Setting.INTERNAL_STATISTICS_DATA]: data.internalStatisticsData,
|
||||||
|
[Setting.LAST_MAPPING_UPDATE]: data.lastMappingUpdate,
|
||||||
|
[Setting.NEGATE_HTML_FILTER_LIST]: data.negateHtmlFilterList,
|
||||||
|
[Setting.SELECTED_ICON]: data.selectedIcon,
|
||||||
|
[Setting.SHOW_ICON_BADGE]: data.showIconBadge,
|
||||||
|
[Setting.STORAGE_TYPE]: data.storageType,
|
||||||
|
[Setting.STRIP_METADATA]: data.stripMetadata,
|
||||||
|
[Setting.WHITELISTED_DOMAINS]: data.whitelistedDomains,
|
||||||
|
[Setting.XHR_TEST_DOMAIN]: data.xhrTestDomain
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// ********************************************************************************
|
||||||
|
|
||||||
// If add-on update true, check last update of mappings.js
|
// If add-on update true, check last update of mappings.js
|
||||||
storageManager.type.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) {
|
storageManager.type.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) {
|
||||||
@ -92,6 +124,7 @@ main._showReleaseNotes = function (details) {
|
|||||||
storageManager.type.set({
|
storageManager.type.set({
|
||||||
[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate
|
[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate
|
||||||
}, function() {
|
}, function() {
|
||||||
|
// ********************************************************************************
|
||||||
// TODO: Remove me in v2.4.1
|
// TODO: Remove me in v2.4.1
|
||||||
// if (!items.hideReleaseNotes) {
|
// if (!items.hideReleaseNotes) {
|
||||||
if (true) {
|
if (true) {
|
||||||
|
@ -35,38 +35,42 @@ storageManager.checkStorageType = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
storageManager.migrateData = function (target) {
|
storageManager.migrateData = function (target) {
|
||||||
let storageSource, storageDestination, newItems, onlyLocal;
|
let storageSource, storageDestination;
|
||||||
|
|
||||||
newItems = {};
|
|
||||||
onlyLocal = {};
|
|
||||||
|
|
||||||
if (target === 'local') {
|
if (target === 'local') {
|
||||||
storageSource = chrome.storage.sync;
|
storageSource = chrome.storage.sync;
|
||||||
storageDestination = chrome.storage.local;
|
storageDestination = chrome.storage.local;
|
||||||
} else {
|
} else if (target === 'sync') {
|
||||||
storageSource = chrome.storage.local;
|
storageSource = chrome.storage.local;
|
||||||
storageDestination = chrome.storage.sync;
|
storageDestination = chrome.storage.sync;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
storageSource.get(null, function (items) {
|
storageSource.get(null, function (data) {
|
||||||
for (const [key, value] of Object.entries(items)) {
|
chrome.storage.local.set({
|
||||||
// Filter unused old data
|
[Setting.AMOUNT_INJECTED]: data.amountInjected,
|
||||||
if (Object.values(Setting).includes(key)) {
|
[Setting.INTERNAL_STATISTICS]: data.internalStatistics,
|
||||||
// Remove previous default values
|
[Setting.INTERNAL_STATISTICS_DATA]: data.internalStatisticsData,
|
||||||
if (key === 'xhrTestDomain' && value === 'decentraleyes.org') {
|
[Setting.STORAGE_TYPE]: target
|
||||||
newItems[key] = 'localcdn.org';
|
});
|
||||||
} else if (key === 'amountInjected' || key === 'internalStatistics' || key === 'internalStatisticsData') {
|
storageDestination.set({
|
||||||
onlyLocal[key] = value;
|
[Setting.ALLOWED_DOMAINS_GOOGLE_FONTS]: data.allowedDomainsGoogleFonts,
|
||||||
} else {
|
[Setting.BLOCK_GOOGLE_FONTS]: data.blockGoogleFonts,
|
||||||
newItems[key] = value;
|
[Setting.BLOCK_MISSING]: data.blockMissing,
|
||||||
}
|
[Setting.DISABLE_PREFETCH]: data.disablePrefetch,
|
||||||
}
|
[Setting.DOMAINS_MANIPULATE_DOM]: data.domainsManipulateDOM,
|
||||||
}
|
[Setting.LOGGING]: data.logging,
|
||||||
chrome.storage.local.set(onlyLocal);
|
[Setting.ENFORCE_STAGING]: data.enforceStaging,
|
||||||
storageDestination.set(newItems);
|
[Setting.HIDE_RELEASE_NOTES]: data.hideReleaseNotes,
|
||||||
|
[Setting.LAST_MAPPING_UPDATE]: data.lastMappingUpdate,
|
||||||
// Clear sync storage
|
[Setting.NEGATE_HTML_FILTER_LIST]: data.negateHtmlFilterList,
|
||||||
// chrome.storage.sync.clear();
|
[Setting.SELECTED_ICON]: data.selectedIcon,
|
||||||
|
[Setting.SHOW_ICON_BADGE]: data.showIconBadge,
|
||||||
|
[Setting.STRIP_METADATA]: data.stripMetadata,
|
||||||
|
[Setting.WHITELISTED_DOMAINS]: data.whitelistedDomains,
|
||||||
|
[Setting.XHR_TEST_DOMAIN]: data.xhrTestDomain
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -402,6 +402,11 @@ options._onStorageOptionChanged = function ({ target }) {
|
|||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
[Setting.STORAGE_TYPE]: target.value,
|
[Setting.STORAGE_TYPE]: target.value,
|
||||||
});
|
});
|
||||||
|
if (target.value === 'local') {
|
||||||
|
storageManager.migrateData('local');
|
||||||
|
} else {
|
||||||
|
storageManager.migrateData('sync');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
options._onLinkClick = function (url) {
|
options._onLinkClick = function (url) {
|
||||||
|
Reference in New Issue
Block a user