From 93e082dfa376f4ca63628a9a0eb70a8a83a88592 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Wed, 22 Feb 2023 21:08:00 +0100 Subject: Handle config updates dynamically --- background.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/background.js b/background.js index 59c6c2b..0df541a 100644 --- a/background.js +++ b/background.js @@ -43,23 +43,25 @@ function setIcon(icon) { browser.browserAction.setIcon({ path: "icons/" + icon + ".png" }); } -function onReady() { - // Listen for all header receive events, which contain the cert details we want - browser.webRequest.onHeadersReceived.addListener( - onHeaderReceive, - { - urls: [""] - }, - [ - "blocking" - ] - ); -} +// Listen for all header receive events, which contain the cert details we want +browser.webRequest.onHeadersReceived.addListener( + onHeaderReceive, + { + urls: [""] + }, + [ + "blocking" + ] +); -// Fetch config for certs list -const getting = browser.storage.sync.get("certs"); -getting.then(saved => { - certs = saved.certs; - console.log("certs=" + certs) - onReady(); -}, console.error); \ No newline at end of file +function updateCerts() { + const getting = browser.storage.sync.get("certs"); + getting.then(saved => { + certs = saved.certs; + console.log("certs=" + certs) + }, console.error) +} +// Listen to config change for certs list +browser.storage.local.onChanged.addListener(() => updateCerts()); +// Initial config fetch +updateCerts(); \ No newline at end of file -- cgit