1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/app/scripts/lib/notifications.js

66 lines
1.2 KiB
JavaScript
Raw Normal View History

const extension = require('./extension')
const height = 520
const width = 360
2016-07-12 05:53:26 +02:00
const notifications = {
2016-08-24 00:44:50 +02:00
show,
getPopup,
2016-08-24 00:44:50 +02:00
closePopup,
}
module.exports = notifications
window.METAMASK_NOTIFIER = notifications
2016-08-24 00:44:50 +02:00
function show () {
getPopup((err, popup) => {
if (err) throw err
if (popup) {
// bring focus to existing popup
extension.windows.update(popup.id, { focused: true })
} else {
// create new popup
extension.windows.create({
url: 'notification.html',
type: 'popup',
focused: true,
width,
height,
})
}
})
2016-06-25 02:22:27 +02:00
}
2016-06-23 04:28:11 +02:00
2016-11-11 19:26:12 +01:00
function getWindows (cb) {
2016-08-23 20:48:46 +02:00
// Ignore in test environment
if (!extension.windows) {
return cb()
2016-08-23 20:48:46 +02:00
}
extension.windows.getAll({}, (windows) => {
cb(null, windows)
})
}
2016-11-11 19:26:12 +01:00
function getPopup (cb) {
getWindows((err, windows) => {
if (err) throw err
cb(null, getPopupIn(windows))
})
}
2016-11-11 19:26:12 +01:00
function getPopupIn (windows) {
return windows ? windows.find((win) => {
return (win && win.type === 'popup' &&
win.height === height &&
win.width === width)
}) : null
}
2016-11-11 19:26:12 +01:00
function closePopup () {
getPopup((err, popup) => {
if (err) throw err
2016-08-24 00:44:50 +02:00
if (!popup) return
extension.windows.remove(popup.id, console.error)
})
}