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
|
const isEdge = !isIE && !!window.StyleMedia
|
||||||
|
|
||||||
let popupIsOpen = false
|
let popupIsOpen = false
|
||||||
|
let notificationIsOpen = false
|
||||||
let openMetamaskTabsIDs = {}
|
let openMetamaskTabsIDs = {}
|
||||||
|
|
||||||
// state persistence
|
// state persistence
|
||||||
|
@ -165,6 +166,11 @@ function setupController (initState) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (remotePort.name === 'notification') {
|
||||||
|
endOfStream(portStream, () => {
|
||||||
|
notificationIsOpen = false
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// communication with page
|
// communication with page
|
||||||
const originDomain = urlUtil.parse(remotePort.sender.url).hostname
|
const originDomain = urlUtil.parse(remotePort.sender.url).hostname
|
||||||
|
@ -207,7 +213,8 @@ function setupController (initState) {
|
||||||
function triggerUi () {
|
function triggerUi () {
|
||||||
extension.tabs.query({ active: true }, (tabs) => {
|
extension.tabs.query({ active: true }, (tabs) => {
|
||||||
const currentlyActiveMetamaskTab = tabs.find(tab => openMetamaskTabsIDs[tab.id])
|
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) => {
|
this._getPopup((err, popup) => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
|
// Bring focus to chrome popup
|
||||||
if (popup) {
|
if (popup) {
|
||||||
// bring focus to existing popup
|
// bring focus to existing chrome popup
|
||||||
extension.windows.update(popup.id, { focused: true })
|
extension.windows.update(popup.id, { focused: true })
|
||||||
} else {
|
} else {
|
||||||
// create new popup
|
// create new notification popup
|
||||||
extension.windows.create({
|
extension.windows.create({
|
||||||
url: 'notification.html',
|
url: 'notification.html',
|
||||||
type: 'popup',
|
type: 'popup',
|
||||||
|
@ -29,6 +30,7 @@ class NotificationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
closePopup () {
|
closePopup () {
|
||||||
|
// closes notification popup
|
||||||
this._getPopup((err, popup) => {
|
this._getPopup((err, popup) => {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
if (!popup) return
|
if (!popup) return
|
||||||
|
@ -60,9 +62,8 @@ class NotificationManager {
|
||||||
|
|
||||||
_getPopupIn (windows) {
|
_getPopupIn (windows) {
|
||||||
return windows ? windows.find((win) => {
|
return windows ? windows.find((win) => {
|
||||||
return (win && win.type === 'popup' &&
|
// Returns notification popup
|
||||||
win.height === height &&
|
return (win && win.type === 'popup')
|
||||||
win.width === width)
|
|
||||||
}) : null
|
}) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ startPopup({ container, connectionStream }, (err, store) => {
|
||||||
|
|
||||||
function closePopupIfOpen (windowType) {
|
function closePopupIfOpen (windowType) {
|
||||||
if (windowType !== 'notification') {
|
if (windowType !== 'notification') {
|
||||||
|
// should close only chrome popup
|
||||||
notificationManager.closePopup()
|
notificationManager.closePopup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue