added code for migrating prop name from 0.7 to 0.8

This commit is contained in:
Ilya Ig. Petrov 2016-02-05 21:11:19 +05:00
parent 4dc16667df
commit 03cec0b7bd
2 changed files with 21 additions and 7 deletions

View File

@ -3,7 +3,7 @@
"name": "Ненавязчивый РосКомНадзор", "name": "Ненавязчивый РосКомНадзор",
"description": "Аргументы против цензуры: https://git.io/vEkI9", "description": "Аргументы против цензуры: https://git.io/vEkI9",
"version": "0.0.0.8", "version": "0.0.0.9",
"icons": { "icons": {
"128": "/icons/ribbon128.png" "128": "/icons/ribbon128.png"
}, },

View File

@ -57,21 +57,30 @@ window.antiCensorRu = {
// PROTECTED // PROTECTED
pushToStorage(cb) { pushToStorage(cb) {
// Copy only settable properties.
var onlySettable = {};
for(var key of Object.keys(this))
if (Object.getOwnPropertyDescriptor(this, key).writable && typeof(this[key]) !== 'function')
onlySettable[key] = this[key]
return chrome.storage.local.set(onlySettable, () => cb && cb(chrome.runtime.lastError, onlySettable) ); // Copy only settable properties.
var onlySettable = {};
for(var key of Object.keys(this))
if (Object.getOwnPropertyDescriptor(this, key).writable && typeof(this[key]) !== 'function')
onlySettable[key] = this[key]
return chrome.storage.local.clear(
() => chrome.storage.local.set(
onlySettable,
() => cb && cb(chrome.runtime.lastError, onlySettable)
)
);
}, },
pullFromStorage(cb) { pullFromStorage(cb) {
chrome.storage.local.get(null, storage => { chrome.storage.local.get(null, storage => {
console.log('In storage:', storage);
for(var key of Object.keys(storage)) for(var key of Object.keys(storage))
this[key] = storage[key]; this[key] = storage[key];
console.log('Synced with storage, any callback?', !!cb); console.log('Synced with storage, any callback?', !!cb);
console.log('ifFirstInstall?', this.ifFirstInstall);
if (cb) if (cb)
cb(chrome.runtime.lastError, storage); cb(chrome.runtime.lastError, storage);
}); });
@ -179,6 +188,11 @@ chrome.runtime.onInstalled.addListener( details => {
console.log('Extension just installed, reason:', details.reason); console.log('Extension just installed, reason:', details.reason);
window.storageSyncedPromise.then( window.storageSyncedPromise.then(
storage => { storage => {
// Change property name from version 0.0.0.7
window.antiCensorRu.ifFirstInstall = window.antiCensorRu.ifNotInstalled;
delete window.antiCensorRu.ifNotInstalled;
switch(details.reason) { switch(details.reason) {
case 'update': case 'update':
console.log('Ah, it\'s just an update or reload. Do nothing.'); console.log('Ah, it\'s just an update or reload. Do nothing.');