mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Position notification relative to last focused window (#8356)
This commit is contained in:
parent
50451341a0
commit
f9989c52c5
@ -29,17 +29,30 @@ class NotificationManager {
|
|||||||
// bring focus to existing chrome popup
|
// bring focus to existing chrome popup
|
||||||
await this.platform.focusWindow(popup.id)
|
await this.platform.focusWindow(popup.id)
|
||||||
} else {
|
} else {
|
||||||
const { screenX, screenY, outerWidth, outerHeight } = window
|
let left = 0
|
||||||
const notificationTop = Math.round(screenY + (outerHeight / 2) - (NOTIFICATION_HEIGHT / 2))
|
let top = 0
|
||||||
const notificationLeft = Math.round(screenX + (outerWidth / 2) - (NOTIFICATION_WIDTH / 2))
|
try {
|
||||||
|
const lastFocused = await this.platform.getLastFocusedWindow()
|
||||||
|
// Position window in top right corner of lastFocused window.
|
||||||
|
top = lastFocused.top
|
||||||
|
left = lastFocused.left + (lastFocused.width - NOTIFICATION_WIDTH)
|
||||||
|
} catch (_) {
|
||||||
|
// The following properties are more than likely 0, due to being
|
||||||
|
// opened from the background chrome process for the extension that
|
||||||
|
// has no physical dimensions
|
||||||
|
const { screenX, screenY, outerWidth } = window
|
||||||
|
top = Math.max(screenY, 0)
|
||||||
|
left = Math.max(screenX + (outerWidth - NOTIFICATION_WIDTH), 0)
|
||||||
|
}
|
||||||
|
|
||||||
// create new notification popup
|
// create new notification popup
|
||||||
const popupWindow = await this.platform.openWindow({
|
const popupWindow = await this.platform.openWindow({
|
||||||
url: 'notification.html',
|
url: 'notification.html',
|
||||||
type: 'popup',
|
type: 'popup',
|
||||||
width: NOTIFICATION_WIDTH,
|
width: NOTIFICATION_WIDTH,
|
||||||
height: NOTIFICATION_HEIGHT,
|
height: NOTIFICATION_HEIGHT,
|
||||||
top: Math.max(notificationTop, 0),
|
left,
|
||||||
left: Math.max(notificationLeft, 0),
|
top,
|
||||||
})
|
})
|
||||||
this._popupId = popupWindow.id
|
this._popupId = popupWindow.id
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,18 @@ class ExtensionPlatform {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastFocusedWindow () {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
extension.windows.getLastFocused((windowObject) => {
|
||||||
|
const error = checkForError()
|
||||||
|
if (error) {
|
||||||
|
return reject(error)
|
||||||
|
}
|
||||||
|
return resolve(windowObject)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
closeCurrentWindow () {
|
closeCurrentWindow () {
|
||||||
return extension.windows.getCurrent((windowDetails) => {
|
return extension.windows.getCurrent((windowDetails) => {
|
||||||
return extension.windows.remove(windowDetails.id)
|
return extension.windows.remove(windowDetails.id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user