2018-01-24 01:26:50 +01:00
|
|
|
// We should not rely on local storage in an extension!
|
|
|
|
// We should use this instead!
|
|
|
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
|
|
|
|
|
|
|
|
const extension = require('extensionizer')
|
|
|
|
|
|
|
|
module.exports = class ExtensionStore {
|
|
|
|
constructor() {
|
|
|
|
this.isSupported = !!(extension.storage.local)
|
|
|
|
if (!this.isSupported) {
|
|
|
|
log.error('Storage local API not available.')
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 22:05:13 +01:00
|
|
|
get() {
|
2018-01-24 01:26:50 +01:00
|
|
|
return new Promise((resolve) => {
|
2018-01-25 00:03:16 +01:00
|
|
|
extension.storage.local.get(null, resolve)
|
2018-01-24 01:26:50 +01:00
|
|
|
})
|
|
|
|
}
|
2018-01-24 22:05:13 +01:00
|
|
|
set(state) {
|
2018-01-24 01:26:50 +01:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
extension.storage.local.set(state, resolve)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|