aboutsummaryrefslogtreecommitdiffstats
path: root/mascara
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-03-31 07:18:48 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-03-31 07:18:48 +0800
commitba23843f91ca5046400cea14cea4c0d256578fec (patch)
treee29ef2a930930d4256bd7f59aa3d0274563bc4cf /mascara
parentbdc4a6964ae83faa8229c50870e3bcc9b9074989 (diff)
parent8e0f39353dd47c4a201aaf2ee160912846f2e68b (diff)
downloadtangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar.gz
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar.bz2
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar.lz
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar.xz
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.tar.zst
tangerine-wallet-browser-ba23843f91ca5046400cea14cea4c0d256578fec.zip
Fix merge conflicts
Diffstat (limited to 'mascara')
-rw-r--r--mascara/proxy/index.html2
-rw-r--r--mascara/server/index.js23
-rw-r--r--mascara/src/background.js16
-rw-r--r--mascara/src/metamascara.js (renamed from mascara/src/mascara.js)0
-rw-r--r--mascara/src/proxy.js14
-rw-r--r--mascara/src/ui.js54
-rw-r--r--mascara/ui/index.html4
7 files changed, 53 insertions, 60 deletions
diff --git a/mascara/proxy/index.html b/mascara/proxy/index.html
index b83fc41af..4e167db72 100644
--- a/mascara/proxy/index.html
+++ b/mascara/proxy/index.html
@@ -17,4 +17,4 @@
Hello! I am the MetaMask iframe.
<script src="./proxy.js"></script>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/mascara/server/index.js b/mascara/server/index.js
index 6fb1287cc..a30120438 100644
--- a/mascara/server/index.js
+++ b/mascara/server/index.js
@@ -1,7 +1,5 @@
const path = require('path')
const express = require('express')
-const createBundle = require('./util').createBundle
-const serveBundle = require('./util').serveBundle
const compression = require('compression')
module.exports = createMetamascaraServer
@@ -9,27 +7,14 @@ module.exports = createMetamascaraServer
function createMetamascaraServer () {
- // start bundlers
- const metamascaraBundle = createBundle(path.join(__dirname, '/../src/mascara.js'))
- const proxyBundle = createBundle(path.join(__dirname, '/../src/proxy.js'))
- const uiBundle = createBundle(path.join(__dirname, '/../src/ui.js'))
- const backgroundBuild = createBundle(path.join(__dirname, '/../src/background.js'))
-
- // serve bundles
+ // setup server
const server = express()
server.use(compression())
- // ui window
- serveBundle(server, '/ui.js', uiBundle)
+ // serve assets
server.use(express.static(path.join(__dirname, '/../ui/'), { setHeaders: (res) => res.set('X-Frame-Options', 'DENY') }))
- server.use(express.static(path.join(__dirname, '/../../dist/chrome')))
- // metamascara
- serveBundle(server, '/metamascara.js', metamascaraBundle)
- // proxy
- serveBundle(server, '/proxy/proxy.js', proxyBundle)
- server.use('/proxy/', express.static(path.join(__dirname, '/../proxy')))
- // background
- serveBundle(server, '/background.js', backgroundBuild)
+ server.use(express.static(path.join(__dirname, '/../../dist/mascara')))
+ server.use(express.static(path.join(__dirname, '/../proxy')))
return server
diff --git a/mascara/src/background.js b/mascara/src/background.js
index 8aa1d8fe2..40a684f3d 100644
--- a/mascara/src/background.js
+++ b/mascara/src/background.js
@@ -30,15 +30,19 @@ global.addEventListener('activate', function (event) {
log.debug('inside:open')
-
-// // state persistence
+// state persistence
const dbController = new DbController({
key: STORAGE_KEY,
})
-loadStateFromPersistence()
-.then((initState) => setupController(initState))
-.then(() => log.debug('MetaMask initialization complete.'))
-.catch((err) => console.error('WHILE SETTING UP:', err))
+
+start().catch(log.error)
+
+async function start() {
+ log.debug('MetaMask initializing...')
+ const initState = await loadStateFromPersistence()
+ await setupController(initState)
+ log.debug('MetaMask initialization complete.')
+}
//
// State and Persistence
diff --git a/mascara/src/mascara.js b/mascara/src/metamascara.js
index 0af6f532f..0af6f532f 100644
--- a/mascara/src/mascara.js
+++ b/mascara/src/metamascara.js
diff --git a/mascara/src/proxy.js b/mascara/src/proxy.js
index 54c5d5cf4..80b4dc516 100644
--- a/mascara/src/proxy.js
+++ b/mascara/src/proxy.js
@@ -1,13 +1,13 @@
const createParentStream = require('iframe-stream').ParentStream
-const SWcontroller = require('client-sw-ready-event/lib/sw-client.js')
+const SwController = require('sw-controller')
const SwStream = require('sw-stream/lib/sw-stream.js')
-const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
-const background = new SWcontroller({
- fileName: '/background.js',
- letBeIdle: false,
- wakeUpInterval: 30000,
- intervalDelay,
+const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
+const background = new SwController({
+ fileName: './scripts/background.js',
+ keepAlive: true,
+ keepAliveInterval: 30000,
+ keepAliveDelay,
})
const pageStream = createParentStream()
diff --git a/mascara/src/ui.js b/mascara/src/ui.js
index b272a2e06..f35a11fc4 100644
--- a/mascara/src/ui.js
+++ b/mascara/src/ui.js
@@ -1,6 +1,6 @@
const injectCss = require('inject-css')
-const SWcontroller = require('client-sw-ready-event/lib/sw-client.js')
-const SwStream = require('sw-stream/lib/sw-stream.js')
+const SwController = require('sw-controller')
+const SwStream = require('sw-stream')
const MetaMaskUiCss = require('../../ui/css')
const MetamascaraPlatform = require('../../app/scripts/platforms/window')
const startPopup = require('../../app/scripts/popup-core')
@@ -8,27 +8,44 @@ const startPopup = require('../../app/scripts/popup-core')
// create platform global
global.platform = new MetamascaraPlatform()
-
var css = MetaMaskUiCss()
injectCss(css)
const container = document.getElementById('app-content')
-var name = 'popup'
+const name = 'popup'
window.METAMASK_UI_TYPE = name
window.METAMASK_PLATFORM_TYPE = 'mascara'
-const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
+const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
-const background = new SWcontroller({
- fileName: '/background.js',
- letBeIdle: false,
- intervalDelay,
- wakeUpInterval: 20000,
+const swController = new SwController({
+ fileName: './background.js',
+ keepAlive: true,
+ keepAliveDelay,
+ keepAliveInterval: 20000,
})
+
+swController.once('updatefound', windowReload)
+swController.once('ready', async () => {
+ try {
+ swController.removeListener('updatefound', windowReload)
+ console.log('swController ready')
+ await timeout(1000)
+ console.log('connecting to app')
+ await connectApp()
+ console.log('app connected')
+ } catch (err) {
+ console.error(err)
+ }
+})
+
+console.log('starting service worker')
+swController.startWorker()
+
// Setup listener for when the service worker is read
-const connectApp = function (readSw) {
+function connectApp() {
const connectionStream = SwStream({
- serviceWorker: background.controller,
+ serviceWorker: swController.getWorker(),
context: name,
})
return new Promise((resolve, reject) => {
@@ -43,19 +60,6 @@ const connectApp = function (readSw) {
})
})
}
-background.on('ready', async (sw) => {
- try {
- background.removeListener('updatefound', connectApp)
- await timeout(1000)
- await connectApp(sw)
- console.log('hello from cb ready event!')
- } catch (e) {
- console.error(e)
- }
-})
-background.on('updatefound', windowReload)
-
-background.startWorker()
function windowReload () {
if (window.METAMASK_SKIP_RELOAD) return
diff --git a/mascara/ui/index.html b/mascara/ui/index.html
index eac8e4898..dbc445891 100644
--- a/mascara/ui/index.html
+++ b/mascara/ui/index.html
@@ -7,6 +7,6 @@
</head>
<body>
<div id="app-content"></div>
- <script src="./ui.js" type="text/javascript" charset="utf-8"></script>
+ <script src="./scripts/ui.js" type="text/javascript" charset="utf-8"></script>
</body>
-</html> \ No newline at end of file
+</html>