@@ -89,38 +89,40 @@ class Notification extends React.Component {
89
89
}
90
90
}
91
91
92
+ doNotification ( ) {
93
+ let opt = this . props . options ;
94
+ if ( typeof opt . tag !== 'string' ) {
95
+ opt . tag = 'web-notification-' + seq ( ) ;
96
+ }
97
+ if ( this . notifications [ opt . tag ] ) {
98
+ return ;
99
+ }
92
100
101
+ if ( this . props . swRegistration && this . props . swRegistration . showNotification ) {
102
+ this . props . swRegistration . showNotification ( this . props . title , opt )
103
+ this . notifications [ opt . tag ] = { } ;
104
+ } else {
105
+ const n = new window . Notification ( this . props . title , opt ) ;
106
+ n . onshow = e => {
107
+ this . props . onShow ( e , opt . tag ) ;
108
+ if ( this . props . timeout > 0 ) {
109
+ setTimeout ( ( ) => {
110
+ this . close ( n ) ;
111
+ } , this . props . timeout ) ;
112
+ }
113
+ } ;
114
+ n . onclick = e => { this . props . onClick ( e , opt . tag ) ; } ;
115
+ n . onclose = e => { this . props . onClose ( e , opt . tag ) ; } ;
116
+ n . onerror = e => { this . props . onError ( e , opt . tag ) ; } ;
117
+
118
+ this . notifications [ opt . tag ] = n ;
119
+ }
120
+ }
93
121
94
122
render ( ) {
95
123
let doNotShowOnActiveWindow = this . props . disableActiveWindow && this . windowFocus ;
96
124
if ( ! this . props . ignore && this . props . title && this . state . supported && this . state . granted && ! doNotShowOnActiveWindow ) {
97
-
98
- let opt = this . props . options ;
99
- if ( typeof opt . tag !== 'string' ) {
100
- opt . tag = 'web-notification-' + seq ( ) ;
101
- }
102
-
103
- if ( ! this . notifications [ opt . tag ] ) {
104
- if ( this . props . swRegistration && this . props . swRegistration . showNotification ) {
105
- this . props . swRegistration . showNotification ( this . props . title , opt )
106
- this . notifications [ opt . tag ] = { } ;
107
- } else {
108
- const n = new window . Notification ( this . props . title , opt ) ;
109
- n . onshow = e => {
110
- this . props . onShow ( e , opt . tag ) ;
111
- if ( this . props . timeout > 0 ) {
112
- setTimeout ( ( ) => {
113
- this . close ( n ) ;
114
- } , this . props . timeout ) ;
115
- }
116
- } ;
117
- n . onclick = e => { this . props . onClick ( e , opt . tag ) ; } ;
118
- n . onclose = e => { this . props . onClose ( e , opt . tag ) ; } ;
119
- n . onerror = e => { this . props . onError ( e , opt . tag ) ; } ;
120
-
121
- this . notifications [ opt . tag ] = n ;
122
- }
123
- }
125
+ this . doNotification ( ) ;
124
126
}
125
127
126
128
// return null cause
0 commit comments