|
|
|
// disallow promises from swallowing errors
|
|
|
|
enableFailureOnUnhandledPromiseRejection()
|
|
|
|
|
|
|
|
// logging util
|
|
|
|
var log = require('loglevel')
|
|
|
|
log.setDefaultLevel(5)
|
|
|
|
global.log = log
|
|
|
|
|
|
|
|
//
|
|
|
|
// polyfills
|
|
|
|
//
|
|
|
|
|
|
|
|
// dom
|
Made configuration migrateable
Abstract all configuration data into a singleton called `configManager`, who is responsible for reading and writing to the persisted storage (localStorage, in our case).
Uses my new module [pojo-migrator](https://www.npmjs.com/package/pojo-migrator), and wraps it with the `ConfigManager` class, which we can hang any state setting or getting methods we need.
By keeping all the persisted state in one place, we can stabilize its outward-facing API, making the interactions increasingly atomic, which will allow us to add features that require restructuring the persisted data in the long term without having to rewrite UI or even `background.js` code.
All the restructuring and data-type management is kept in one neat little place.
This should make it very easy to add new configuration options like user-configured providers, per-domain vaults, and more!
I know this doesn't seem like a big user-facing feature, but we have a big laundry list of features that I think this will really help streamline.
9 years ago
|
|
|
require('jsdom-global')()
|
|
|
|
|
|
|
|
// localStorage
|
Made configuration migrateable
Abstract all configuration data into a singleton called `configManager`, who is responsible for reading and writing to the persisted storage (localStorage, in our case).
Uses my new module [pojo-migrator](https://www.npmjs.com/package/pojo-migrator), and wraps it with the `ConfigManager` class, which we can hang any state setting or getting methods we need.
By keeping all the persisted state in one place, we can stabilize its outward-facing API, making the interactions increasingly atomic, which will allow us to add features that require restructuring the persisted data in the long term without having to rewrite UI or even `background.js` code.
All the restructuring and data-type management is kept in one neat little place.
This should make it very easy to add new configuration options like user-configured providers, per-domain vaults, and more!
I know this doesn't seem like a big user-facing feature, but we have a big laundry list of features that I think this will really help streamline.
9 years ago
|
|
|
window.localStorage = {}
|
|
|
|
|
|
|
|
// crypto.getRandomValues
|
|
|
|
if (!window.crypto) window.crypto = {}
|
|
|
|
if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enableFailureOnUnhandledPromiseRejection() {
|
|
|
|
// overwrite node's promise with the stricter Bluebird promise
|
|
|
|
global.Promise = require('bluebird')
|
|
|
|
|
|
|
|
// modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
|
|
|
|
|
|
|
|
// rethrow unhandledRejections
|
|
|
|
if (typeof process !== 'undefined') {
|
|
|
|
process.on('unhandledRejection', function (reason) {
|
|
|
|
throw reason
|
|
|
|
})
|
|
|
|
} else if (typeof window !== 'undefined') {
|
|
|
|
// 2016-02-01: No browsers support this natively, however bluebird, when.js,
|
|
|
|
// and probably other libraries do.
|
|
|
|
if (typeof window.addEventListener === 'function') {
|
|
|
|
window.addEventListener('unhandledrejection', function (evt) {
|
|
|
|
throw evt.detail.reason
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
var oldOHR = window.onunhandledrejection
|
|
|
|
window.onunhandledrejection = function (evt) {
|
|
|
|
if (typeof oldOHR === 'function') oldOHR.apply(this, arguments)
|
|
|
|
throw evt.detail.reason
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (typeof console !== 'undefined' &&
|
|
|
|
typeof (console.error || console.log) === 'function') {
|
|
|
|
(console.error || console.log)('Unhandled rejections will be ignored!')
|
|
|
|
}
|
|
|
|
}
|