Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
Add support for Firefox 45 ESR
Browse files Browse the repository at this point in the history
Known issue: Options page not displayed by this version (but on-off-toolbar-button works).

In theory this should also work in Thunderbird, but could not be tested unfortunately.
  • Loading branch information
ntninja committed Jan 10, 2017
1 parent 282ef7a commit ba8327c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 36 deletions.
26 changes: 26 additions & 0 deletions webextension/gecko45-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Wrapper for old storage API in FireFox 45 – 48
if(browser.storage.local.get([], () => {}) === undefined) {
let _storage_get = browser.storage.local.get;
let _storage_set = browser.storage.local.set;

browser.storage.local.get = function(keys) {
// List of storage keys is mandatory in this browser version
if(!keys) {
keys = Object.keys(OPTIONS_DEFAULT);
}

// Interestingly enough the browser actually resolves the internally returned promise
// and calls a (non-standard) callback parameter instead
return new Promise((callback, errback) => {
_storage_get(keys, callback);
});
}

browser.storage.local.set = function(options) {
// Interestingly enough the browser actually resolves the internally returned promise
// and calls a (non-standard) callback parameter instead
return new Promise((callback, errback) => {
_storage_set(options, callback);
});
}
}
2 changes: 1 addition & 1 deletion webextension/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ browser.storage.onChanged.addListener((changes, areaName) => {
});

browser.browserAction.onClicked.addListener((tab) => {
browser.storage.local.get("enable").then((result) => {
browser.storage.local.get(["enable"]).then((result) => {
return browser.storage.local.set({ enable: !result.enable });
}).catch(console.exception);
});
68 changes: 33 additions & 35 deletions webextension/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,41 @@ const OPTIONS_DEFAULT = {
let options = Object.assign({}, OPTIONS_DEFAULT);
let policy = new Policy(options.allow);

document.addEventListener("DOMContentLoaded", function() {
// Now load all currently set options from storage
browser.storage.local.get().then((result) => {
// Update the default options with the real ones loaded from storage
Object.assign(options, result);

// Write back the final option list so that the defaults are properly displayed on the
// options page as well
return browser.storage.local.set(options);
}).then(() => {
// Keep track of new developments in option land
browser.storage.onChanged.addListener((changes, areaName) => {
if(areaName !== "local") {
return;
}

// Apply change
for(let name of Object.keys(changes)) {
options[name] = changes[name].newValue;
}
});

// Done setting up options
}).then(() => {
// Do initial policy fetch (will cause timer for more updates to be set)
updatePolicy();
// Now load all currently set options from storage
browser.storage.local.get().then((result) => {
// Update the default options with the real ones loaded from storage
Object.assign(options, result);

// Write back the final option list so that the defaults are properly displayed on the
// options page as well
return browser.storage.local.set(options);
}).then(() => {
// Keep track of new developments in option land
browser.storage.onChanged.addListener((changes, areaName) => {
if(areaName !== "local") {
return;
}

// Also update policy when its settings are changed
browser.storage.onChanged.addListener((changes, areaName) => {
for(let name of Object.keys(changes)) {
if(areaName === "local" && (name === "allow" || name === "whitelist")) {
updatePolicy();
}
// Apply change
for(let name of Object.keys(changes)) {
options[name] = changes[name].newValue;
}
});

// Done setting up options
}).then(() => {
// Do initial policy fetch (will cause timer for more updates to be set)
updatePolicy();

// Also update policy when its settings are changed
browser.storage.onChanged.addListener((changes, areaName) => {
for(let name of Object.keys(changes)) {
if(areaName === "local" && (name === "allow" || name === "whitelist")) {
updatePolicy();
}
});
}).catch(console.exception);
});
}
});
}).catch(console.exception);


/**
Expand Down
9 changes: 9 additions & 0 deletions webextension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"icons": {
"256": "icon.svg"
},

"applications": {
"gecko": {
"id": "smart-referer@meh.paranoid.pk",
"strict_min_version": "45.0"
}
},

"permissions": [
"*://meh.schizofreni.co/smart-referer/whitelist.txt",
Expand All @@ -31,6 +38,8 @@
"scripts": [
"deps/public-suffix-list/dist/psl.js",

"gecko45-shim.js",

"icon.js",
"policy.js",
"main.js"
Expand Down

0 comments on commit ba8327c

Please sign in to comment.