1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #3656 from MetaMask/trigun0x2-master2

Prevent batch request from opening multiple windows (3)
This commit is contained in:
kumavis 2018-03-21 12:42:03 -07:00 committed by GitHub
commit 278e1ba61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -42,6 +42,7 @@ const isIE = !!document.documentMode
const isEdge = !isIE && !!window.StyleMedia
let popupIsOpen = false
let notificationIsOpen = false
let openMetamaskTabsIDs = {}
// state persistence
@ -165,6 +166,11 @@ function setupController (initState) {
}
})
}
if (remotePort.name === 'notification') {
endOfStream(portStream, () => {
notificationIsOpen = false
})
}
} else {
// communication with page
const originDomain = urlUtil.parse(remotePort.sender.url).hostname
@ -207,7 +213,8 @@ function setupController (initState) {
function triggerUi () {
extension.tabs.query({ active: true }, (tabs) => {
const currentlyActiveMetamaskTab = tabs.find(tab => openMetamaskTabsIDs[tab.id])
if (!popupIsOpen && !currentlyActiveMetamaskTab) notificationManager.showPopup()
if (!popupIsOpen && !currentlyActiveMetamaskTab && !notificationIsOpen) notificationManager.showPopup()
notificationIsOpen = true
})
}

View File

@ -13,11 +13,12 @@ class NotificationManager {
this._getPopup((err, popup) => {
if (err) throw err
// Bring focus to chrome popup
if (popup) {
// bring focus to existing popup
// bring focus to existing chrome popup
extension.windows.update(popup.id, { focused: true })
} else {
// create new popup
// create new notification popup
extension.windows.create({
url: 'notification.html',
type: 'popup',
@ -29,6 +30,7 @@ class NotificationManager {
}
closePopup () {
// closes notification popup
this._getPopup((err, popup) => {
if (err) throw err
if (!popup) return
@ -60,9 +62,8 @@ class NotificationManager {
_getPopupIn (windows) {
return windows ? windows.find((win) => {
return (win && win.type === 'popup' &&
win.height === height &&
win.width === width)
// Returns notification popup
return (win && win.type === 'popup')
}) : null
}

View File

@ -65,6 +65,7 @@ startPopup({ container, connectionStream }, (err, store) => {
function closePopupIfOpen (windowType) {
if (windowType !== 'notification') {
// should close only chrome popup
notificationManager.closePopup()
}
}