diff --git a/background.js b/background.js index 22f8b6a..9078264 100644 --- a/background.js +++ b/background.js @@ -530,6 +530,7 @@ async function dnsBlockListener(details) { } function setDnsBlocking(onOrOff) { + console.log('DNS blocking set request: '+onOrOff); let isCurrentlyOn = browser.webRequest.onBeforeRequest.hasListener(dnsBlockListener); if(onOrOff != isCurrentlyOn) { shouldUseDnsBlocking = onOrOff; @@ -545,6 +546,8 @@ function setDnsBlocking(onOrOff) { browser.webRequest.onBeforeRequest.removeListener(dnsBlockListener); } console.log('DNS blocking is now: '+onOrOff); + } else { + console.log('DNS blocking is already correctly set.'); } } @@ -737,6 +740,11 @@ browser.webRequest.onHeadersReceived.addListener( ); ////////////////////////Actual Startup////////////////////////////// +function updateFromSettings() { + browser.storage.local.get("is_dns_blocking").then(dnsResult=> + setDnsBlocking(dnsResult.is_dns_blocking == true)); +} + function handleMessage(request, sender, sendResponse) { if(request.type=='setZone') { @@ -756,10 +764,11 @@ function handleMessage(request, sender, sendResponse) { } else if(request.type=='setDnsBlocking') { - setDnsBlocking(request.value); + updateFromSettings(); } } browser.runtime.onMessage.addListener(handleMessage); setZone('neutral'); browser.browserAction.setIcon({path: "icons/wingman_icon_32.png"}); -wingman_startup(); \ No newline at end of file +wingman_startup(); +updateFromSettings(); \ No newline at end of file diff --git a/options.js b/options.js index 320f750..dca4999 100644 --- a/options.js +++ b/options.js @@ -1,14 +1,14 @@ -function saveOptions() { +async function saveOptions() { let isDnsBlocking = document.querySelector('input[name="dns_blocking"]:checked').value == "dns_blocking_yes"; - browser.storage.local.set({ - is_dns_blocking: isDnsBlocking + await browser.storage.local.set({ + is_dns_blocking: isDnsBlocking }); browser.runtime.sendMessage({ type: 'setDnsBlocking', value: isDnsBlocking }); - } - - function restoreOptions() { +} + +function restoreOptions() { console.log('Restoring saved options'); - + function setCurrentChoice(rawResult) { let result = rawResult.is_dns_blocking; console.log('Setting DNS to '+result); @@ -19,19 +19,19 @@ function saveOptions() { } browser.runtime.sendMessage({ type: 'setDnsBlocking', value: result }); } - + function onError(error) { - console.log(`Error saving: ${error}`); + console.log(`Error saving: ${error}`); } - + let getting = browser.storage.local.get("is_dns_blocking"); getting.then(setCurrentChoice, onError); - } - - document.addEventListener("DOMContentLoaded", restoreOptions); - var radios = document.forms[0].elements["dns_blocking"]; - for(var i = 0, max = radios.length; i < max; i++) { - radios[i].onclick = function() { - saveOptions(); - } - } \ No newline at end of file +} + +document.addEventListener("DOMContentLoaded", restoreOptions); +var radios = document.forms[0].elements["dns_blocking"]; +for(var i = 0, max = radios.length; i < max; i++) { + radios[i].onclick = function() { + saveOptions(); + } +} \ No newline at end of file