barsa-novin-ray-core 2.3.96 → 2.3.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, inject, ElementRef, Input, ChangeDetectionStrategy, Component, Pipe, ComponentFactoryResolver, Injector, ApplicationRef, Compiler, DOCUMENT, NgModuleFactory, InjectionToken, NgZone, EventEmitter, ChangeDetectorRef, Renderer2, HostBinding, Output, HostListener, ViewContainerRef, ViewChild, signal, Directive, TemplateRef, input, NgModule, NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA, provideAppInitializer, ErrorHandler } from '@angular/core';
3
- import { Subject, from, BehaviorSubject, of, exhaustMap, map as map$1, combineLatest, withLatestFrom as withLatestFrom$1, fromEvent, forkJoin, takeUntil as takeUntil$1, filter as filter$1, throwError, merge, interval, concatMap as concatMap$1, catchError as catchError$1, finalize as finalize$1, take, debounceTime as debounceTime$1, skip, Observable, tap as tap$1, timer, mergeWith, Subscription } from 'rxjs';
3
+ import { Subject, from, BehaviorSubject, of, exhaustMap, map as map$1, combineLatest, withLatestFrom as withLatestFrom$1, fromEvent, forkJoin, takeUntil as takeUntil$1, filter as filter$1, throwError, merge, interval, tap as tap$1, concatMap as concatMap$1, catchError as catchError$1, finalize as finalize$1, take, debounceTime as debounceTime$1, skip, Observable, timer, mergeWith, Subscription } from 'rxjs';
4
4
  import * as i1 from '@angular/router';
5
5
  import { Router, NavigationEnd, ActivatedRoute, RouterEvent, NavigationStart, RouterModule } from '@angular/router';
6
6
  import { DomSanitizer, Title } from '@angular/platform-browser';
@@ -7802,16 +7802,35 @@ const NOTIFICATION_WEBWORKER_FACTORY = new InjectionToken('notificaion-worker');
7802
7802
 
7803
7803
  class ServiceWorkerNotificationService {
7804
7804
  constructor() {
7805
+ this.hasRegistration = false;
7805
7806
  this._logService = inject(LogService);
7806
7807
  this._swPush = inject(SwPush);
7807
7808
  this._portalService = inject(PortalService);
7808
- this._notificationPermissionAllowed = false;
7809
- this._hasRegistration = false;
7810
- this.init();
7809
+ this._notificationPermissionAllowed = true;
7810
+ const _logService = this._logService;
7811
+ const _swPush = this._swPush;
7812
+ _logService.info(`swPush enable ${_swPush.isEnabled}`);
7813
+ _swPush.notificationClicks.pipe(tap$1((c) => console.log(c))).subscribe((e) => {
7814
+ if (!e.notification.tag) {
7815
+ return;
7816
+ }
7817
+ this.closeNotifications([e.notification.tag]);
7818
+ let actionTitle = e.action;
7819
+ if (actionTitle === '') {
7820
+ actionTitle = 'show';
7821
+ }
7822
+ if (!BarsaApi?.LoginFormData?.IsUserLoggedIn) {
7823
+ return;
7824
+ }
7825
+ this._portalService.ExecuteNotificationAction(e.notification.tag, actionTitle);
7826
+ // TODO:exeucte action
7827
+ // not handled!!
7828
+ });
7829
+ this.getSw().then((c) => (this.hasRegistration = !!c));
7830
+ this.handlePermission();
7811
7831
  }
7812
- // بررسی وضعیت فعلی
7813
7832
  get isEnabled() {
7814
- return this._swPush.isEnabled && this._hasRegistration && this._notificationPermissionAllowed;
7833
+ return this._swPush.isEnabled && this.hasRegistration && this._notificationPermissionAllowed;
7815
7834
  }
7816
7835
  async closeNotifications(tags) {
7817
7836
  const sw = await this.getSw();
@@ -7825,7 +7844,6 @@ class ServiceWorkerNotificationService {
7825
7844
  }
7826
7845
  });
7827
7846
  }
7828
- // نمایش دستی نوتیفیکیشن (برای تست)
7829
7847
  async showNotification(payload) {
7830
7848
  const sw = await this.getSw();
7831
7849
  if (!sw) {
@@ -7865,40 +7883,43 @@ class ServiceWorkerNotificationService {
7865
7883
  data
7866
7884
  });
7867
7885
  }
7868
- async init() {
7869
- this._logService.info(`SwPush enabled: ${this._swPush.isEnabled}`);
7870
- // مدیریت کلیک روی نوتیفیکیشن‌ها
7871
- this._swPush.notificationClicks.subscribe((e) => {
7872
- if (!e.notification.tag) {
7873
- return;
7874
- }
7875
- const actionTitle = e.action || 'show';
7876
- if (!BarsaApi?.LoginFormData?.IsUserLoggedIn) {
7877
- return;
7878
- }
7879
- this._portalService.ExecuteNotificationAction(e.notification.tag, actionTitle);
7880
- });
7881
- // بررسی مجوز و ثبت سرویس‌ورکر
7882
- await this.registerServiceWorker();
7883
- await this.requestPermission();
7884
- }
7885
- async requestPermission() {
7886
- if (Notification.permission === 'default') {
7887
- await Notification.requestPermission();
7886
+ handlePermission() {
7887
+ if (!navigator?.permissions?.query) {
7888
+ return;
7888
7889
  }
7889
- this._notificationPermissionAllowed = Notification.permission === 'granted';
7890
+ return navigator.permissions
7891
+ .query({ name: 'notifications' })
7892
+ .then(this.permissionQuery.bind(this))
7893
+ .catch(this.permissionError.bind(this));
7890
7894
  }
7891
- async registerServiceWorker() {
7892
- if (!('serviceWorker' in navigator)) {
7893
- return;
7895
+ permissionQuery(result) {
7896
+ let newPrompt;
7897
+ if (result.state === 'granted') {
7898
+ // notifications allowed, go wild
7894
7899
  }
7895
- const reg = await navigator.serviceWorker.getRegistration();
7896
- this._hasRegistration = !!reg;
7900
+ else if (result.state === 'prompt') {
7901
+ // we can ask the user
7902
+ newPrompt = Notification.requestPermission();
7903
+ }
7904
+ else if (result.state === 'denied') {
7905
+ // notifications were disabled
7906
+ this._notificationPermissionAllowed = false;
7907
+ }
7908
+ result.onchange = () => console.log({ updatedPermission: result });
7909
+ return newPrompt || result;
7910
+ }
7911
+ permissionError(error) {
7912
+ this._notificationPermissionAllowed = false;
7913
+ console.error(error);
7897
7914
  }
7898
7915
  async getSw() {
7899
- const reg = await navigator.serviceWorker.getRegistration();
7900
- this._hasRegistration = !!reg;
7901
- return reg;
7916
+ if (!navigator.serviceWorker) {
7917
+ this.hasRegistration = false;
7918
+ return undefined;
7919
+ }
7920
+ const x = await navigator.serviceWorker.getRegistration('custom-ngsw-worker.js');
7921
+ this.hasRegistration = !!x;
7922
+ return x;
7902
7923
  }
7903
7924
  _isSupported() {
7904
7925
  if (!('serviceWorker' in navigator)) {