mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Centralized settings management
This commit is contained in:
parent
18df3f97fe
commit
2193313980
24 changed files with 917 additions and 912 deletions
32
lib/frame.js
32
lib/frame.js
|
@ -4,6 +4,7 @@
|
|||
(function(){
|
||||
"use strict";
|
||||
|
||||
const settings = require("./settings");
|
||||
const {intercept} = require("./intercept.js");
|
||||
const {ask} = require("./askForPermission.js");
|
||||
const lists = require("./lists.js");
|
||||
|
@ -46,6 +47,7 @@
|
|||
var port = browser.runtime.connect();
|
||||
var tabId;
|
||||
port.onMessage.addListener(function(data){
|
||||
message("Got data from port", data);
|
||||
if (data.hasOwnProperty("tabId")){
|
||||
notice("my tab id is", data.tabId);
|
||||
tabId = data.tabId;
|
||||
|
@ -64,8 +66,6 @@
|
|||
settings[key] = data.settings[key];
|
||||
});
|
||||
settings.isStillDefault = false;
|
||||
logging.clearQueue();
|
||||
lists.updateAll();
|
||||
}
|
||||
});
|
||||
var notifications = [];
|
||||
|
@ -141,22 +141,9 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
if (settings.isStillDefault){
|
||||
message("load settings");
|
||||
browser.storage.local.get().then(function(data){
|
||||
Object.keys(data).forEach(function(key){
|
||||
notice("loaded setting:", key, ":", data[key]);
|
||||
settings[key] = data[key];
|
||||
});
|
||||
settings.isStillDefault = false;
|
||||
logging.clearQueue();
|
||||
lists.updateAll();
|
||||
interceptWindow(window);
|
||||
});
|
||||
}
|
||||
else {
|
||||
settings.onloaded(function(){
|
||||
interceptWindow(window);
|
||||
}
|
||||
});
|
||||
|
||||
message("register listener for messages from background script");
|
||||
browser.runtime.onMessage.addListener(function(data){
|
||||
|
@ -175,15 +162,4 @@
|
|||
notice("notifications sent");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
message("register listener for settings changes");
|
||||
browser.storage.onChanged.addListener(function(change, area){
|
||||
if (area === "local"){
|
||||
Object.keys(change).forEach(function(key){
|
||||
notice("setting changed:", key, ":", change[key].newValue);
|
||||
settings[key] = change[key].newValue;
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue