@@ -9,20 +9,26 @@ module.exports = notifications
9
9
window . METAMASK_NOTIFIER = notifications
10
10
11
11
function show ( ) {
12
- getWindows ( ( windows ) => {
12
+ getPopup ( ( err , popup ) => {
13
+ if ( err ) throw err
13
14
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 {
18
21
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
+ }
26
32
} )
27
33
}
28
34
@@ -38,19 +44,19 @@ function getWindows(cb) {
38
44
}
39
45
40
46
function getPopup ( cb ) {
41
- getWindows ( ( windows ) => {
42
- cb ( getPopupIn ( windows ) )
47
+ getWindows ( ( err , windows ) => {
48
+ if ( err ) throw err
49
+ cb ( null , getPopupIn ( windows ) )
43
50
} )
44
51
}
45
52
46
53
function 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
50
55
}
51
56
52
57
function closePopup ( ) {
53
- getPopup ( ( popup ) => {
58
+ getPopup ( ( err , popup ) => {
59
+ if ( err ) throw err
54
60
if ( ! popup ) return
55
61
extension . windows . remove ( popup . id , console . error )
56
62
} )
0 commit comments