mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
break out IndexDbController && Run the first time test on mascara
This commit is contained in:
parent
e7e0919d7c
commit
53537824f1
3
.gitignore
vendored
3
.gitignore
vendored
@ -16,3 +16,6 @@ development/bundle.js
|
|||||||
builds.zip
|
builds.zip
|
||||||
test/integration/bundle.js
|
test/integration/bundle.js
|
||||||
development/states.js
|
development/states.js
|
||||||
|
test/background.js
|
||||||
|
test/bundle.js
|
||||||
|
test/test-bundle.js
|
||||||
|
@ -22,6 +22,7 @@ const STORAGE_KEY = 'metamask-config'
|
|||||||
// const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
|
// const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
|
||||||
const METAMASK_DEBUG = true
|
const METAMASK_DEBUG = true
|
||||||
let popupIsOpen = false
|
let popupIsOpen = false
|
||||||
|
let connectedClientCount = 0
|
||||||
|
|
||||||
const log = require('loglevel')
|
const log = require('loglevel')
|
||||||
global.log = log
|
global.log = log
|
||||||
@ -32,6 +33,11 @@ self.addEventListener('install', function(event) {
|
|||||||
})
|
})
|
||||||
self.addEventListener('activate', function(event) {
|
self.addEventListener('activate', function(event) {
|
||||||
event.waitUntil(self.clients.claim())
|
event.waitUntil(self.clients.claim())
|
||||||
|
self.clients.matchAll()
|
||||||
|
.then((clients) => {
|
||||||
|
if (connectedClientCount < clients.length) sendMessageToAllClients('reconnect')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('inside:open')
|
console.log('inside:open')
|
||||||
@ -108,6 +114,7 @@ function setupController (initState, client) {
|
|||||||
|
|
||||||
connectionListener.on('remote', (portStream, messageEvent) => {
|
connectionListener.on('remote', (portStream, messageEvent) => {
|
||||||
console.log('REMOTE CONECTION FOUND***********')
|
console.log('REMOTE CONECTION FOUND***********')
|
||||||
|
connectedClientCount += 1
|
||||||
connectRemote(portStream, messageEvent.data.context)
|
connectRemote(portStream, messageEvent.data.context)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -143,4 +150,12 @@ function setupController (initState, client) {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendMessageToAllClients (message) {
|
||||||
|
self.clients.matchAll().then(function(clients) {
|
||||||
|
clients.forEach(function(client) {
|
||||||
|
client.postMessage(message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
function noop () {}
|
function noop () {}
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
const EventEmitter = require('events')
|
|
||||||
module.exports = class IndexDbController extends EventEmitter {
|
|
||||||
|
|
||||||
constructor (opts) {
|
|
||||||
super()
|
|
||||||
global.IDBTransaction = global.IDBTransaction || global.webkitIDBTransaction || global.msIDBTransaction || {READ_WRITE: "readwrite"}; // This line should only be needed if it is needed to support the object's constants for older browsers
|
|
||||||
global.IDBKeyRange = global.IDBKeyRange || global.webkitIDBKeyRange || global.msIDBKeyRange
|
|
||||||
this.migrations = opts.migrations
|
|
||||||
this.key = opts.key
|
|
||||||
this.version = opts.version
|
|
||||||
this.initialState = opts.initialState
|
|
||||||
}
|
|
||||||
|
|
||||||
// Opens the database connection and returns a promise
|
|
||||||
open () {
|
|
||||||
return this.get('dataStore')
|
|
||||||
.then((data) => {
|
|
||||||
if (!data) {
|
|
||||||
return this._add('dataStore', this.initialState)
|
|
||||||
.then(() => this.get('dataStore'))
|
|
||||||
.then((versionedData) => Promise.resolve(versionedData))
|
|
||||||
}
|
|
||||||
return Promise.resolve(data)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
get (key = 'dataStore') {
|
|
||||||
return this._request('get', key)
|
|
||||||
}
|
|
||||||
put (state) {
|
|
||||||
return this._request('put', state, 'dataStore')
|
|
||||||
}
|
|
||||||
|
|
||||||
_add (key = 'dataStore', objStore) {
|
|
||||||
return this._request('add', objStore, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
_request (call, ...args) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const self = this
|
|
||||||
const dbOpenRequest = global.indexedDB.open(this.key, this.version)
|
|
||||||
|
|
||||||
dbOpenRequest.addEventListener('upgradeneeded', (event) => {
|
|
||||||
this.db = event.target.result
|
|
||||||
this.db.createObjectStore('dataStore')
|
|
||||||
})
|
|
||||||
|
|
||||||
dbOpenRequest.onsuccess = (event) => {
|
|
||||||
this.db = dbOpenRequest.result
|
|
||||||
this.emit('success')
|
|
||||||
const dbTransaction = this.db.transaction('dataStore', 'readwrite')
|
|
||||||
const request = dbTransaction.objectStore('dataStore')
|
|
||||||
const objRequest = request[call](...args)
|
|
||||||
objRequest.addEventListener('success', (event) => {
|
|
||||||
return resolve(objRequest.result)
|
|
||||||
})
|
|
||||||
objRequest.addEventListener('error', (err) => {
|
|
||||||
return reject(`IndexDBController - ${call} failed to excute on indexedDB`)
|
|
||||||
})
|
|
||||||
dbTransaction.addEventListener('complete', (event) => {
|
|
||||||
this.emit('complete')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
dbOpenRequest.addEventListener('error', (event) => {
|
|
||||||
return reject({message: `IndexDBController - open:@${call} failed to excute on indexedDB`, errorEvent: event})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ const background = new SWcontroller({
|
|||||||
wakeUpInterval: 20000
|
wakeUpInterval: 20000
|
||||||
})
|
})
|
||||||
// Setup listener for when the service worker is read
|
// Setup listener for when the service worker is read
|
||||||
background.on('ready', (readSw) => {
|
const connectApp = function (readSw) {
|
||||||
let connectionStream = SwStream({
|
let connectionStream = SwStream({
|
||||||
serviceWorker: background.controller,
|
serviceWorker: background.controller,
|
||||||
context: name,
|
context: name,
|
||||||
@ -37,8 +37,24 @@ background.on('ready', (readSw) => {
|
|||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
const state = store.getState()
|
const state = store.getState()
|
||||||
if (state.appState.shouldClose) window.close()
|
if (state.appState.shouldClose) window.close()
|
||||||
|
console.log('IN the things?')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
background.on('ready', (sw) => {
|
||||||
|
background.removeListener('updatefound', connectApp)
|
||||||
|
connectApp(sw)
|
||||||
})
|
})
|
||||||
background.startWorker()
|
background.on('updatefound', () => background.serviceWorkerApi.ready
|
||||||
|
.then((sw) =>{
|
||||||
|
background.removeListener('ready', connectApp)
|
||||||
|
connectApp(sw.active)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
background.on('message', (messageEvent) => {
|
||||||
|
console.log(messageEvent)
|
||||||
|
})
|
||||||
|
window.addEventListener('load', () => background.startWorker())
|
||||||
|
// background.startWorker()
|
||||||
console.log('hello from MetaMascara ui!')
|
console.log('hello from MetaMascara ui!')
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
<script src="./helpers.js"></script>
|
<script src="./helpers.js"></script>
|
||||||
<script src="./test-bundle.js"></script>
|
<script src="./test-bundle.js"></script>
|
||||||
<script src="/testem.js"></script>
|
<script src="/testem.js"></script>
|
||||||
<script src="./bundle.js"></script>
|
|
||||||
<div id="app-content"></div>
|
<div id="app-content"></div>
|
||||||
|
<script src="./bundle.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,8 +6,8 @@ QUnit.test('render init screen', function (assert) {
|
|||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
let app
|
let app
|
||||||
|
|
||||||
wait().then(function() {
|
wait(1000).then(function() {
|
||||||
app = $('#app-content')
|
app = $('#app-content').contents()
|
||||||
const recurseNotices = function () {
|
const recurseNotices = function () {
|
||||||
let button = app.find('button')
|
let button = app.find('button')
|
||||||
if (button.html() === 'Continue') {
|
if (button.html() === 'Continue') {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const EventEmitter = require('events')
|
const EventEmitter = require('events')
|
||||||
const IDB = require('../../../mascara/src/lib/index-db-controller')
|
const IDB = require('idb-global')
|
||||||
const KEY = 'metamask-test-config'
|
const KEY = 'metamask-test-config'
|
||||||
module.exports = class Helper extends EventEmitter {
|
module.exports = class Helper extends EventEmitter {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const Helper = require('./util/mascara-test-helper.js')
|
const Helper = require('./util/mascara-test-helper.js')
|
||||||
debugger
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const helper = new Helper()
|
// const helper = new Helper()
|
||||||
helper.on('complete', () => require('../src/ui.js'))
|
// helper.on('complete', () => require('../src/ui.js'))
|
||||||
helper.tryToCleanContext()
|
// helper.tryToCleanContext()
|
||||||
|
require('../src/ui.js')
|
||||||
})
|
})
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
"extensionizer": "^1.0.0",
|
"extensionizer": "^1.0.0",
|
||||||
"gulp-eslint": "^2.0.0",
|
"gulp-eslint": "^2.0.0",
|
||||||
"hat": "0.0.3",
|
"hat": "0.0.3",
|
||||||
|
"idb-global": "^1.0.0",
|
||||||
"identicon.js": "^1.2.1",
|
"identicon.js": "^1.2.1",
|
||||||
"iframe": "^1.0.0",
|
"iframe": "^1.0.0",
|
||||||
"iframe-stream": "^1.0.2",
|
"iframe-stream": "^1.0.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user