Skip to content

Commit

Permalink
feat: enable Local Storage and IndexedDB clearing for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jan 18, 2018
1 parent 21a929e commit a6306be
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/_locales/en/messages-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
52 changes: 52 additions & 0 deletions src/storage/versions/local/ByCtvupNz.js
Original file line number Diff line number Diff line change
@@ -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
};
2 changes: 1 addition & 1 deletion src/storage/versions/local/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"versions": ["xO0Hh1Vm2", "BkFsUtt7f"]}
{"versions": ["xO0Hh1Vm2", "BkFsUtt7f", "ByCtvupNz"]}
52 changes: 52 additions & 0 deletions src/storage/versions/sync/ByCtvupNz.js
Original file line number Diff line number Diff line change
@@ -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
};
2 changes: 1 addition & 1 deletion src/storage/versions/sync/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"versions": ["xO0Hh1Vm2", "BkFsUtt7f"]}
{"versions": ["xO0Hh1Vm2", "BkFsUtt7f", "ByCtvupNz"]}

0 comments on commit a6306be

Please sign in to comment.