@@ -7,11 +7,15 @@ declare const Notification: any;
77@Injectable ( )
88export class PushNotificationsService {
99
10- permission : Permission = 'granted' ;
10+ permission : Permission ;
11+
12+ constructor ( ) {
13+ this . permission = this . isSupported ( ) ? Notification . permission : 'denied' ;
14+ }
1115
1216 requestPermission ( ) {
1317 if ( 'Notification' in window )
14- Notification . requestPermission ( status => this . permission = status ) ;
18+ Notification . requestPermission ( ( status : any ) => this . permission = status ) ;
1519 }
1620
1721 isSupported ( ) {
@@ -20,31 +24,25 @@ export class PushNotificationsService {
2024
2125 create ( title : string , options ?: PushNotification ) : any {
2226
23- return new Observable ( obs => {
27+ return new Observable ( ( obs : any ) => {
2428
2529 if ( ! ( 'Notification' in window ) ) {
26- obs . error ( 'Notifications are not available in this envirement ' ) ;
30+ obs . error ( 'Notifications are not available in this environment ' ) ;
2731 obs . complete ( ) ;
2832 }
2933
30- this . permission = Notification . permission ;
31-
3234 if ( this . permission !== 'granted' ) {
33- obs . error ( `The user didn 't granted you permission to send push notifications` ) ;
35+ obs . error ( `The user hasn 't granted you permission to send push notifications` ) ;
3436 obs . complete ( ) ;
3537 }
3638
3739 const n = new Notification ( title , options ) ;
3840
39- n . onshow = ( e ) => obs . next ( { notification : n , event : e } ) ;
40- n . onclick = ( e ) => obs . next ( { notification : n , event : e } ) ;
41- n . onerror = ( e ) => obs . error ( { notification : n , event : e } ) ;
41+ n . onshow = ( e : any ) => obs . next ( { notification : n , event : e } ) ;
42+ n . onclick = ( e : any ) => obs . next ( { notification : n , event : e } ) ;
43+ n . onerror = ( e : any ) => obs . error ( { notification : n , event : e } ) ;
4244 n . onclose = ( ) => obs . complete ( ) ;
43- n . close = ( ) => {
44- n . close . bind ( n ) ;
45- obs . complete ( ) ;
46- } ;
4745 } ) ;
4846 }
4947
50- }
48+ }
0 commit comments