|
|
@ -1,6 +1,5 @@ |
|
|
|
const urlUtil = require('url') |
|
|
|
const urlUtil = require('url') |
|
|
|
const endOfStream = require('end-of-stream') |
|
|
|
const endOfStream = require('end-of-stream') |
|
|
|
const asyncQ = require('async-q') |
|
|
|
|
|
|
|
const pipe = require('pump') |
|
|
|
const pipe = require('pump') |
|
|
|
const LocalStorageStore = require('obs-store/lib/localStorage') |
|
|
|
const LocalStorageStore = require('obs-store/lib/localStorage') |
|
|
|
const storeTransform = require('obs-store/lib/transform') |
|
|
|
const storeTransform = require('obs-store/lib/transform') |
|
|
@ -30,34 +29,29 @@ let popupIsOpen = false |
|
|
|
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) |
|
|
|
const diskStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) |
|
|
|
|
|
|
|
|
|
|
|
// initialization flow
|
|
|
|
// initialization flow
|
|
|
|
asyncQ.waterfall([ |
|
|
|
initialize().catch(console.error) |
|
|
|
() => loadStateFromPersistence(), |
|
|
|
|
|
|
|
(initState) => setupController(initState), |
|
|
|
async function initialize() { |
|
|
|
]) |
|
|
|
const initState = await loadStateFromPersistence() |
|
|
|
.then(() => console.log('MetaMask initialization complete.')) |
|
|
|
await setupController(initState) |
|
|
|
.catch((err) => { console.error(err) }) |
|
|
|
console.log('MetaMask initialization complete.') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// State and Persistence
|
|
|
|
// State and Persistence
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
function loadStateFromPersistence () { |
|
|
|
async function loadStateFromPersistence () { |
|
|
|
// migrations
|
|
|
|
// migrations
|
|
|
|
const migrator = new Migrator({ migrations }) |
|
|
|
const migrator = new Migrator({ migrations }) |
|
|
|
const initialState = migrator.generateInitialState(firstTimeState) |
|
|
|
// read from disk
|
|
|
|
return asyncQ.waterfall([ |
|
|
|
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState) |
|
|
|
// read from disk
|
|
|
|
// migrate data
|
|
|
|
() => Promise.resolve(diskStore.getState() || initialState), |
|
|
|
versionedData = await migrator.migrateData(versionedData) |
|
|
|
// migrate data
|
|
|
|
// write to disk
|
|
|
|
(versionedData) => migrator.migrateData(versionedData), |
|
|
|
diskStore.putState(versionedData) |
|
|
|
// write to disk
|
|
|
|
// return just the data
|
|
|
|
(versionedData) => { |
|
|
|
return versionedData.data |
|
|
|
diskStore.putState(versionedData) |
|
|
|
|
|
|
|
return Promise.resolve(versionedData) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// resolve to just data
|
|
|
|
|
|
|
|
(versionedData) => Promise.resolve(versionedData.data), |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setupController (initState) { |
|
|
|
function setupController (initState) { |
|
|
|