Persist state between relaunches for Firefox

This commit is contained in:
Ilya Ig. Petrov 2017-11-22 16:03:20 +05:00
parent a35ab098d4
commit 4738bcf9af
2 changed files with 10 additions and 13 deletions

View File

@ -256,11 +256,13 @@
if (!chrome.proxy.settings) { if (!chrome.proxy.settings) {
let currentSettings = {}; const ffxStore = window.utils.createStorage('firefox-only');
chrome.proxy.settings = { chrome.proxy.settings = {
get: (_, cb) => { get: (_, cb) => {
let currentSettings = ffxStore('proxySettings') || {};
currentSettings.levelOfControl = 'controlled_by_this_extension'; // May be lie, but this field is required. currentSettings.levelOfControl = 'controlled_by_this_extension'; // May be lie, but this field is required.
cb(currentSettings); cb(currentSettings);
@ -274,14 +276,19 @@
browser.proxy.register('./default.pac.js'); browser.proxy.register('./default.pac.js');
browser.proxy.onProxyError.addListener((...err) => { console.log('ERROR IN PAC:', ...err) }); // browser.proxy.onProxyError.addListener((...err) => { console.log('ERROR IN PAC:', ...err) });
browser.runtime.sendMessage(details, {toProxyScript: true}); browser.runtime.sendMessage(details, {toProxyScript: true});
currentSettings = details; ffxStore('proxySettings', details);
cb(); cb();
}, },
}; };
const proxySettings = ffxStore('proxySettings');
if (proxySettings) {
chrome.proxy.settings.set(proxySettings);
}
} }
} }

View File

@ -242,12 +242,6 @@
}, },
clearLastModified() {
this.setLastModified(0);
},
mustBeKey(key = mandatory()) { mustBeKey(key = mandatory()) {
if ( !(key === null || this.pacProviders[key]) ) { if ( !(key === null || this.pacProviders[key]) ) {
@ -525,10 +519,6 @@
// LAUNCH, RELOAD, ENABLE // LAUNCH, RELOAD, ENABLE
antiCensorRu.pacProviders = oldStorage.pacProviders; antiCensorRu.pacProviders = oldStorage.pacProviders;
console.log('Extension launched, reloaded or enabled.'); console.log('Extension launched, reloaded or enabled.');
if (window.apis.platform.ifFirefox) {
antiCensorRu.clearLastModified();
await new Promise((r) => antiCensorRu.syncWithPacProviderAsync(r)); // On each launch, ffx has no memory.
}
return resolve(); return resolve();
} }