From bdf99269e275590b31347322961e773ad980b812 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 14:06:59 -0700 Subject: mascara - move file locations to match extension structure --- mascara/server/index.js | 8 ++++---- mascara/src/proxy.js | 2 +- mascara/src/ui.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'mascara') diff --git a/mascara/server/index.js b/mascara/server/index.js index 6fb1287cc..0f9b047a7 100644 --- a/mascara/server/index.js +++ b/mascara/server/index.js @@ -20,16 +20,16 @@ function createMetamascaraServer () { server.use(compression()) // ui window - serveBundle(server, '/ui.js', uiBundle) + serveBundle(server, '/scripts/ui.js', uiBundle) 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'))) + serveBundle(server, '/scripts/proxy.js', proxyBundle) + server.use('/', express.static(path.join(__dirname, '/../proxy'))) // background - serveBundle(server, '/background.js', backgroundBuild) + serveBundle(server, '/scripts/background.js', backgroundBuild) return server diff --git a/mascara/src/proxy.js b/mascara/src/proxy.js index 54c5d5cf4..3958f7d50 100644 --- a/mascara/src/proxy.js +++ b/mascara/src/proxy.js @@ -4,7 +4,7 @@ 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', + fileName: './scripts/background.js', letBeIdle: false, wakeUpInterval: 30000, intervalDelay, diff --git a/mascara/src/ui.js b/mascara/src/ui.js index b272a2e06..21e5f32a9 100644 --- a/mascara/src/ui.js +++ b/mascara/src/ui.js @@ -20,7 +20,7 @@ window.METAMASK_PLATFORM_TYPE = 'mascara' const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000 const background = new SWcontroller({ - fileName: '/background.js', + fileName: './scripts/background.js', letBeIdle: false, intervalDelay, wakeUpInterval: 20000, -- cgit v1.2.3 From f35356a89a0f2b0eb670394667e9650ab92f03ed Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 18:07:02 -0700 Subject: mascara - html - fix script locations --- mascara/proxy/index.html | 4 ++-- mascara/ui/index.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'mascara') diff --git a/mascara/proxy/index.html b/mascara/proxy/index.html index b83fc41af..0dff83f18 100644 --- a/mascara/proxy/index.html +++ b/mascara/proxy/index.html @@ -15,6 +15,6 @@ Hello! I am the MetaMask iframe. - + - \ No newline at end of file + 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 @@
- + - \ No newline at end of file + -- cgit v1.2.3 From cbfee0ac7e9ac705ba1a8b5bffa2c5ed4511b70d Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 18:07:38 -0700 Subject: mascara - server - server bundles before static assets + serve dist/mascara instead of chrome --- mascara/server/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'mascara') diff --git a/mascara/server/index.js b/mascara/server/index.js index 0f9b047a7..2ad8af242 100644 --- a/mascara/server/index.js +++ b/mascara/server/index.js @@ -15,22 +15,21 @@ function createMetamascaraServer () { 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, '/scripts/ui.js', uiBundle) - 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 + // serve bundles serveBundle(server, '/metamascara.js', metamascaraBundle) - // proxy + serveBundle(server, '/scripts/ui.js', uiBundle) serveBundle(server, '/scripts/proxy.js', proxyBundle) - server.use('/', express.static(path.join(__dirname, '/../proxy'))) - // background serveBundle(server, '/scripts/background.js', backgroundBuild) + // 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/mascara'))) + server.use(express.static(path.join(__dirname, '/../proxy'))) + return server } -- cgit v1.2.3 From c9a47923042ca01c1968cf72e6d43d19890f4cd5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 21:33:04 -0700 Subject: mascara - use sw-controller and other cleanups --- mascara/server/index.js | 3 ++- mascara/src/background.js | 16 ++++++++------ mascara/src/proxy.js | 12 +++++------ mascara/src/ui.js | 54 +++++++++++++++++++++++++---------------------- 4 files changed, 47 insertions(+), 38 deletions(-) (limited to 'mascara') diff --git a/mascara/server/index.js b/mascara/server/index.js index 2ad8af242..2bc2441d0 100644 --- a/mascara/server/index.js +++ b/mascara/server/index.js @@ -23,7 +23,8 @@ function createMetamascaraServer () { serveBundle(server, '/metamascara.js', metamascaraBundle) serveBundle(server, '/scripts/ui.js', uiBundle) serveBundle(server, '/scripts/proxy.js', proxyBundle) - serveBundle(server, '/scripts/background.js', backgroundBuild) + // the serviceworker must be served from the root of the app + serveBundle(server, '/background.js', backgroundBuild) // serve assets server.use(express.static(path.join(__dirname, '/../ui/'), { setHeaders: (res) => res.set('X-Frame-Options', 'DENY') })) 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 -- cgit v1.2.3 From fbdf497487e7d5b653d6eb36e92d917e935a6935 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 21:40:20 -0700 Subject: mascara - fix proxy html script link --- mascara/proxy/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mascara') diff --git a/mascara/proxy/index.html b/mascara/proxy/index.html index 0dff83f18..4e167db72 100644 --- a/mascara/proxy/index.html +++ b/mascara/proxy/index.html @@ -15,6 +15,6 @@ Hello! I am the MetaMask iframe. - + -- cgit v1.2.3 From 99e618d3f2fed0504e9dcc4647b8492440617162 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 23:06:01 -0700 Subject: mascara - server - serve bundles from dist --- mascara/server/index.js | 13 ------------- mascara/src/mascara.js | 1 - mascara/src/metamascara.js | 1 + 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 mascara/src/mascara.js create mode 100644 mascara/src/metamascara.js (limited to 'mascara') diff --git a/mascara/server/index.js b/mascara/server/index.js index 2bc2441d0..2f3a7a5ff 100644 --- a/mascara/server/index.js +++ b/mascara/server/index.js @@ -9,23 +9,10 @@ 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')) - // setup server const server = express() server.use(compression()) - // serve bundles - serveBundle(server, '/metamascara.js', metamascaraBundle) - serveBundle(server, '/scripts/ui.js', uiBundle) - serveBundle(server, '/scripts/proxy.js', proxyBundle) - // the serviceworker must be served from the root of the app - serveBundle(server, '/background.js', backgroundBuild) - // 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/mascara'))) diff --git a/mascara/src/mascara.js b/mascara/src/mascara.js deleted file mode 100644 index 0af6f532f..000000000 --- a/mascara/src/mascara.js +++ /dev/null @@ -1 +0,0 @@ -global.metamask = require('metamascara') diff --git a/mascara/src/metamascara.js b/mascara/src/metamascara.js new file mode 100644 index 000000000..0af6f532f --- /dev/null +++ b/mascara/src/metamascara.js @@ -0,0 +1 @@ +global.metamask = require('metamascara') -- cgit v1.2.3 From 89e6baa3ba07cc46dcc62886fbe3f1906649ae77 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 23:09:31 -0700 Subject: clean - mascara - remove unused code --- mascara/server/index.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'mascara') diff --git a/mascara/server/index.js b/mascara/server/index.js index 2f3a7a5ff..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 -- cgit v1.2.3