@burdenoff/fe-libs 2026.1012.4 → 2026.1012.5
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.
|
@@ -10,6 +10,7 @@ export interface PushOptInDeps {
|
|
|
10
10
|
isRealNativePlatform: () => boolean;
|
|
11
11
|
isWebPushSupported: () => boolean;
|
|
12
12
|
getWebPushSubscription: () => Promise<unknown>;
|
|
13
|
+
checkNativePermission: () => Promise<string | null>;
|
|
13
14
|
requestNativePermission: () => Promise<boolean>;
|
|
14
15
|
requestWebPermission: () => Promise<unknown>;
|
|
15
16
|
unsubscribeWeb: () => Promise<boolean>;
|
|
@@ -1,62 +1,63 @@
|
|
|
1
1
|
import { unregisterPushDevice as e } from "../shared/native/push-registration.js";
|
|
2
2
|
import { registerPushOptInController as t } from "../shared/native/push-optin.js";
|
|
3
3
|
import { isRealNativePlatform as n } from "./platform.js";
|
|
4
|
-
import {
|
|
5
|
-
import { getWebPushSubscription as
|
|
4
|
+
import { checkPushPermission as r, requestPushPermission as i } from "./push.js";
|
|
5
|
+
import { getWebPushSubscription as a, isWebPushSupported as o, requestWebPushPermission as s, unsubscribeWebPush as c } from "./web-push.js";
|
|
6
6
|
//#region src/shell-native/push-optin.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
for (let t of
|
|
7
|
+
var l = /* @__PURE__ */ new Set(), u = "unsupported";
|
|
8
|
+
function d(e) {
|
|
9
|
+
u = e;
|
|
10
|
+
for (let t of l) try {
|
|
11
11
|
t(e);
|
|
12
12
|
} catch {}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function f() {
|
|
15
15
|
return typeof Notification > "u" ? null : Notification.permission;
|
|
16
16
|
}
|
|
17
|
-
async function
|
|
18
|
-
if (
|
|
19
|
-
let e =
|
|
17
|
+
async function p() {
|
|
18
|
+
if (g.isRealNativePlatform()) {
|
|
19
|
+
let e = await g.checkNativePermission();
|
|
20
20
|
return e === "denied" ? "denied" : e === "granted" ? "enabled" : "default";
|
|
21
21
|
}
|
|
22
|
-
if (!
|
|
23
|
-
let e =
|
|
24
|
-
return e === "denied" ? "denied" : e === "granted" ? await
|
|
22
|
+
if (!g.isWebPushSupported()) return "unsupported";
|
|
23
|
+
let e = f();
|
|
24
|
+
return e === "denied" ? "denied" : e === "granted" ? await g.getWebPushSubscription() ? "enabled" : "disabled" : "default";
|
|
25
25
|
}
|
|
26
|
-
async function
|
|
27
|
-
let e = await
|
|
28
|
-
return
|
|
26
|
+
async function m() {
|
|
27
|
+
let e = await p();
|
|
28
|
+
return d(e), e;
|
|
29
29
|
}
|
|
30
|
-
var
|
|
30
|
+
var h = {
|
|
31
31
|
isRealNativePlatform: n,
|
|
32
|
-
isWebPushSupported:
|
|
33
|
-
getWebPushSubscription:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
isWebPushSupported: o,
|
|
33
|
+
getWebPushSubscription: a,
|
|
34
|
+
checkNativePermission: r,
|
|
35
|
+
requestNativePermission: i,
|
|
36
|
+
requestWebPermission: s,
|
|
37
|
+
unsubscribeWeb: c,
|
|
37
38
|
unregisterDevice: e
|
|
38
|
-
},
|
|
39
|
-
getState: () =>
|
|
39
|
+
}, g = h, _ = {
|
|
40
|
+
getState: () => u,
|
|
40
41
|
async enable() {
|
|
41
|
-
return
|
|
42
|
+
return g.isRealNativePlatform() ? await g.requestNativePermission() : await g.requestWebPermission(), m();
|
|
42
43
|
},
|
|
43
44
|
async disable() {
|
|
44
|
-
return
|
|
45
|
+
return g.isRealNativePlatform() || await g.unsubscribeWeb(), await g.unregisterDevice(), m();
|
|
45
46
|
},
|
|
46
47
|
subscribe(e) {
|
|
47
|
-
return
|
|
48
|
+
return l.add(e), () => l.delete(e);
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
...
|
|
51
|
+
function v(e) {
|
|
52
|
+
g = e ? {
|
|
53
|
+
...h,
|
|
53
54
|
...e
|
|
54
|
-
} :
|
|
55
|
-
|
|
55
|
+
} : h, t(_), m(), typeof window < "u" && window.addEventListener("burdenoff:pushToken", () => {
|
|
56
|
+
m();
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
59
|
+
function y() {
|
|
60
|
+
l.clear(), u = "unsupported", g = h, t(null);
|
|
60
61
|
}
|
|
61
62
|
//#endregion
|
|
62
|
-
export {
|
|
63
|
+
export { v as installPushOptIn, y as resetPushOptInForTests };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PushTokenEventDetail } from '../shared/native/types';
|
|
2
|
-
import { PushNotificationsLoader, PushOptions } from './types';
|
|
2
|
+
import { PushNotificationsLoader, PushOptions, PushPermissionStateLike } from './types';
|
|
3
3
|
export declare const PUSH_TOKEN_EVENT = "burdenoff:pushToken";
|
|
4
4
|
/**
|
|
5
5
|
* Publish a push token to the rest of the app: `window.__burdenoffPushToken`
|
|
@@ -16,6 +16,16 @@ export declare function emitPushToken(value: string, platform: PushTokenEventDet
|
|
|
16
16
|
* Does NOT prompt for permission — call `requestPushPermission()` for that.
|
|
17
17
|
*/
|
|
18
18
|
export declare function installPushNotifications(loader: PushNotificationsLoader, options?: Pick<PushOptions, 'onToken' | 'onNotificationAction' | 'onNotificationReceived'>): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Read current native permission state WITHOUT prompting.
|
|
21
|
+
*
|
|
22
|
+
* `push-optin.ts` needs this to answer "is push on?" for a real native
|
|
23
|
+
* platform — the Web `Notification` API (`push-optin.ts`'s `browserPermission()`)
|
|
24
|
+
* is a browser/PWA concept and reads as unset inside a Capacitor WKWebView, so
|
|
25
|
+
* using it there always reported `default` even after the user granted the
|
|
26
|
+
* native OS permission prompt, leaving the toggle stuck off.
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkPushPermission(): Promise<PushPermissionStateLike | null>;
|
|
19
29
|
/**
|
|
20
30
|
* Ask the user for push permission (call from an in-context UI affordance,
|
|
21
31
|
* never at boot) and register for a token on grant.
|
|
@@ -57,6 +57,15 @@ async function l(t, r = {}) {
|
|
|
57
57
|
} catch {}
|
|
58
58
|
}
|
|
59
59
|
async function u() {
|
|
60
|
+
let e = await s();
|
|
61
|
+
if (!e) return null;
|
|
62
|
+
try {
|
|
63
|
+
return (await e.checkPermissions()).receive;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function d() {
|
|
60
69
|
let t = await s();
|
|
61
70
|
if (!t) return !1;
|
|
62
71
|
try {
|
|
@@ -69,4 +78,4 @@ async function u() {
|
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
//#endregion
|
|
72
|
-
export { r as PUSH_TOKEN_EVENT, i as emitPushToken, l as installPushNotifications,
|
|
81
|
+
export { r as PUSH_TOKEN_EVENT, u as checkPushPermission, i as emitPushToken, l as installPushNotifications, d as requestPushPermission };
|