1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 01:13:22 +01:00

Unify notification and popup ui files

This commit is contained in:
Dan Finlay 2016-08-16 16:46:44 -07:00
parent 4ba90969ee
commit 030bdec27a
7 changed files with 29 additions and 58 deletions

View File

@ -3,9 +3,14 @@
<head>
<meta charset="utf-8">
<title>MetaMask Notification</title>
<style>
body {
overflow: hidden;
}
</style>
</head>
<body>
<div id="app-content"></div>
<script src="./scripts/notification.js" type="text/javascript" charset="utf-8"></script>
<script src="./scripts/popup.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

View File

@ -41,6 +41,12 @@ function Extension () {
}
} catch (e) {}
try {
if (browser[api]) {
_this[api] = browser[api]
}
}
try {
_this.api = browser.extension[api]
} catch (e) {}

View File

@ -0,0 +1,8 @@
module.exports = function isPopupOrNotification() {
const url = window.location.href
if (url.match(/popup.html$/)) {
return 'popup'
} else {
return 'notification'
}
}

View File

@ -31,7 +31,7 @@ function createMsgNotification (state) {
}
function showNotification() {
chrome.windows.create({
extension.windows.create({
url:"notification.html",
type:"panel",
width:360,

View File

@ -9,6 +9,7 @@ const injectCss = require('inject-css')
const PortStream = require('./lib/port-stream.js')
const StreamProvider = require('web3-stream-provider')
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
const isPopupOrNotification = require('./lib/is-popup-or-notification')
const extension = require('./lib/extension')
// setup app
@ -22,7 +23,10 @@ async.parallel({
function connectToAccountManager (cb) {
// setup communication with background
var pluginPort = extension.runtime.connect({name: 'popup'})
var name = isPopupOrNotification()
window.METAMASK_UI_TYPE = name
var pluginPort = extension.runtime.connect({ name })
var portStream = new PortStream(pluginPort)
// setup multiplexing
var mx = setupMultiplex(portStream)
@ -93,3 +97,4 @@ function setupApp (err, opts) {
networkVersion: opts.networkVersion,
})
}

View File

@ -108,7 +108,6 @@ const jsFiles = [
'contentscript',
'background',
'popup',
'notification',
]
jsFiles.forEach((jsFile) => {
@ -116,9 +115,9 @@ jsFiles.forEach((jsFile) => {
gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` }))
})
gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup', 'dev:js:notification'))
gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup'))
gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup', 'dev:js:notification'))
gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup'))
// clean dist

View File

@ -1,52 +0,0 @@
const render = require('react-dom').render
const h = require('react-hyperscript')
const Root = require('./app/root')
const actions = require('./app/actions')
const configureStore = require('./app/store')
module.exports = launchApp
function launchApp (opts) {
var accountManager = opts.accountManager
actions._setAccountManager(accountManager)
// check if we are unlocked first
accountManager.getState(function (err, metamaskState) {
if (err) throw err
startApp(metamaskState, accountManager, opts)
})
}
function startApp (metamaskState, accountManager, opts) {
// parse opts
var store = configureStore({
// metamaskState represents the cross-tab state
metamask: metamaskState,
// appState represents the current tab's popup state
appState: {
currentDomain: opts.currentDomain,
},
// Which blockchain we are using:
networkVersion: opts.networkVersion,
})
// if unconfirmed txs, start on txConf page
if (Object.keys(metamaskState.unconfTxs || {}).length) {
store.dispatch(actions.showConfTxPage())
}
accountManager.on('update', function (metamaskState) {
store.dispatch(actions.updateMetamaskState(metamaskState))
})
// start app
render(
h(Root, {
// inject initial state
store: store,
}
), opts.container)
}