Fixed settings conversion on update

This commit is contained in:
ManeraKai 2024-03-11 07:51:30 +03:00
parent b6c98028b9
commit 2a239a2fb2
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 25 additions and 14 deletions

View File

@ -642,7 +642,6 @@ async function reverse(url) {
case "imdb":
case "imgur":
case "tiktok":
case "twitter":
case "reddit":
case "imdb":
case "snopes":
@ -702,7 +701,6 @@ const defaultInstances = {
'4get': ['https://4get.ca'],
'rimgo': ['https://rimgo.vern.cc'],
'hyperpipe': ['https://hyperpipe.surge.sh'],
'facil': [' https://facilmap.org '],
'osm': ['https://www.openstreetmap.org'],
'breezeWiki': ['https://breezewiki.com'],
'neuters': ['https://neuters.de'],
@ -749,12 +747,12 @@ function initDefaults() {
}
}
}
options['exceptions'] = {
options.exceptions = {
url: [],
regex: [],
}
options.theme = "detect"
options.popupServices = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
options.popupServices = ["youtube", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
options.fetchInstances = 'github'
options.redirectOnlyInIncognito = false
@ -781,28 +779,27 @@ function upgradeOptions() {
function processUpdate() {
return new Promise(async resolve => {
let config = await utils.getConfig()
let frontends = []
const config = await utils.getConfig()
let options = await utils.getOptions()
for (const service in config.services) {
if (!options[service]) options[service] = {}
if (!(options[service].frontend in config.services[service].frontends)) {
options[service] = config.services[service].options
delete options[options[service].frontend]
options[service] = config.services[service].options // Reset settings for service
delete options[options[service].frontend] // Remove deprecated frontend
}
for (const defaultOption in config.services[service].options) {
if (options[service][defaultOption] === undefined) {
if (!(defaultOption in options[service])) {
options[service][defaultOption] = config.services[service].options[defaultOption]
}
}
for (const frontend in config.services[service].frontends) {
if (options[frontend] === undefined && config.services[service].frontends[frontend].instanceList) {
options[frontend] = defaultInstances[frontend]
}
else if (frontend in options && !(frontend in config.services[service].frontends)) {
delete options[frontend]
frontends.push(frontend)
if (!(frontend in options) && config.services[service].frontends[frontend].instanceList) {
options[frontend] = defaultInstances[frontend] || []
}
}
@ -813,6 +810,20 @@ function processUpdate() {
}
}
}
const general = ['theme', 'popupServices', 'fetchInstances', 'redirectOnlyInIncognito']
const combined = [
...Object.keys(config.services),
...frontends,
...general,
'exceptions',
'popupServices',
'version',
]
for (const key in options) {
if (combined.indexOf(key) < 0) {
delete options[key] // Remove any unknown settings in options
}
}
browser.storage.local.set({ options }, () => {
resolve()
})

View File

@ -51,7 +51,7 @@ section(class="block-option" id="general_page")
path(d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z")
|&nbsp;
x(data-localise="__MSG_importSettings__") Import Settings
input(id="import-settings" type="file" style="display: none")
input(id="import-settings" type="file" accept=".json" style="display: none")
|&nbsp;&nbsp;