mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-10 19:46:34 +03:00
Migrate storage for <=0.0.1.48. Fix ffx bugs
This commit is contained in:
parent
aa727d9329
commit
c566fcecb5
|
@ -158,6 +158,32 @@ console.log('Extension started.');
|
|||
|
||||
},
|
||||
|
||||
promisedLocalStorage: {
|
||||
get(key) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.get(
|
||||
key,
|
||||
window.utils.getOrDie((storage) => resolve(key ? storage[key] : storage)),
|
||||
)
|
||||
));
|
||||
},
|
||||
set(items) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.set(items, resolve)
|
||||
));
|
||||
},
|
||||
remove(keys) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.remove(keys, resolve)
|
||||
));
|
||||
},
|
||||
clear() {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.clear(resolve)
|
||||
));
|
||||
},
|
||||
},
|
||||
|
||||
/*
|
||||
* Possible values for levelOfControl:
|
||||
*
|
||||
|
|
|
@ -4,27 +4,6 @@ if (window.apis.platform.ifFirefox) {
|
|||
|
||||
const prefix = 'firefox-only';
|
||||
|
||||
const ffxStorage = {
|
||||
get(key) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.get(
|
||||
key,
|
||||
window.utils.getOrDie((obj) => resolve(obj[key])),
|
||||
)
|
||||
));
|
||||
},
|
||||
set(items) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.set(items, resolve)
|
||||
));
|
||||
},
|
||||
remove(keys) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.remove(keys, resolve)
|
||||
));
|
||||
},
|
||||
};
|
||||
|
||||
const originalSet = chrome.proxy.settings.set.bind( chrome.proxy.settings );
|
||||
chrome.proxy.settings.set = function(details, cb) {
|
||||
const pac = window.utils.getProp(details, 'value.pacScript') || {};
|
||||
|
@ -45,52 +24,41 @@ if (window.apis.platform.ifFirefox) {
|
|||
cb();
|
||||
return;
|
||||
}
|
||||
window.pacData = pac.data;
|
||||
window.ffxStorage = ffxStorage;
|
||||
await ffxStorage.set({ [`${prefix}-pac-data`]: pac.data });
|
||||
await window.utils.promisedLocalStorage.set({ [`${prefix}-pac-data`]: pac.data });
|
||||
cb();
|
||||
}));
|
||||
};
|
||||
|
||||
const originalGet = chrome.proxy.settings.get.bind( chrome.proxy.settings );
|
||||
chrome.proxy.settings.get = function(details, cb) {
|
||||
originalGet(details, window.utils.chromified((err, originalDetails) => {
|
||||
originalGet(details, window.utils.chromified(async (err, originalDetails) => {
|
||||
if (err) {
|
||||
window.utils.lastError = err;
|
||||
cb(originalDetails);
|
||||
return;
|
||||
}
|
||||
const autoConfigUrl = window.utils.getProp(originalDetails, 'value.autoConfigUrl');
|
||||
if (!autoConfigUrl) {
|
||||
return cb(originalDetails);
|
||||
let pacData = await window.utils.promisedLocalStorage.get(`${prefix}-pac-data`);
|
||||
if (!pacData || !Object.keys(pacData).length) {
|
||||
cb(originalDetails);
|
||||
return;
|
||||
}
|
||||
window.apis.httpLib.get(autoConfigUrl, async (err, pacData) => {
|
||||
if (err) {
|
||||
pacData = await ffxStorage.get(`${prefix}-pac-data`);
|
||||
if (!pacData || !Object.keys(pacData).length) {
|
||||
window.utils.lastError = err;
|
||||
cb(originalDetails);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cb(Object.assign(
|
||||
originalDetails,
|
||||
{
|
||||
value: {
|
||||
mode: 'pac_script',
|
||||
pacScript: {
|
||||
data: pacData,
|
||||
},
|
||||
cb(Object.assign(
|
||||
originalDetails,
|
||||
{
|
||||
value: {
|
||||
mode: 'pac_script',
|
||||
pacScript: {
|
||||
data: pacData,
|
||||
},
|
||||
}
|
||||
));
|
||||
});
|
||||
},
|
||||
}
|
||||
));
|
||||
}));
|
||||
};
|
||||
|
||||
const originalClear = chrome.proxy.settings.clear.bind( chrome.proxy.settings );
|
||||
chrome.proxy.settings.clear = async function(details, cb) {
|
||||
await ffxStorage.remove(`${prefix}-pac-data`);
|
||||
await window.utils.promisedLocalStorage.remove(`${prefix}-pac-data`);
|
||||
originalClear(details, cb);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -380,10 +380,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
chrome.storage.local.set(
|
||||
onlySettable,
|
||||
chromified(cb),
|
||||
)
|
||||
chrome.storage.local.remove(
|
||||
'antiCensorRu',
|
||||
() => chrome.storage.local.set(
|
||||
{ antiCensorRu: onlySettable },
|
||||
chromified(cb),
|
||||
),
|
||||
);
|
||||
|
||||
},
|
||||
|
||||
|
@ -521,10 +524,18 @@
|
|||
};
|
||||
|
||||
// ON EACH LAUNCH, STARTUP, RELOAD, UPDATE, ENABLE
|
||||
chrome.storage.local.get(null, chromified( async (err, oldStorage) => {
|
||||
(async () => {
|
||||
let oldStorage = await window.utils.promisedLocalStorage.get('antiCensorRu') || {};
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
if (!Object.keys(oldStorage).length) {
|
||||
const storage = await window.utils.promisedLocalStorage.get(null);
|
||||
if (storage.version && window.apis.version.isLeq(storage.version, '0.0.1.48')) {
|
||||
const ffxPacData = storage['firefox-only-pac-data'];
|
||||
delete storage['firefox-only-pac-data'];
|
||||
await window.utils.promisedLocalStorage.clear();
|
||||
await window.utils.promisedLocalStorage.set({ antiCensorRu: storage });
|
||||
oldStorage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -560,7 +571,7 @@
|
|||
console.log('Keep cooked...');
|
||||
await new Promise((resolve) => window.apis.pacKitchen.keepCookedNowAsync(resolve));
|
||||
|
||||
console.log('Storage on init:', oldStorage);
|
||||
//console.log('Storage on init:', oldStorage);
|
||||
antiCensorRu.ifFirstInstall = Object.keys(oldStorage).length === 0;
|
||||
|
||||
if (antiCensorRu.ifFirstInstall) {
|
||||
|
@ -695,6 +706,6 @@
|
|||
* Add storage.lastPacUpdateStamp.
|
||||
**/
|
||||
|
||||
}));
|
||||
})();
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ export default function getLastUpdateDate(theState) {
|
|||
|
||||
componentWillMount() {
|
||||
|
||||
this.onStorageChangedHandler = (changes) =>
|
||||
changes.lastPacUpdateStamp.newValue && this.forceUpdate();
|
||||
this.onStorageChangedHandler = (changes) => {
|
||||
const ac = changes.antiCensorRu;
|
||||
return ac && ac.newValue && ac.newValue.lastPacUpdateStamp && this.forceUpdate();
|
||||
};
|
||||
|
||||
chrome.storage.onChanged.addListener( this.onStorageChangedHandler );
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
|
|||
// winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' });
|
||||
|
||||
theState.flags.ifInsideOptionsPage = !currentTab || /.*:\/\/extensions\/\?options=/g.test(currentTab.url) || currentTab.url.startsWith('about:addons');
|
||||
theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');
|
||||
theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab && currentTab.url.startsWith('edge://');
|
||||
|
||||
theState.currentTab = currentTab;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user