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:
commit
278e1ba61e
@ -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
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ startPopup({ container, connectionStream }, (err, store) => {
|
||||
|
||||
function closePopupIfOpen (windowType) {
|
||||
if (windowType !== 'notification') {
|
||||
// should close only chrome popup
|
||||
notificationManager.closePopup()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user