From a6306be08b564bb0710debcbf73ea7c210a202a9 Mon Sep 17 00:00:00 2001 From: dessant Date: Thu, 18 Jan 2018 08:10:37 +0200 Subject: [PATCH] feat: enable Local Storage and IndexedDB clearing for Firefox --- src/_locales/en/messages-firefox.json | 5 +++ src/storage/versions/local/ByCtvupNz.js | 52 ++++++++++++++++++++++++ src/storage/versions/local/versions.json | 2 +- src/storage/versions/sync/ByCtvupNz.js | 52 ++++++++++++++++++++++++ src/storage/versions/sync/versions.json | 2 +- 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/storage/versions/local/ByCtvupNz.js create mode 100644 src/storage/versions/sync/ByCtvupNz.js diff --git a/src/_locales/en/messages-firefox.json b/src/_locales/en/messages-firefox.json index 509ce07..da54ef0 100644 --- a/src/_locales/en/messages-firefox.json +++ b/src/_locales/en/messages-firefox.json @@ -4,6 +4,11 @@ "description": "Title of the menu item." }, + "menuItemTitle_localStorage": { + "message": "Local Storage", + "description": "Title of the menu item." + }, + "menuItemTitle_pluginData": { "message": "Plugin Data", "description": "Title of the menu item." diff --git a/src/storage/versions/local/ByCtvupNz.js b/src/storage/versions/local/ByCtvupNz.js new file mode 100644 index 0000000..b76c414 --- /dev/null +++ b/src/storage/versions/local/ByCtvupNz.js @@ -0,0 +1,52 @@ +import browser from 'webextension-polyfill'; + +import {targetEnv} from 'utils/config'; + +const message = 'Enable localStorage and indexedDB for Firefox'; + +const revision = 'ByCtvupNz'; +const downRevision = 'BkFsUtt7f'; + +const storage = browser.storage.local; + +async function upgrade() { + const changes = {}; + + if (targetEnv === 'firefox') { + const {dataTypes} = await storage.get('dataTypes'); + + changes.dataTypes = dataTypes.concat('localStorage', 'indexedDB'); + } + + changes.storageVersion = revision; + return storage.set(changes); +} + +async function downgrade() { + const changes = {}; + + if (targetEnv === 'firefox') { + const {dataTypes, disabledDataTypes} = await storage.get([ + 'dataTypes', + 'disabledDataTypes' + ]); + + const unsupportedDataTypes = ['indexedDB', 'localStorage']; + changes.dataTypes = dataTypes.filter( + x => unsupportedDataTypes.indexOf(x) === -1 + ); + changes.disabledDataTypes = disabledDataTypes.filter( + x => unsupportedDataTypes.indexOf(x) === -1 + ); + } + + changes.storageVersion = downRevision; + return storage.set(changes); +} + +module.exports = { + message, + revision, + upgrade, + downgrade +}; diff --git a/src/storage/versions/local/versions.json b/src/storage/versions/local/versions.json index 6906023..69aae04 100644 --- a/src/storage/versions/local/versions.json +++ b/src/storage/versions/local/versions.json @@ -1 +1 @@ -{"versions": ["xO0Hh1Vm2", "BkFsUtt7f"]} +{"versions": ["xO0Hh1Vm2", "BkFsUtt7f", "ByCtvupNz"]} diff --git a/src/storage/versions/sync/ByCtvupNz.js b/src/storage/versions/sync/ByCtvupNz.js new file mode 100644 index 0000000..d7d4f33 --- /dev/null +++ b/src/storage/versions/sync/ByCtvupNz.js @@ -0,0 +1,52 @@ +import browser from 'webextension-polyfill'; + +import {targetEnv} from 'utils/config'; + +const message = 'Enable localStorage and indexedDB for Firefox'; + +const revision = 'ByCtvupNz'; +const downRevision = 'BkFsUtt7f'; + +const storage = browser.storage.sync; + +async function upgrade() { + const changes = {}; + + if (targetEnv === 'firefox') { + const {dataTypes} = await storage.get('dataTypes'); + + changes.dataTypes = dataTypes.concat('localStorage', 'indexedDB'); + } + + changes.storageVersion = revision; + return storage.set(changes); +} + +async function downgrade() { + const changes = {}; + + if (targetEnv === 'firefox') { + const {dataTypes, disabledDataTypes} = await storage.get([ + 'dataTypes', + 'disabledDataTypes' + ]); + + const unsupportedDataTypes = ['indexedDB', 'localStorage']; + changes.dataTypes = dataTypes.filter( + x => unsupportedDataTypes.indexOf(x) === -1 + ); + changes.disabledDataTypes = disabledDataTypes.filter( + x => unsupportedDataTypes.indexOf(x) === -1 + ); + } + + changes.storageVersion = downRevision; + return storage.set(changes); +} + +module.exports = { + message, + revision, + upgrade, + downgrade +}; diff --git a/src/storage/versions/sync/versions.json b/src/storage/versions/sync/versions.json index 6906023..69aae04 100755 --- a/src/storage/versions/sync/versions.json +++ b/src/storage/versions/sync/versions.json @@ -1 +1 @@ -{"versions": ["xO0Hh1Vm2", "BkFsUtt7f"]} +{"versions": ["xO0Hh1Vm2", "BkFsUtt7f", "ByCtvupNz"]}