@@ -9,20 +9,26 @@ module.exports = notifications
99window . METAMASK_NOTIFIER = notifications
1010
1111function show ( ) {
12- getWindows ( ( windows ) => {
12+ getPopup ( ( err , popup ) => {
13+ if ( err ) throw err
1314
14- if ( windows . length > 0 ) {
15- const win = windows [ 0 ]
16- return extension . windows . update ( win . id , { focused : true } )
17- }
15+ if ( popup ) {
16+
17+ // bring focus to existing popup
18+ extension . windows . update ( popup . id , { focused : true } )
19+
20+ } else {
1821
19- extension . windows . create ( {
20- url : 'notification.html' ,
21- type : 'popup' ,
22- focused : true ,
23- width : 360 ,
24- height : 500 ,
25- } )
22+ // create new popup
23+ extension . windows . create ( {
24+ url : 'notification.html' ,
25+ type : 'popup' ,
26+ focused : true ,
27+ width : 360 ,
28+ height : 500 ,
29+ } )
30+
31+ }
2632 } )
2733}
2834
@@ -38,19 +44,19 @@ function getWindows(cb) {
3844}
3945
4046function getPopup ( cb ) {
41- getWindows ( ( windows ) => {
42- cb ( getPopupIn ( windows ) )
47+ getWindows ( ( err , windows ) => {
48+ if ( err ) throw err
49+ cb ( null , getPopupIn ( windows ) )
4350 } )
4451}
4552
4653function getPopupIn ( windows ) {
47- return windows ? windows . find ( ( win ) => {
48- return win . type === 'popup'
49- } ) : null
54+ return windows ? windows . find ( ( win ) => win . type === 'popup' ) : null
5055}
5156
5257function closePopup ( ) {
53- getPopup ( ( popup ) => {
58+ getPopup ( ( err , popup ) => {
59+ if ( err ) throw err
5460 if ( ! popup ) return
5561 extension . windows . remove ( popup . id , console . error )
5662 } )
0 commit comments