Fixed redirect toggles set to false being reset

Closes https://github.com/libredirect/libredirect/issues/499
This commit is contained in:
Hygna 2022-10-21 19:24:55 +01:00
parent c86fe25b44
commit 51bb4e1557
No known key found for this signature in database
4 changed files with 17 additions and 32 deletions

View File

@ -4,6 +4,7 @@
"useTabs": true, "useTabs": true,
"arrowParens": "avoid", "arrowParens": "avoid",
"printWidth": 200, "printWidth": 200,
"bracketSameLine": true,
"overrides": [ "overrides": [
{ {
"files": ["*.js", "*.json"], "files": ["*.js", "*.json"],

View File

@ -716,7 +716,11 @@ function processUpdate() {
for (const service in config.services) { for (const service in config.services) {
if (!options[service]) options[service] = {} if (!options[service]) options[service] = {}
if (config.services[service].targets == "datajson") targets[service] = redirects[service] if (config.services[service].targets == "datajson") targets[service] = redirects[service]
for (const defaultOption in config.services[service].options) if (!options[service][defaultOption]) options[service][defaultOption] = config.services[service].options[defaultOption] for (const defaultOption in config.services[service].options) {
if (options[service][defaultOption] === undefined) {
options[service][defaultOption] = config.services[service].options[defaultOption]
}
}
for (const frontend in config.services[service].frontends) { for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) { if (config.services[service].frontends[frontend].instanceList) {
if (!options[frontend]) options[frontend] = {} if (!options[frontend]) options[frontend] = {}
@ -733,6 +737,11 @@ function processUpdate() {
} }
} }
} }
} else {
for (const instance of options[frontend][network].enabled) {
let i = redirects[frontend][network].indexOf(instance)
if (i < 0) options[frontend][network].enabled.splice(i, 1)
}
} }
} }
} }
@ -784,34 +793,6 @@ function modifyContentSecurityPolicy(details) {
} }
} }
function processEnabledInstanceList() {
return new Promise(resolve => {
fetch("/config/config.json")
.then(response => response.text())
.then(configData => {
const config = JSON.parse(configData)
browser.storage.local.get(["redirects", "options"], r => {
let options = r.options
for (const service in config.services) {
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {
for (const network in config.networks) {
for (const instance of options[frontend][network].enabled) {
let i = redirects[frontend][network].indexOf(instance)
if (i < 0) options[frontend][network].enabled.splice(i, 1)
}
}
}
}
}
browser.storage.local.set({ options }, () => {
resolve()
})
})
})
})
}
export default { export default {
redirect, redirect,
computeService, computeService,
@ -823,5 +804,4 @@ export default {
upgradeOptions, upgradeOptions,
processUpdate, processUpdate,
modifyContentSecurityPolicy, modifyContentSecurityPolicy,
processEnabledInstanceList,
} }

View File

@ -163,7 +163,12 @@
"instanceList": true "instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com(\\/|$)", "^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com(\\/|$)", "^https?:\\/{2}platform\\.twitter\\.com/embed(\\/|$)", "^https?:\\/{2}t\\.co(\\/|$)"], "targets": [
"^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com(\\/|$)",
"^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com(\\/|$)",
"^https?:\\/{2}platform\\.twitter\\.com/embed(\\/|$)",
"^https?:\\/{2}t\\.co(\\/|$)"
],
"name": "Twitter", "name": "Twitter",
"options": { "options": {
"enabled": true, "enabled": true,

View File

@ -37,7 +37,6 @@ browser.runtime.onInstalled.addListener(details => {
break break
default: default:
await servicesHelper.processUpdate() await servicesHelper.processUpdate()
await servicesHelper.processEnabledInstanceList()
} }
} }
}) })