Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
flauc committed Nov 1, 2016
2 parents b1ef230 + f65f336 commit c6a5fea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class NotificationComponent implements OnInit, OnDestroy {
return this.position !== 0 ? this.position * 90 : 0;
}

onClick($e): void {
onClick($e: any): void {
this.item.click.emit($e);

if (this.clickToClose) {
Expand Down
28 changes: 13 additions & 15 deletions src/push-notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ declare const Notification: any;
@Injectable()
export class PushNotificationsService {

permission: Permission = 'granted';
permission: Permission;

constructor() {
this.permission = this.isSupported() ? Notification.permission : 'denied';
}

requestPermission() {
if ('Notification' in window)
Notification.requestPermission(status => this.permission = status);
Notification.requestPermission((status: any) => this.permission = status);
}

isSupported() {
Expand All @@ -20,31 +24,25 @@ export class PushNotificationsService {

create(title: string, options?: PushNotification): any {

return new Observable(obs => {
return new Observable((obs: any) => {

if (!('Notification' in window)) {
obs.error('Notifications are not available in this envirement');
obs.error('Notifications are not available in this environment');
obs.complete();
}

this.permission = Notification.permission;

if (this.permission !== 'granted') {
obs.error(`The user didn't granted you permission to send push notifications`);
obs.error(`The user hasn't granted you permission to send push notifications`);
obs.complete();
}

const n = new Notification(title, options);

n.onshow = (e) => obs.next({notification: n, event: e});
n.onclick = (e) => obs.next({notification: n, event: e});
n.onerror = (e) => obs.error({notification: n, event: e});
n.onshow = (e: any) => obs.next({notification: n, event: e});
n.onclick = (e: any) => obs.next({notification: n, event: e});
n.onerror = (e: any) => obs.error({notification: n, event: e});
n.onclose = () => obs.complete();
n.close = () => {
n.close.bind(n);
obs.complete();
};
});
}

}
}

0 comments on commit c6a5fea

Please sign in to comment.