Skip to content

Commit

Permalink
Fixed settings conversion on update
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Mar 11, 2024
1 parent b6c9802 commit 2a239a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions src/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ async function reverse(url) {
case "imdb":
case "imgur":
case "tiktok":
case "twitter":
case "reddit":
case "imdb":
case "snopes":
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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

Expand All @@ -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] || []
}
}

Expand All @@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/options/widgets/general.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2a239a2

Please sign in to comment.