mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
WIP: streams->indexdb
This commit is contained in:
parent
d4e8ff188b
commit
45ab81fb45
@ -204,7 +204,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
//
|
||||
|
||||
getState () {
|
||||
|
||||
const wallet = this.configManager.getWallet()
|
||||
const vault = this.keyringController.store.getState().vault
|
||||
const isInitialized = (!!wallet || !!vault)
|
||||
|
@ -11,6 +11,7 @@ module.exports = initializePopup
|
||||
|
||||
function initializePopup (connectionStream) {
|
||||
// setup app
|
||||
debugger
|
||||
connectToAccountManager(connectionStream, setupApp)
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,13 @@
|
||||
const SWcontroller = require('./sw-controller')
|
||||
console.log('outside:open')
|
||||
const background = new SWcontroller({
|
||||
fileName: 'sw-build.js',
|
||||
registerOpts: {
|
||||
scope: './',
|
||||
}
|
||||
})
|
||||
// const SWcontroller = require('./sw-controller')
|
||||
// const SwStream = require('sw-stream/lib/sw-stream.js')
|
||||
// const startPopup = require('../app/scripts/popup-core')
|
||||
|
||||
background.startWorker()
|
||||
.then(registerdWorker => {
|
||||
return background.sendMessage('connect')
|
||||
})
|
||||
.then((port) => {
|
||||
debugger
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(`SW Controller: ${err}`)
|
||||
})
|
||||
// console.log('outside:open')
|
||||
// const background = new SWcontroller({
|
||||
// fileName: 'sw-build.js',
|
||||
// })
|
||||
// background.on('ready', (readSw) => {
|
||||
// startPopup(SwStream(background.controller))
|
||||
// })
|
||||
// background.startWorker()
|
||||
console.log('hello from controller')
|
||||
|
@ -5,6 +5,7 @@ module.exports = setupIframe
|
||||
|
||||
|
||||
function setupIframe(opts) {
|
||||
debugger
|
||||
opts = opts || {}
|
||||
var frame = Iframe({
|
||||
src: opts.zeroClientProvider || 'https://zero.metamask.io/',
|
||||
|
@ -1,7 +1,10 @@
|
||||
const injectCss = require('inject-css')
|
||||
const MetaMaskUiCss = require('../ui/css')
|
||||
const startPopup = require('../app/scripts/popup-core')
|
||||
const setupIframe = require('./lib/setup-iframe.js')
|
||||
const MetamaskInpageProvider = require('../app/scripts/lib/inpage-provider.js')
|
||||
const SWcontroller = require('./sw-controller')
|
||||
const SwStream = require('sw-stream/lib/sw-stream.js')
|
||||
const startPopup = require('../app/scripts/popup-core')
|
||||
|
||||
|
||||
var css = MetaMaskUiCss()
|
||||
@ -15,5 +18,14 @@ var iframeStream = setupIframe({
|
||||
sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'],
|
||||
container: document.body,
|
||||
})
|
||||
|
||||
startPopup(iframeStream)
|
||||
console.log('outside:open')
|
||||
const background = new SWcontroller({
|
||||
fileName: '/popup/sw-build.js',
|
||||
})
|
||||
background.on('ready', (readSw) => {
|
||||
// var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller))
|
||||
// startPopup(inpageProvider)
|
||||
startPopup(SwStream(background.controller))
|
||||
})
|
||||
background.startWorker()
|
||||
console.log('hello from /library/popup.js')
|
||||
|
@ -25,7 +25,7 @@ iframeServer.use('/popup', express.static('../dist/chrome'))
|
||||
iframeServer.get('/controller.js', function(req, res){
|
||||
res.send(controllerBundle.latest)
|
||||
})
|
||||
iframeServer.get('/sw-build.js', function(req, res){
|
||||
iframeServer.get('/popup/sw-build.js', function(req, res){
|
||||
console.log('/sw-build.js')
|
||||
res.setHeader('Content-Type', 'application/javascript')
|
||||
res.send(swBuild.latest)
|
||||
|
@ -1,34 +1,63 @@
|
||||
const EventEmitter = require('events')
|
||||
|
||||
module.exports = class serviceWorkerController extends EventEmitter{
|
||||
module.exports = class ClientSideServiceWorker extends EventEmitter{
|
||||
constructor (opts) {
|
||||
super()
|
||||
this.fileName = opts.fileName
|
||||
this.registerOpts = opts.registerOpts
|
||||
this.serviceWorker = navigator.serviceWorker
|
||||
this.startDelay = opts.startDelay
|
||||
|
||||
this.serviceWorkerApi = navigator.serviceWorker
|
||||
this.serviceWorkerApi.onmessage = (event) => this.emit('message', event)
|
||||
this.serviceWorkerApi.onerror = (event) => this.emit('error')
|
||||
|
||||
// temporary function
|
||||
this.askForId = (message) => {
|
||||
this.sendMessage('check-in')
|
||||
.then((data) => console.log(`${message}----${data}`))
|
||||
}
|
||||
|
||||
// if (!!this.serviceWorkerApi) this.askForId('before')
|
||||
|
||||
if (opts.initStart) this.startWorker()
|
||||
|
||||
this.on('ready', (sw) => {
|
||||
this.askForId('ready')
|
||||
})
|
||||
}
|
||||
|
||||
get controller () {
|
||||
return this.sw || this.serviceWorkerApi.controller
|
||||
}
|
||||
|
||||
|
||||
startWorker () {
|
||||
// check to see if their is a preregistered service worker
|
||||
if (!this.serviceWorker.controller) {
|
||||
return Promise.resolve(this.registerWorker())
|
||||
} else {
|
||||
return Promise.resolve(this.serviceWorker.ready)
|
||||
}
|
||||
return this.registerWorker()
|
||||
.then((sw) => {
|
||||
this.sw = sw
|
||||
this.askForId('after register:')
|
||||
this.sw.onerror = (err) => this.emit('error', err)
|
||||
this.sw = sw
|
||||
this.emit('ready', this.sw)
|
||||
})
|
||||
.catch((err) => this.emit('error', err))
|
||||
}
|
||||
|
||||
registerWorker () {
|
||||
return this.serviceWorker.register(this.fileName, this.registerOpts)
|
||||
.then(sw => {
|
||||
return sw
|
||||
})
|
||||
}
|
||||
return this.serviceWorkerApi.register(this.fileName)
|
||||
.then((registerdWorker) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.askForId('after')
|
||||
let timeOutId = setTimeout(() => {
|
||||
if (this.serviceWorkerApi.controller) return resolve(this.serviceWorkerApi.controller)
|
||||
if (registerdWorker.active) return resolve(registerdWorker.active)
|
||||
return reject(new Error('ClientSideServiceWorker: No controller found and onupdatefound timed out'))
|
||||
}, this.startDelay || 1000 )
|
||||
|
||||
syncSW (registeredSW) {
|
||||
return registeredSW.sync.register('sync')
|
||||
.then(() => {
|
||||
console.log('sync')
|
||||
registerdWorker.onupdatefound = (event) => {
|
||||
this.emit('updatefound')
|
||||
registerdWorker.update()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -43,7 +72,7 @@ module.exports = class serviceWorkerController extends EventEmitter{
|
||||
resolve(event.data.data)
|
||||
}
|
||||
}
|
||||
self.serviceWorker.controller.postMessage(message, [messageChannel.port2])
|
||||
this.controller.postMessage(message, [messageChannel.port2])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ const STORAGE_KEY = 'metamask-config'
|
||||
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
|
||||
let popupIsOpen = false
|
||||
|
||||
const log = require('loglevel')
|
||||
global.log = log
|
||||
log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn')
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
event.waitUntil(self.skipWaiting())
|
||||
})
|
||||
@ -132,12 +136,16 @@ function setupController (initState, client) {
|
||||
global.metamaskController = controller
|
||||
|
||||
// setup state persistence
|
||||
pipe(
|
||||
controller.store,
|
||||
storeTransform(versionifyData),
|
||||
diskStore
|
||||
)
|
||||
|
||||
// pipe(
|
||||
// controller.store,
|
||||
// storeTransform(versionifyData),
|
||||
// diskStore
|
||||
// )
|
||||
controller.store.subscribe((store) => {
|
||||
dbController.put('dataStore', store)
|
||||
// .then((event) => {debugger})
|
||||
// .catch((err) => {debugger})
|
||||
})
|
||||
function versionifyData(state) {
|
||||
let versionedData = diskStore.getState()
|
||||
versionedData.data = state
|
||||
@ -150,10 +158,8 @@ function setupController (initState, client) {
|
||||
/*
|
||||
need to write a service worker stream for this
|
||||
*/
|
||||
// var connectionStream = new ParentStream()
|
||||
connectionListener.on('remote', (portStream, messageEvent) => {
|
||||
debugger
|
||||
connectRemote(connectionStream, messageEvent.origin)
|
||||
connectRemote(portStream, messageEvent.origin)
|
||||
})
|
||||
|
||||
function connectRemote (connectionStream, originDomain) {
|
||||
|
@ -104,14 +104,14 @@
|
||||
"request-promise": "^4.1.1",
|
||||
"sandwich-expando": "^1.0.5",
|
||||
"semaphore": "^1.0.5",
|
||||
"sw-stream": "^1.0.1",
|
||||
"sw-stream": "^1.0.2",
|
||||
"textarea-caret": "^3.0.1",
|
||||
"three.js": "^0.73.2",
|
||||
"through2": "^2.0.1",
|
||||
"valid-url": "^1.0.9",
|
||||
"vreme": "^3.0.2",
|
||||
"web3": "0.18.2",
|
||||
"web3-provider-engine": "^10.0.1",
|
||||
"web3-provider-engine": "^11.0.0",
|
||||
"web3-stream-provider": "^2.0.6",
|
||||
"xtend": "^4.0.1"
|
||||
},
|
||||
|
@ -14,7 +14,7 @@ log.setLevel(debugMode ? 'debug' : 'warn')
|
||||
function launchApp (opts) {
|
||||
var accountManager = opts.accountManager
|
||||
actions._setBackgroundConnection(accountManager)
|
||||
|
||||
debugger
|
||||
// check if we are unlocked first
|
||||
accountManager.getState(function (err, metamaskState) {
|
||||
if (err) throw err
|
||||
|
Loading…
Reference in New Issue
Block a user