aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/src
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-03-29 12:33:04 +0800
committerkumavis <aaron@kumavis.me>2018-03-29 12:33:04 +0800
commitc9a47923042ca01c1968cf72e6d43d19890f4cd5 (patch)
tree2782cefaed7cf1daf7c2f495cb18d5e26c7b4d46 /mascara/src
parent253abd60fca5a6efb1a2e0ecbe305989a852ec32 (diff)
downloadtangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar.gz
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar.bz2
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar.lz
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar.xz
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.tar.zst
tangerine-wallet-browser-c9a47923042ca01c1968cf72e6d43d19890f4cd5.zip
mascara - use sw-controller and other cleanups
Diffstat (limited to 'mascara/src')
-rw-r--r--mascara/src/background.js16
-rw-r--r--mascara/src/proxy.js12
-rw-r--r--mascara/src/ui.js54
3 files changed, 45 insertions, 37 deletions
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/proxy.js b/mascara/src/proxy.js
index 3958f7d50..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({
+const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
+const background = new SwController({
fileName: './scripts/background.js',
- letBeIdle: false,
- wakeUpInterval: 30000,
- intervalDelay,
+ keepAlive: true,
+ keepAliveInterval: 30000,
+ keepAliveDelay,
})
const pageStream = createParentStream()
diff --git a/mascara/src/ui.js b/mascara/src/ui.js
index 21e5f32a9..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: './scripts/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