From 5815de33fbef617625d8350ec8e88aa4dbff6156 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 14:04:33 -0700 Subject: build - rename 'popup.js' to 'ui.js' --- app/home.html | 2 +- app/notification.html | 2 +- app/popup.html | 2 +- app/scripts/popup.js | 84 --------------------------------------------------- app/scripts/ui.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 app/scripts/popup.js create mode 100644 app/scripts/ui.js (limited to 'app') diff --git a/app/home.html b/app/home.html index 730215d1a..bb8e936a3 100644 --- a/app/home.html +++ b/app/home.html @@ -7,6 +7,6 @@
- + diff --git a/app/notification.html b/app/notification.html index f10cbbf41..2255ca2c1 100644 --- a/app/notification.html +++ b/app/notification.html @@ -11,6 +11,6 @@
- + diff --git a/app/popup.html b/app/popup.html index 148d266d3..109487d3e 100644 --- a/app/popup.html +++ b/app/popup.html @@ -7,6 +7,6 @@
- + diff --git a/app/scripts/popup.js b/app/scripts/popup.js deleted file mode 100644 index 13c7ac5ec..000000000 --- a/app/scripts/popup.js +++ /dev/null @@ -1,84 +0,0 @@ -const injectCss = require('inject-css') -const OldMetaMaskUiCss = require('../../old-ui/css') -const NewMetaMaskUiCss = require('../../ui/css') -const startPopup = require('./popup-core') -const PortStream = require('./lib/port-stream.js') -const isPopupOrNotification = require('./lib/is-popup-or-notification') -const extension = require('extensionizer') -const ExtensionPlatform = require('./platforms/extension') -const NotificationManager = require('./lib/notification-manager') -const notificationManager = new NotificationManager() -const setupRaven = require('./lib/setupRaven') - -start().catch(log.error) - -async function start() { - - // create platform global - global.platform = new ExtensionPlatform() - - // setup sentry error reporting - const release = global.platform.getVersion() - setupRaven({ release }) - - // inject css - // const css = MetaMaskUiCss() - // injectCss(css) - - // identify window type (popup, notification) - const windowType = isPopupOrNotification() - global.METAMASK_UI_TYPE = windowType - closePopupIfOpen(windowType) - - // setup stream to background - const extensionPort = extension.runtime.connect({ name: windowType }) - const connectionStream = new PortStream(extensionPort) - - // start ui - const container = document.getElementById('app-content') - startPopup({ container, connectionStream }, (err, store) => { - if (err) return displayCriticalError(err) - - // Code commented out until we begin auto adding users to NewUI - // const { isMascara, identities = {}, featureFlags = {} } = store.getState().metamask - // const firstTime = Object.keys(identities).length === 0 - const { isMascara, featureFlags = {} } = store.getState().metamask - let betaUIState = featureFlags.betaUI - - // Code commented out until we begin auto adding users to NewUI - // const useBetaCss = isMascara || firstTime || betaUIState - const useBetaCss = isMascara || betaUIState - - let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss() - let deleteInjectedCss = injectCss(css) - let newBetaUIState - - store.subscribe(() => { - const state = store.getState() - newBetaUIState = state.metamask.featureFlags.betaUI - if (newBetaUIState !== betaUIState) { - deleteInjectedCss() - betaUIState = newBetaUIState - css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss() - deleteInjectedCss = injectCss(css) - } - if (state.appState.shouldClose) notificationManager.closePopup() - }) - }) - - - function closePopupIfOpen (windowType) { - if (windowType !== 'notification') { - // should close only chrome popup - notificationManager.closePopup() - } - } - - function displayCriticalError (err) { - container.innerHTML = '
The MetaMask app failed to load: please open and close MetaMask again to restart.
' - container.style.height = '80px' - log.error(err.stack) - throw err - } - -} diff --git a/app/scripts/ui.js b/app/scripts/ui.js new file mode 100644 index 000000000..13c7ac5ec --- /dev/null +++ b/app/scripts/ui.js @@ -0,0 +1,84 @@ +const injectCss = require('inject-css') +const OldMetaMaskUiCss = require('../../old-ui/css') +const NewMetaMaskUiCss = require('../../ui/css') +const startPopup = require('./popup-core') +const PortStream = require('./lib/port-stream.js') +const isPopupOrNotification = require('./lib/is-popup-or-notification') +const extension = require('extensionizer') +const ExtensionPlatform = require('./platforms/extension') +const NotificationManager = require('./lib/notification-manager') +const notificationManager = new NotificationManager() +const setupRaven = require('./lib/setupRaven') + +start().catch(log.error) + +async function start() { + + // create platform global + global.platform = new ExtensionPlatform() + + // setup sentry error reporting + const release = global.platform.getVersion() + setupRaven({ release }) + + // inject css + // const css = MetaMaskUiCss() + // injectCss(css) + + // identify window type (popup, notification) + const windowType = isPopupOrNotification() + global.METAMASK_UI_TYPE = windowType + closePopupIfOpen(windowType) + + // setup stream to background + const extensionPort = extension.runtime.connect({ name: windowType }) + const connectionStream = new PortStream(extensionPort) + + // start ui + const container = document.getElementById('app-content') + startPopup({ container, connectionStream }, (err, store) => { + if (err) return displayCriticalError(err) + + // Code commented out until we begin auto adding users to NewUI + // const { isMascara, identities = {}, featureFlags = {} } = store.getState().metamask + // const firstTime = Object.keys(identities).length === 0 + const { isMascara, featureFlags = {} } = store.getState().metamask + let betaUIState = featureFlags.betaUI + + // Code commented out until we begin auto adding users to NewUI + // const useBetaCss = isMascara || firstTime || betaUIState + const useBetaCss = isMascara || betaUIState + + let css = useBetaCss ? NewMetaMaskUiCss() : OldMetaMaskUiCss() + let deleteInjectedCss = injectCss(css) + let newBetaUIState + + store.subscribe(() => { + const state = store.getState() + newBetaUIState = state.metamask.featureFlags.betaUI + if (newBetaUIState !== betaUIState) { + deleteInjectedCss() + betaUIState = newBetaUIState + css = betaUIState ? NewMetaMaskUiCss() : OldMetaMaskUiCss() + deleteInjectedCss = injectCss(css) + } + if (state.appState.shouldClose) notificationManager.closePopup() + }) + }) + + + function closePopupIfOpen (windowType) { + if (windowType !== 'notification') { + // should close only chrome popup + notificationManager.closePopup() + } + } + + function displayCriticalError (err) { + container.innerHTML = '
The MetaMask app failed to load: please open and close MetaMask again to restart.
' + container.style.height = '80px' + log.error(err.stack) + throw err + } + +} -- cgit