Skip to content

Commit

Permalink
Remove instances not in the redirects list from the enabled list
Browse files Browse the repository at this point in the history
  • Loading branch information
RustomDuck committed Oct 17, 2022
1 parent 7230df1 commit af74a07
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/assets/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,34 @@ 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 {
redirect,
computeService,
Expand All @@ -795,4 +823,5 @@ export default {
upgradeOptions,
processUpdate,
modifyContentSecurityPolicy,
processEnabledInstanceList,
}
3 changes: 2 additions & 1 deletion src/assets/javascripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function updateInstances() {
await initBlackList()
const instances = JSON.parse(http.responseText)

servicesHelper.setRedirects(instances)
await servicesHelper.setRedirects(instances)
await servicesHelper.processEnabledInstanceList()

console.info("Successfully updated Instances")
resolve(true)
Expand Down
2 changes: 1 addition & 1 deletion src/instances/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1884,4 +1884,4 @@
"https://diode.zone",
"https://peertube.nomagic.uk"
]
}
}
2 changes: 2 additions & 0 deletions src/pages/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ browser.runtime.onInstalled.addListener(details => {
await generalHelper.initDefaults()
await servicesHelper.initDefaults()
await servicesHelper.upgradeOptions()
await servicesHelper.processEnabledInstanceList()
}
})
break
default:
await servicesHelper.processUpdate()
await servicesHelper.processEnabledInstanceList()
}
})
})
Expand Down
16 changes: 9 additions & 7 deletions src/pages/options/widgets/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ async function getConfig() {
}

function setOption(option, type, event) {
browser.storage.local.get("options", r => {
let options = r.options
browser.storage.local.set({ options })
})

browser.storage.local.get("options", r => {
let options = r.options
if (type == "select") {
Expand Down Expand Up @@ -82,13 +77,20 @@ importSettingsElement.addEventListener("change", () => {
await generalHelper.initDefaults()
await servicesHelper.initDefaults()
await servicesHelper.upgradeOptions()
await servicesHelper.processEnabledInstanceList()
location.reload()
})
})
})
)
} else if ("version" in data) browser.storage.local.set({ options: data }, () => location.reload())
else {
} else if ("version" in data) {
let options = data
delete options.version
browser.storage.local.set({ options: data }, async () => {
await servicesHelper.processEnabledInstanceList()
location.reload()
})
} else {
console.log("incompatible settings")
importError()
}
Expand Down

0 comments on commit af74a07

Please sign in to comment.