barsa-novin-ray-core 2.3.97 → 2.3.98

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, 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';
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';
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';
@@ -7803,32 +7803,12 @@ const NOTIFICATION_WEBWORKER_FACTORY = new InjectionToken('notificaion-worker');
7803
7803
  class ServiceWorkerNotificationService {
7804
7804
  constructor() {
7805
7805
  this.hasRegistration = false;
7806
- this._logService = inject(LogService);
7807
7806
  this._swPush = inject(SwPush);
7808
7807
  this._portalService = inject(PortalService);
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();
7808
+ this._notificationPermissionAllowed = false;
7809
+ this.init();
7831
7810
  }
7811
+ // بررسی وضعیت فعلی
7832
7812
  get isEnabled() {
7833
7813
  return this._swPush.isEnabled && this.hasRegistration && this._notificationPermissionAllowed;
7834
7814
  }
@@ -7844,6 +7824,7 @@ class ServiceWorkerNotificationService {
7844
7824
  }
7845
7825
  });
7846
7826
  }
7827
+ // نمایش دستی نوتیفیکیشن (برای تست)
7847
7828
  async showNotification(payload) {
7848
7829
  const sw = await this.getSw();
7849
7830
  if (!sw) {
@@ -7883,6 +7864,23 @@ class ServiceWorkerNotificationService {
7883
7864
  data
7884
7865
  });
7885
7866
  }
7867
+ async init() {
7868
+ console.log(`SwPush enabled: ${this._swPush.isEnabled}`);
7869
+ this.handlePermission();
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
+ }
7886
7884
  handlePermission() {
7887
7885
  if (!navigator?.permissions?.query) {
7888
7886
  return;
@@ -7895,14 +7893,17 @@ class ServiceWorkerNotificationService {
7895
7893
  permissionQuery(result) {
7896
7894
  let newPrompt;
7897
7895
  if (result.state === 'granted') {
7896
+ console.log('notificaiton granted');
7898
7897
  // notifications allowed, go wild
7899
7898
  }
7900
7899
  else if (result.state === 'prompt') {
7901
7900
  // we can ask the user
7901
+ console.log('notificaiton prompt');
7902
7902
  newPrompt = Notification.requestPermission();
7903
7903
  }
7904
7904
  else if (result.state === 'denied') {
7905
7905
  // notifications were disabled
7906
+ console.log('notificaiton denied');
7906
7907
  this._notificationPermissionAllowed = false;
7907
7908
  }
7908
7909
  result.onchange = () => console.log({ updatedPermission: result });
@@ -7912,14 +7913,23 @@ class ServiceWorkerNotificationService {
7912
7913
  this._notificationPermissionAllowed = false;
7913
7914
  console.error(error);
7914
7915
  }
7915
- async getSw() {
7916
- if (!navigator.serviceWorker) {
7917
- this.hasRegistration = false;
7918
- return undefined;
7916
+ async requestPermission() {
7917
+ if (Notification.permission === 'default') {
7918
+ await Notification.requestPermission();
7919
7919
  }
7920
- const x = await navigator.serviceWorker.getRegistration('custom-ngsw-worker.js');
7921
- this.hasRegistration = !!x;
7922
- return x;
7920
+ this._notificationPermissionAllowed = Notification.permission === 'granted';
7921
+ }
7922
+ async registerServiceWorker() {
7923
+ if (!('serviceWorker' in navigator)) {
7924
+ return;
7925
+ }
7926
+ const reg = await navigator.serviceWorker.getRegistration();
7927
+ this.hasRegistration = !!reg;
7928
+ }
7929
+ async getSw() {
7930
+ const reg = await navigator.serviceWorker.getRegistration();
7931
+ this.hasRegistration = !!reg;
7932
+ return reg;
7923
7933
  }
7924
7934
  _isSupported() {
7925
7935
  if (!('serviceWorker' in navigator)) {