barsa-novin-ray-core 2.3.96 → 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.
|
@@ -7802,16 +7802,15 @@ const NOTIFICATION_WEBWORKER_FACTORY = new InjectionToken('notificaion-worker');
|
|
|
7802
7802
|
|
|
7803
7803
|
class ServiceWorkerNotificationService {
|
|
7804
7804
|
constructor() {
|
|
7805
|
-
this.
|
|
7805
|
+
this.hasRegistration = false;
|
|
7806
7806
|
this._swPush = inject(SwPush);
|
|
7807
7807
|
this._portalService = inject(PortalService);
|
|
7808
7808
|
this._notificationPermissionAllowed = false;
|
|
7809
|
-
this._hasRegistration = false;
|
|
7810
7809
|
this.init();
|
|
7811
7810
|
}
|
|
7812
7811
|
// بررسی وضعیت فعلی
|
|
7813
7812
|
get isEnabled() {
|
|
7814
|
-
return this._swPush.isEnabled && this.
|
|
7813
|
+
return this._swPush.isEnabled && this.hasRegistration && this._notificationPermissionAllowed;
|
|
7815
7814
|
}
|
|
7816
7815
|
async closeNotifications(tags) {
|
|
7817
7816
|
const sw = await this.getSw();
|
|
@@ -7866,7 +7865,8 @@ class ServiceWorkerNotificationService {
|
|
|
7866
7865
|
});
|
|
7867
7866
|
}
|
|
7868
7867
|
async init() {
|
|
7869
|
-
|
|
7868
|
+
console.log(`SwPush enabled: ${this._swPush.isEnabled}`);
|
|
7869
|
+
this.handlePermission();
|
|
7870
7870
|
// مدیریت کلیک روی نوتیفیکیشنها
|
|
7871
7871
|
this._swPush.notificationClicks.subscribe((e) => {
|
|
7872
7872
|
if (!e.notification.tag) {
|
|
@@ -7880,7 +7880,38 @@ class ServiceWorkerNotificationService {
|
|
|
7880
7880
|
});
|
|
7881
7881
|
// بررسی مجوز و ثبت سرویسورکر
|
|
7882
7882
|
await this.registerServiceWorker();
|
|
7883
|
-
|
|
7883
|
+
}
|
|
7884
|
+
handlePermission() {
|
|
7885
|
+
if (!navigator?.permissions?.query) {
|
|
7886
|
+
return;
|
|
7887
|
+
}
|
|
7888
|
+
return navigator.permissions
|
|
7889
|
+
.query({ name: 'notifications' })
|
|
7890
|
+
.then(this.permissionQuery.bind(this))
|
|
7891
|
+
.catch(this.permissionError.bind(this));
|
|
7892
|
+
}
|
|
7893
|
+
permissionQuery(result) {
|
|
7894
|
+
let newPrompt;
|
|
7895
|
+
if (result.state === 'granted') {
|
|
7896
|
+
console.log('notificaiton granted');
|
|
7897
|
+
// notifications allowed, go wild
|
|
7898
|
+
}
|
|
7899
|
+
else if (result.state === 'prompt') {
|
|
7900
|
+
// we can ask the user
|
|
7901
|
+
console.log('notificaiton prompt');
|
|
7902
|
+
newPrompt = Notification.requestPermission();
|
|
7903
|
+
}
|
|
7904
|
+
else if (result.state === 'denied') {
|
|
7905
|
+
// notifications were disabled
|
|
7906
|
+
console.log('notificaiton denied');
|
|
7907
|
+
this._notificationPermissionAllowed = false;
|
|
7908
|
+
}
|
|
7909
|
+
result.onchange = () => console.log({ updatedPermission: result });
|
|
7910
|
+
return newPrompt || result;
|
|
7911
|
+
}
|
|
7912
|
+
permissionError(error) {
|
|
7913
|
+
this._notificationPermissionAllowed = false;
|
|
7914
|
+
console.error(error);
|
|
7884
7915
|
}
|
|
7885
7916
|
async requestPermission() {
|
|
7886
7917
|
if (Notification.permission === 'default') {
|
|
@@ -7893,11 +7924,11 @@ class ServiceWorkerNotificationService {
|
|
|
7893
7924
|
return;
|
|
7894
7925
|
}
|
|
7895
7926
|
const reg = await navigator.serviceWorker.getRegistration();
|
|
7896
|
-
this.
|
|
7927
|
+
this.hasRegistration = !!reg;
|
|
7897
7928
|
}
|
|
7898
7929
|
async getSw() {
|
|
7899
7930
|
const reg = await navigator.serviceWorker.getRegistration();
|
|
7900
|
-
this.
|
|
7931
|
+
this.hasRegistration = !!reg;
|
|
7901
7932
|
return reg;
|
|
7902
7933
|
}
|
|
7903
7934
|
_isSupported() {
|