mirror of
https://github.com/NohamR/BetterYGG.git
synced 2026-01-10 08:18:19 +00:00
[1.2] Migration mechanism put in place
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
var categories = [{
|
||||
var defaults = {
|
||||
defaultCategories: [{
|
||||
name: "tv_show",
|
||||
season: true,
|
||||
urls: ["/filmvid%C3%A9o/s%C3%A9rie-tv/", "/filmvideo/serie-tv/"],
|
||||
@@ -15,15 +16,41 @@ var categories = [{
|
||||
"/filmvid%C3%A9o/animation/",
|
||||
"/filmvideo/animation/"
|
||||
],
|
||||
}],
|
||||
},
|
||||
];
|
||||
storageSchema: 1 // Increment this when data format changes
|
||||
};
|
||||
|
||||
chrome.runtime.onInstalled.addListener(function(details){
|
||||
if(details.reason === "install"){
|
||||
chrome.storage.sync.set(defaults);
|
||||
chrome.storage.sync.set({ 'categories': defaults.defaultCategories});
|
||||
} else if(details.reason === "update"){
|
||||
migrateData();
|
||||
}
|
||||
});
|
||||
|
||||
function migrateData() {
|
||||
if(details.reason == "install"){
|
||||
chrome.storage.sync.set({ 'defaultCategories': categories});
|
||||
chrome.storage.sync.set({ 'categories': categories});
|
||||
// This pulls stored values, falling back to defaults, if none
|
||||
chrome.storage.sync.get(defaults, function (data) {
|
||||
var migrated = false;
|
||||
while (!migrated) {
|
||||
switch (data.storageSchema) {
|
||||
// case 1:
|
||||
// /* modify data to migrate from 1.0-1.2 to 1.3 */
|
||||
// data.storageSchema = 2;
|
||||
// break;
|
||||
case defaults.storageSchema: // Expected; we're done migrating
|
||||
migrated = true;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unrecognized storage schema ${data.storageSchema}!`);
|
||||
}
|
||||
}
|
||||
if(details.reason == "update"){
|
||||
chrome.storage.sync.set({ 'defaultCategories': categories});
|
||||
}
|
||||
});
|
||||
chrome.storage.sync.set(defaults);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "BetterYGG",
|
||||
"version": "1.1",
|
||||
"version": "1.2",
|
||||
"description": "Téléchargez des torrents sur YGG sans ètre connecté et autres !!!",
|
||||
"icons": {
|
||||
"16": "img/flexgg16.png",
|
||||
@@ -49,4 +49,4 @@
|
||||
}
|
||||
],
|
||||
"manifest_version": 2
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user