Updating v3 data migration
Setting v3migration flag to avoid repeating migration script, along with other general improvementspull/327/head
parent
ae70730683
commit
dc8e54351a
100
background.js
100
background.js
|
@ -41,68 +41,72 @@ chrome.runtime.onInstalled.addListener(async function (detail) {
|
||||||
|
|
||||||
// Temporary functions for 3.0 migration
|
// Temporary functions for 3.0 migration
|
||||||
if (detail.reason === 'update') {
|
if (detail.reason === 'update') {
|
||||||
// Set new default action settings:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
chrome.storage.sync.get({ 'defaultWikiAction': null }, function (item) {
|
if (!storage.v3migration) {
|
||||||
if (!item.defaultWikiAction) {
|
// Set new default action settings:
|
||||||
chrome.storage.sync.get({ 'defaultActionSettings': {} }, function (item) {
|
if (!storage.defaultWikiAction) {
|
||||||
if (item.defaultActionSettings['EN']) {
|
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': item.defaultActionSettings['EN'] });
|
chrome.storage.sync.set({ 'defaultWikiAction': storage.defaultActionSettings['EN'] });
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
if (!storage.defaultSearchAction) {
|
||||||
});
|
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
|
||||||
chrome.storage.sync.get({ 'defaultSearchAction': null }, function (item) {
|
if (storage.defaultSearchFilterSettings['EN'] === 'false') {
|
||||||
if (!item.defaultSearchAction) {
|
|
||||||
chrome.storage.sync.get({ 'defaultSearchFilterSettings': {} }, function (item) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN']) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN'] === 'true') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
|
||||||
} else if (item.defaultSearchFilterSettings['EN'] === 'false') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
||||||
|
} else {
|
||||||
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// Remove old objects
|
||||||
|
chrome.storage.sync.remove('defaultActionSettings');
|
||||||
|
chrome.storage.sync.remove('defaultSearchFilterSettings');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create new searchEngineSettings and wikiSettings objects:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
sites = await getData();
|
if (!storage.v3migration) {
|
||||||
chrome.storage.sync.get(function (storage) {
|
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
|
||||||
let siteSettings = storage.siteSettings || {};
|
sites = await getData();
|
||||||
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
let siteSettings = storage.siteSettings || {};
|
||||||
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
||||||
let searchEngineSettings = storage.searchEngineSettings || {};
|
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
||||||
let wikiSettings = storage.wikiSettings || {};
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
||||||
|
let wikiSettings = storage.wikiSettings || {};
|
||||||
sites.forEach((site) => {
|
|
||||||
if (!searchEngineSettings[site.id]) {
|
sites.forEach((site) => {
|
||||||
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
if (!searchEngineSettings[site.id]) {
|
||||||
if (siteSettings[site.id].searchFilter === 'false') {
|
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
||||||
searchEngineSettings[site.id] = 'disabled';
|
if (siteSettings[site.id].searchFilter === 'false') {
|
||||||
|
searchEngineSettings[site.id] = 'disabled';
|
||||||
|
} else {
|
||||||
|
searchEngineSettings[site.id] = 'replace';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
searchEngineSettings[site.id] = 'replace';
|
searchEngineSettings[site.id] = defaultSearchAction;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
searchEngineSettings[site.id] = defaultSearchAction;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (!wikiSettings[site.id]) {
|
||||||
if (!wikiSettings[site.id]) {
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
||||||
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
||||||
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
||||||
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
|
||||||
|
// Remove old objects:
|
||||||
|
chrome.storage.sync.remove('siteSettings');
|
||||||
|
|
||||||
|
// Mark v3 migration as complete:
|
||||||
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove old objects:
|
|
||||||
chrome.storage.sync.remove('siteSettings');
|
|
||||||
chrome.storage.sync.remove('defaultActionSettings');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
92
popup.js
92
popup.js
|
@ -30,68 +30,72 @@ async function getData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateData() {
|
async function migrateData() {
|
||||||
// Set new default action settings:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
chrome.storage.sync.get({ 'defaultWikiAction': null }, function (item) {
|
if (!storage.v3migration) {
|
||||||
if (!item.defaultWikiAction) {
|
// Set new default action settings:
|
||||||
chrome.storage.sync.get({ 'defaultActionSettings': {} }, function (item) {
|
if (!storage.defaultWikiAction) {
|
||||||
if (item.defaultActionSettings['EN']) {
|
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': item.defaultActionSettings['EN'] });
|
chrome.storage.sync.set({ 'defaultWikiAction': storage.defaultActionSettings['EN'] });
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
if (!storage.defaultSearchAction) {
|
||||||
});
|
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
|
||||||
chrome.storage.sync.get({ 'defaultSearchAction': null }, function (item) {
|
if (storage.defaultSearchFilterSettings['EN'] === 'false') {
|
||||||
if (!item.defaultSearchAction) {
|
|
||||||
chrome.storage.sync.get({ 'defaultSearchFilterSettings': {} }, function (item) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN']) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN'] === 'true') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
|
||||||
} else if (item.defaultSearchFilterSettings['EN'] === 'false') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
||||||
|
} else {
|
||||||
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// Remove old objects
|
||||||
|
chrome.storage.sync.remove('defaultActionSettings');
|
||||||
|
chrome.storage.sync.remove('defaultSearchFilterSettings');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create new searchEngineSettings and wikiSettings objects:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
sites = await getData();
|
if (!storage.v3migration) {
|
||||||
chrome.storage.sync.get(function (storage) {
|
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
|
||||||
let siteSettings = storage.siteSettings || {};
|
sites = await getData();
|
||||||
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
let siteSettings = storage.siteSettings || {};
|
||||||
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
||||||
let searchEngineSettings = storage.searchEngineSettings || {};
|
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
||||||
let wikiSettings = storage.wikiSettings || {};
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
||||||
|
let wikiSettings = storage.wikiSettings || {};
|
||||||
|
|
||||||
sites.forEach((site) => {
|
sites.forEach((site) => {
|
||||||
if (!searchEngineSettings[site.id]) {
|
if (!searchEngineSettings[site.id]) {
|
||||||
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
||||||
if (siteSettings[site.id].searchFilter === 'false') {
|
if (siteSettings[site.id].searchFilter === 'false') {
|
||||||
searchEngineSettings[site.id] = 'disabled';
|
searchEngineSettings[site.id] = 'disabled';
|
||||||
|
} else {
|
||||||
|
searchEngineSettings[site.id] = 'replace';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
searchEngineSettings[site.id] = 'replace';
|
searchEngineSettings[site.id] = defaultSearchAction;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
searchEngineSettings[site.id] = defaultSearchAction;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!wikiSettings[site.id]) {
|
if (!wikiSettings[site.id]) {
|
||||||
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
||||||
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
||||||
|
|
||||||
|
// Remove old objects:
|
||||||
|
chrome.storage.sync.remove('siteSettings');
|
||||||
|
|
||||||
|
// Mark v3 migration as complete:
|
||||||
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove old objects:
|
|
||||||
chrome.storage.sync.remove('siteSettings');
|
|
||||||
chrome.storage.sync.remove('defaultActionSettings');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate BreezeWiki dropdown when enabled
|
// Populate BreezeWiki dropdown when enabled
|
||||||
|
|
92
settings.js
92
settings.js
|
@ -607,68 +607,72 @@ function setBreezeWiki(setting, storeSetting = true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function migrateData() {
|
async function migrateData() {
|
||||||
// Set new default action settings:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
chrome.storage.sync.get({ 'defaultWikiAction': null }, function (item) {
|
if (!storage.v3migration) {
|
||||||
if (!item.defaultWikiAction) {
|
// Set new default action settings:
|
||||||
chrome.storage.sync.get({ 'defaultActionSettings': {} }, function (item) {
|
if (!storage.defaultWikiAction) {
|
||||||
if (item.defaultActionSettings['EN']) {
|
if (storage.defaultActionSettings && storage.defaultActionSettings['EN']) {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': item.defaultActionSettings['EN'] });
|
chrome.storage.sync.set({ 'defaultWikiAction': storage.defaultActionSettings['EN'] });
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
chrome.storage.sync.set({ 'defaultWikiAction': 'alert' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
if (!storage.defaultSearchAction) {
|
||||||
});
|
if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings['EN']) {
|
||||||
chrome.storage.sync.get({ 'defaultSearchAction': null }, function (item) {
|
if (storage.defaultSearchFilterSettings['EN'] === 'false') {
|
||||||
if (!item.defaultSearchAction) {
|
|
||||||
chrome.storage.sync.get({ 'defaultSearchFilterSettings': {} }, function (item) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN']) {
|
|
||||||
if (item.defaultSearchFilterSettings['EN'] === 'true') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
|
||||||
} else if (item.defaultSearchFilterSettings['EN'] === 'false') {
|
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' });
|
||||||
|
} else {
|
||||||
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
chrome.storage.sync.set({ 'defaultSearchAction': 'replace' });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// Remove old objects
|
||||||
|
chrome.storage.sync.remove('defaultActionSettings');
|
||||||
|
chrome.storage.sync.remove('defaultSearchFilterSettings');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create new searchEngineSettings and wikiSettings objects:
|
await chrome.storage.sync.get(async (storage) => {
|
||||||
sites = await getData();
|
if (!storage.v3migration) {
|
||||||
chrome.storage.sync.get(function (storage) {
|
// Migrate wiki settings to new searchEngineSettings and wikiSettings objects
|
||||||
let siteSettings = storage.siteSettings || {};
|
sites = await getData();
|
||||||
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
let siteSettings = storage.siteSettings || {};
|
||||||
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
let defaultWikiAction = storage.defaultWikiAction || 'alert';
|
||||||
let searchEngineSettings = storage.searchEngineSettings || {};
|
let defaultSearchAction = storage.defaultSearchAction || 'replace';
|
||||||
let wikiSettings = storage.wikiSettings || {};
|
let searchEngineSettings = storage.searchEngineSettings || {};
|
||||||
|
let wikiSettings = storage.wikiSettings || {};
|
||||||
|
|
||||||
sites.forEach((site) => {
|
sites.forEach((site) => {
|
||||||
if (!searchEngineSettings[site.id]) {
|
if (!searchEngineSettings[site.id]) {
|
||||||
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
if (siteSettings[site.id] && siteSettings[site.id].searchFilter) {
|
||||||
if (siteSettings[site.id].searchFilter === 'false') {
|
if (siteSettings[site.id].searchFilter === 'false') {
|
||||||
searchEngineSettings[site.id] = 'disabled';
|
searchEngineSettings[site.id] = 'disabled';
|
||||||
|
} else {
|
||||||
|
searchEngineSettings[site.id] = 'replace';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
searchEngineSettings[site.id] = 'replace';
|
searchEngineSettings[site.id] = defaultSearchAction;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
searchEngineSettings[site.id] = defaultSearchAction;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!wikiSettings[site.id]) {
|
if (!wikiSettings[site.id]) {
|
||||||
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
wikiSettings[site.id] = siteSettings[site.id]?.action || defaultWikiAction;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
chrome.storage.sync.set({ 'searchEngineSettings': searchEngineSettings });
|
||||||
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
chrome.storage.sync.set({ 'wikiSettings': wikiSettings });
|
||||||
|
|
||||||
|
// Remove old objects:
|
||||||
|
chrome.storage.sync.remove('siteSettings');
|
||||||
|
|
||||||
|
// Mark v3 migration as complete:
|
||||||
|
chrome.storage.sync.set({ 'v3migration': 'done' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove old objects:
|
|
||||||
chrome.storage.sync.remove('siteSettings');
|
|
||||||
chrome.storage.sync.remove('defaultActionSettings');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main function that runs on-load
|
// Main function that runs on-load
|
||||||
|
|
Loading…
Reference in New Issue