Synchronize settings (#1223)

This commit is contained in:
nobody 2022-12-03 06:22:57 +01:00
parent d8f6587a14
commit 2dc8c14086
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
4 changed files with 43 additions and 8 deletions

View File

@ -44,7 +44,9 @@ storageManager.checkStorageType = function () {
};
storageManager.migrateData = function (target) {
let storageSource, storageDestination;
let storageSource, storageDestination, syncFetch;
syncFetch = false;
if (target === 'local') {
storageSource = chrome.storage.sync;
@ -52,6 +54,11 @@ storageManager.migrateData = function (target) {
} else if (target === 'sync') {
storageSource = chrome.storage.local;
storageDestination = chrome.storage.sync;
} else if (target === 'sync-fetch') {
storageSource = chrome.storage.sync;
storageDestination = chrome.storage.sync;
target = 'sync';
syncFetch = true;
} else {
return;
}
@ -84,6 +91,9 @@ storageManager.migrateData = function (target) {
[Setting.BADGE_HTML_FILTER_BACKGROUND_COLOR]: data.badgeHTMLFilterBackgroundColor,
[Setting.BADGE_HTML_FILTER_TEXT_COLOR]: data.badgeHTMLfilterTextColor
});
if (syncFetch === true) {
chrome.runtime.reload();
}
});
};

View File

@ -111,6 +111,14 @@ optionsOther._onStorageOptionChanged = function ({target}) {
});
if (target.value === 'local') {
storageManager.migrateData('local');
} else {
optionsOther._fetchSyncData();
}
};
optionsOther._fetchSyncData = function () {
if (confirm('Fetch remote data now?')) {
storageManager.migrateData('sync-fetch');
} else {
storageManager.migrateData('sync');
}

View File

@ -155,10 +155,17 @@ options._determineOptionValues = function () {
optionKeys = Object.keys(optionList);
storageManager.type.get(optionKeys, function (items) {
options._optionValues = items;
resolve();
});
if (options._storageType === 'sync') {
chrome.storage.sync.get(optionKeys, function (items) {
options._optionValues = items;
resolve();
});
} else {
chrome.storage.local.get(optionKeys, function (items) {
options._optionValues = items;
resolve();
});
}
});
};
@ -278,9 +285,15 @@ options.onOptionChanged = function ({target}) {
break;
}
storageManager.type.set({
[optionKey]: optionValue,
});
if (options._storageType === 'sync') {
chrome.storage.sync.set({
[optionKey]: optionValue,
});
} else {
chrome.storage.local.set({
[optionKey]: optionValue,
});
}
};
options._onLinkClick = function (url) {

View File

@ -52,6 +52,10 @@
<ul>
<li>Block all non GET requests to CDN (<a href="https://codeberg.org/nobody/LocalCDN/issues/1226">#1226</a>)</li>
</ul>
<p>Fixed</p>
<ul>
<li>Synchronize settings (<a href="https://codeberg.org/nobody/LocalCDN/issues/1223">#1223</a>)</li>
</ul>
</div>
<div id="generator-section">
<div class="topic-label">