Skip to content

Commit

Permalink
chore(#266): add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
vitonsky committed Apr 13, 2023
1 parent 95f9677 commit de9d9ac
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions src/app/ConfigStorage/ConfigStorage.migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const migrations: Migration[] = [
},
},
{
version: 4,
version: 5,
async migrate() {
const storageName = 'appConfig';

Expand All @@ -89,40 +89,22 @@ const migrations: Migration[] = [
actualData = {};
}

// Write data
browser.storage.local.set({
[storageName]: {
ttsModule: DEFAULT_TTS,
...actualData,
pageTranslator: {
enableContextMenu: false,
...actualData?.pageTranslator,
},
const updatedConfig = {
ttsModule: DEFAULT_TTS,
...actualData,
pageTranslator: {
enableContextMenu: false,
toggleTranslationHotkey: null,
...actualData?.pageTranslator,
},
});
},
},
{
version: 5,
async migrate() {
const storageName = 'appConfig';
};

let { [storageName]: actualData } = await browser.storage.local.get(
storageName,
);
if (typeof actualData !== 'object') {
actualData = {};
if (actualData.translatorModule === 'BingTranslatorPublic') {
updatedConfig.translatorModule = DEFAULT_TRANSLATOR;
}

if (actualData.translatorModule !== 'BingTranslatorPublic') return;

// Fallback bing translator
browser.storage.local.set({
[storageName]: {
...actualData,
translatorModule: DEFAULT_TRANSLATOR,
},
});
// Write data
browser.storage.local.set({ [storageName]: updatedConfig });
},
},
];
Expand Down

0 comments on commit de9d9ac

Please sign in to comment.