@ -1,4 +1,4 @@
import extension from 'extensionizer '
import ExtensionPlatform from '../platforms/ extension'
const NOTIFICATION _HEIGHT = 620
const NOTIFICATION _HEIGHT = 620
const NOTIFICATION _WIDTH = 360
const NOTIFICATION _WIDTH = 360
@ -12,57 +12,49 @@ class NotificationManager {
*
*
* /
* /
constructor ( ) {
this . platform = new ExtensionPlatform ( )
}
/ * *
/ * *
* Either brings an existing MetaMask notification window into focus , or creates a new notification window . New
* Either brings an existing MetaMask notification window into focus , or creates a new notification window . New
* notification windows are given a 'popup' type .
* notification windows are given a 'popup' type .
*
*
* /
* /
showPopup ( ) {
async showPopup ( ) {
this . _getPopup ( ( err , popup ) => {
const popup = await this . _getPopup ( )
if ( err ) {
throw err
}
// Bring focus to chrome popup
// Bring focus to chrome popup
if ( popup ) {
if ( popup ) {
// bring focus to existing chrome popup
// bring focus to existing chrome popup
extension . windows . update ( popup . id , { focused : true } )
await this . platform . focusWindow ( popup . id )
} else {
} else {
const { screenX , screenY , outerWidth , outerHeight } = window
const { screenX , screenY , outerWidth , outerHeight } = window
const notificationTop = Math . round ( screenY + ( outerHeight / 2 ) - ( NOTIFICATION _HEIGHT / 2 ) )
const notificationTop = Math . round ( screenY + ( outerHeight / 2 ) - ( NOTIFICATION _HEIGHT / 2 ) )
const notificationLeft = Math . round ( screenX + ( outerWidth / 2 ) - ( NOTIFICATION _WIDTH / 2 ) )
const notificationLeft = Math . round ( screenX + ( outerWidth / 2 ) - ( NOTIFICATION _WIDTH / 2 ) )
const cb = ( currentPopup ) => {
// create new notification popup
this . _popupId = currentPopup . id
const popupWindow = await this . platform . openWindow ( {
}
url : 'notification.html' ,
// create new notification popup
type : 'popup' ,
const creation = extension . windows . create ( {
width : NOTIFICATION _WIDTH ,
url : 'notification.html' ,
height : NOTIFICATION _HEIGHT ,
type : 'popup' ,
top : Math . max ( notificationTop , 0 ) ,
width : NOTIFICATION _WIDTH ,
left : Math . max ( notificationLeft , 0 ) ,
height : NOTIFICATION _HEIGHT ,
} )
top : Math . max ( notificationTop , 0 ) ,
this . _popupId = popupWindow . id
left : Math . max ( notificationLeft , 0 ) ,
}
} , cb )
creation && creation . then && creation . then ( cb )
}
} )
}
}
/ * *
/ * *
* Closes a MetaMask notification if it window exists .
* Closes a MetaMask notification if it window exists .
*
*
* /
* /
closePopup ( ) {
async closePopup ( ) {
// closes notification popup
const popup = this . _getPopup ( )
this . _getPopup ( ( err , popup ) => {
if ( ! popup ) {
if ( err ) {
return
throw err
}
}
await this . platform . removeWindow ( popup . id )
if ( ! popup ) {
return
}
extension . windows . remove ( popup . id , console . error )
} )
}
}
/ * *
/ * *
@ -73,31 +65,9 @@ class NotificationManager {
* @ param { Function } cb - A node style callback that to whcih the found notification window will be passed .
* @ param { Function } cb - A node style callback that to whcih the found notification window will be passed .
*
*
* /
* /
_getPopup ( cb ) {
async _getPopup ( ) {
this . _getWindows ( ( err , windows ) => {
const windows = await this . platform . getAllWindows ( )
if ( err ) {
return this . _getPopupIn ( windows )
throw err
}
cb ( null , this . _getPopupIn ( windows ) )
} )
}
/ * *
* Returns all open MetaMask windows .
*
* @ private
* @ param { Function } cb - A node style callback that to which the windows will be passed .
*
* /
_getWindows ( cb ) {
// Ignore in test environment
if ( ! extension . windows ) {
return cb ( )
}
extension . windows . getAll ( { } , ( windows ) => {
cb ( null , windows )
} )
}
}
/ * *
/ * *