@elizaos/capacitor-mobile-signals 1.0.0

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.
@@ -0,0 +1,285 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const loadWeb = () => Promise.resolve().then(function () { return web; }).then((m) => new m.MobileSignalsWeb());
6
+ const MobileSignals = core.registerPlugin("MobileSignals", {
7
+ web: loadWeb,
8
+ });
9
+
10
+ const SCREEN_TIME_REQUIREMENTS = {
11
+ entitlements: {
12
+ familyControls: "com.apple.developer.family-controls",
13
+ },
14
+ frameworks: ["FamilyControls", "DeviceActivity"],
15
+ deviceActivityReportExtension: false,
16
+ deviceActivityMonitorExtension: false,
17
+ android: {
18
+ usageStatsPermission: "android.permission.PACKAGE_USAGE_STATS",
19
+ usageAccessSettingsAction: "android.settings.USAGE_ACCESS_SETTINGS",
20
+ },
21
+ };
22
+ function getPlatform() {
23
+ if (typeof navigator === "undefined") {
24
+ return "web";
25
+ }
26
+ const ua = navigator.userAgent.toLowerCase();
27
+ if (ua.includes("android"))
28
+ return "android";
29
+ if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) {
30
+ return "ios";
31
+ }
32
+ return "web";
33
+ }
34
+ function buildScreenTimeStatus(reason) {
35
+ return {
36
+ supported: false,
37
+ requirements: SCREEN_TIME_REQUIREMENTS,
38
+ entitlements: {
39
+ familyControls: false,
40
+ },
41
+ provisioning: {
42
+ satisfied: false,
43
+ inspected: "not-inspectable",
44
+ reason,
45
+ },
46
+ authorization: {
47
+ status: "unavailable",
48
+ canRequest: false,
49
+ },
50
+ reportAvailable: false,
51
+ coarseSummaryAvailable: false,
52
+ thresholdEventsAvailable: false,
53
+ rawUsageExportAvailable: false,
54
+ android: {
55
+ usageAccessGranted: false,
56
+ packageUsageStatsPermissionDeclared: false,
57
+ canOpenUsageAccessSettings: false,
58
+ foregroundEventsAvailable: false,
59
+ totalTimeForegroundMs: null,
60
+ },
61
+ reason,
62
+ };
63
+ }
64
+ function buildSetupActions(reason) {
65
+ return [
66
+ {
67
+ id: "health_permissions",
68
+ label: "Health permissions",
69
+ status: "unavailable",
70
+ canRequest: false,
71
+ canOpenSettings: false,
72
+ settingsTarget: null,
73
+ reason,
74
+ },
75
+ {
76
+ id: "screen_time_authorization",
77
+ label: "Screen Time",
78
+ status: "unavailable",
79
+ canRequest: false,
80
+ canOpenSettings: false,
81
+ settingsTarget: null,
82
+ reason: "Web fallback cannot open native Screen Time settings.",
83
+ },
84
+ ];
85
+ }
86
+ async function getBatterySnapshot() {
87
+ const nav = typeof navigator !== "undefined"
88
+ ? navigator
89
+ : null;
90
+ if (!nav || typeof nav.getBattery !== "function") {
91
+ return { onBattery: null, batteryLevel: null, isCharging: null };
92
+ }
93
+ const battery = await nav.getBattery();
94
+ return {
95
+ onBattery: !battery.charging,
96
+ batteryLevel: typeof battery.level === "number"
97
+ ? Math.max(0, Math.min(1, battery.level))
98
+ : null,
99
+ isCharging: battery.charging,
100
+ };
101
+ }
102
+ async function buildSnapshot(reason) {
103
+ const isVisible = typeof document !== "undefined"
104
+ ? document.visibilityState === "visible"
105
+ : true;
106
+ const hasFocus = typeof document !== "undefined" && typeof document.hasFocus === "function"
107
+ ? document.hasFocus()
108
+ : true;
109
+ const battery = await getBatterySnapshot();
110
+ const state = isVisible && hasFocus ? "active" : "background";
111
+ const idleState = isVisible
112
+ ? "active"
113
+ : "idle";
114
+ return {
115
+ source: "mobile_device",
116
+ platform: getPlatform(),
117
+ state,
118
+ observedAt: Date.now(),
119
+ idleState,
120
+ idleTimeSeconds: null,
121
+ onBattery: battery.onBattery,
122
+ metadata: {
123
+ reason,
124
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : "visible",
125
+ hasFocus,
126
+ ...battery,
127
+ },
128
+ };
129
+ }
130
+ function buildHealthSnapshot(reason) {
131
+ return {
132
+ source: "mobile_health",
133
+ platform: getPlatform(),
134
+ state: "idle",
135
+ observedAt: Date.now(),
136
+ idleState: null,
137
+ idleTimeSeconds: null,
138
+ onBattery: null,
139
+ healthSource: "healthkit",
140
+ screenTime: buildScreenTimeStatus("Web fallback has no Family Controls or DeviceActivity access."),
141
+ permissions: {
142
+ sleep: false,
143
+ biometrics: false,
144
+ },
145
+ sleep: {
146
+ available: false,
147
+ isSleeping: false,
148
+ asleepAt: null,
149
+ awakeAt: null,
150
+ durationMinutes: null,
151
+ stage: null,
152
+ },
153
+ biometrics: {
154
+ sampleAt: null,
155
+ heartRateBpm: null,
156
+ restingHeartRateBpm: null,
157
+ heartRateVariabilityMs: null,
158
+ respiratoryRate: null,
159
+ bloodOxygenPercent: null,
160
+ },
161
+ warnings: [`web fallback has no health access (${reason})`],
162
+ metadata: {
163
+ reason,
164
+ platform: getPlatform(),
165
+ supported: false,
166
+ },
167
+ };
168
+ }
169
+ class MobileSignalsWeb extends core.WebPlugin {
170
+ constructor() {
171
+ super(...arguments);
172
+ this.monitoring = false;
173
+ this.cleanup = [];
174
+ this.emitSignal = async (reason) => {
175
+ if (!this.monitoring)
176
+ return;
177
+ const snapshot = await buildSnapshot(reason);
178
+ this.notifyListeners("signal", snapshot);
179
+ this.notifyListeners("signal", buildHealthSnapshot(reason));
180
+ };
181
+ }
182
+ async checkPermissions() {
183
+ return {
184
+ status: "not-applicable",
185
+ canRequest: false,
186
+ screenTime: buildScreenTimeStatus("Web fallback has no Family Controls or DeviceActivity access."),
187
+ setupActions: buildSetupActions("Web fallback has no HealthKit or Health Connect access."),
188
+ permissions: {
189
+ sleep: false,
190
+ biometrics: false,
191
+ },
192
+ reason: "Web fallback has no HealthKit or Health Connect access.",
193
+ };
194
+ }
195
+ async requestPermissions() {
196
+ return this.checkPermissions();
197
+ }
198
+ async openSettings(options = {}) {
199
+ return {
200
+ opened: false,
201
+ target: options.target ?? "app",
202
+ actualTarget: "app",
203
+ reason: "Web fallback cannot open native device settings.",
204
+ };
205
+ }
206
+ attachListeners() {
207
+ if (typeof document !== "undefined") {
208
+ const handleVisibilityChange = () => {
209
+ void this.emitSignal("visibilitychange");
210
+ };
211
+ document.addEventListener("visibilitychange", handleVisibilityChange);
212
+ this.cleanup.push(() => document.removeEventListener("visibilitychange", handleVisibilityChange));
213
+ }
214
+ if (typeof window !== "undefined") {
215
+ const handleFocus = () => {
216
+ void this.emitSignal("focus");
217
+ };
218
+ const handleBlur = () => {
219
+ void this.emitSignal("blur");
220
+ };
221
+ window.addEventListener("focus", handleFocus);
222
+ window.addEventListener("blur", handleBlur);
223
+ this.cleanup.push(() => window.removeEventListener("focus", handleFocus));
224
+ this.cleanup.push(() => window.removeEventListener("blur", handleBlur));
225
+ }
226
+ }
227
+ clearListeners() {
228
+ while (this.cleanup.length > 0) {
229
+ const cleanup = this.cleanup.pop();
230
+ cleanup?.();
231
+ }
232
+ }
233
+ async startMonitoring(options = {}) {
234
+ if (!this.monitoring) {
235
+ this.monitoring = true;
236
+ this.attachListeners();
237
+ }
238
+ const snapshot = await buildSnapshot("start");
239
+ const healthSnapshot = buildHealthSnapshot("start");
240
+ if (options.emitInitial ?? true) {
241
+ this.notifyListeners("signal", snapshot);
242
+ this.notifyListeners("signal", healthSnapshot);
243
+ }
244
+ return {
245
+ enabled: this.monitoring,
246
+ supported: true,
247
+ platform: snapshot.platform,
248
+ snapshot,
249
+ healthSnapshot,
250
+ };
251
+ }
252
+ async stopMonitoring() {
253
+ this.monitoring = false;
254
+ this.clearListeners();
255
+ return { stopped: true };
256
+ }
257
+ async getSnapshot() {
258
+ const snapshot = await buildSnapshot("snapshot");
259
+ return {
260
+ supported: true,
261
+ snapshot,
262
+ healthSnapshot: buildHealthSnapshot("snapshot"),
263
+ };
264
+ }
265
+ async scheduleBackgroundRefresh() {
266
+ return {
267
+ scheduled: false,
268
+ reason: "Web fallback cannot schedule native background refresh tasks.",
269
+ };
270
+ }
271
+ async cancelBackgroundRefresh() {
272
+ return {
273
+ cancelled: false,
274
+ reason: "Web fallback has no native background refresh task to cancel.",
275
+ };
276
+ }
277
+ }
278
+
279
+ var web = /*#__PURE__*/Object.freeze({
280
+ __proto__: null,
281
+ MobileSignalsWeb: MobileSignalsWeb
282
+ });
283
+
284
+ exports.MobileSignals = MobileSignals;
285
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.MobileSignalsWeb());\nexport const MobileSignals = registerPlugin(\"MobileSignals\", {\n web: loadWeb,\n});\n","import { WebPlugin } from \"@capacitor/core\";\nconst SCREEN_TIME_REQUIREMENTS = {\n entitlements: {\n familyControls: \"com.apple.developer.family-controls\",\n },\n frameworks: [\"FamilyControls\", \"DeviceActivity\"],\n deviceActivityReportExtension: false,\n deviceActivityMonitorExtension: false,\n android: {\n usageStatsPermission: \"android.permission.PACKAGE_USAGE_STATS\",\n usageAccessSettingsAction: \"android.settings.USAGE_ACCESS_SETTINGS\",\n },\n};\nfunction getPlatform() {\n if (typeof navigator === \"undefined\") {\n return \"web\";\n }\n const ua = navigator.userAgent.toLowerCase();\n if (ua.includes(\"android\"))\n return \"android\";\n if (ua.includes(\"iphone\") || ua.includes(\"ipad\") || ua.includes(\"ipod\")) {\n return \"ios\";\n }\n return \"web\";\n}\nfunction buildScreenTimeStatus(reason) {\n return {\n supported: false,\n requirements: SCREEN_TIME_REQUIREMENTS,\n entitlements: {\n familyControls: false,\n },\n provisioning: {\n satisfied: false,\n inspected: \"not-inspectable\",\n reason,\n },\n authorization: {\n status: \"unavailable\",\n canRequest: false,\n },\n reportAvailable: false,\n coarseSummaryAvailable: false,\n thresholdEventsAvailable: false,\n rawUsageExportAvailable: false,\n android: {\n usageAccessGranted: false,\n packageUsageStatsPermissionDeclared: false,\n canOpenUsageAccessSettings: false,\n foregroundEventsAvailable: false,\n totalTimeForegroundMs: null,\n },\n reason,\n };\n}\nfunction buildSetupActions(reason) {\n return [\n {\n id: \"health_permissions\",\n label: \"Health permissions\",\n status: \"unavailable\",\n canRequest: false,\n canOpenSettings: false,\n settingsTarget: null,\n reason,\n },\n {\n id: \"screen_time_authorization\",\n label: \"Screen Time\",\n status: \"unavailable\",\n canRequest: false,\n canOpenSettings: false,\n settingsTarget: null,\n reason: \"Web fallback cannot open native Screen Time settings.\",\n },\n ];\n}\nasync function getBatterySnapshot() {\n const nav = typeof navigator !== \"undefined\"\n ? navigator\n : null;\n if (!nav || typeof nav.getBattery !== \"function\") {\n return { onBattery: null, batteryLevel: null, isCharging: null };\n }\n const battery = await nav.getBattery();\n return {\n onBattery: !battery.charging,\n batteryLevel: typeof battery.level === \"number\"\n ? Math.max(0, Math.min(1, battery.level))\n : null,\n isCharging: battery.charging,\n };\n}\nasync function buildSnapshot(reason) {\n const isVisible = typeof document !== \"undefined\"\n ? document.visibilityState === \"visible\"\n : true;\n const hasFocus = typeof document !== \"undefined\" && typeof document.hasFocus === \"function\"\n ? document.hasFocus()\n : true;\n const battery = await getBatterySnapshot();\n const state = isVisible && hasFocus ? \"active\" : \"background\";\n const idleState = isVisible\n ? \"active\"\n : \"idle\";\n return {\n source: \"mobile_device\",\n platform: getPlatform(),\n state,\n observedAt: Date.now(),\n idleState,\n idleTimeSeconds: null,\n onBattery: battery.onBattery,\n metadata: {\n reason,\n visibilityState: typeof document !== \"undefined\" ? document.visibilityState : \"visible\",\n hasFocus,\n ...battery,\n },\n };\n}\nfunction buildHealthSnapshot(reason) {\n return {\n source: \"mobile_health\",\n platform: getPlatform(),\n state: \"idle\",\n observedAt: Date.now(),\n idleState: null,\n idleTimeSeconds: null,\n onBattery: null,\n healthSource: \"healthkit\",\n screenTime: buildScreenTimeStatus(\"Web fallback has no Family Controls or DeviceActivity access.\"),\n permissions: {\n sleep: false,\n biometrics: false,\n },\n sleep: {\n available: false,\n isSleeping: false,\n asleepAt: null,\n awakeAt: null,\n durationMinutes: null,\n stage: null,\n },\n biometrics: {\n sampleAt: null,\n heartRateBpm: null,\n restingHeartRateBpm: null,\n heartRateVariabilityMs: null,\n respiratoryRate: null,\n bloodOxygenPercent: null,\n },\n warnings: [`web fallback has no health access (${reason})`],\n metadata: {\n reason,\n platform: getPlatform(),\n supported: false,\n },\n };\n}\nexport class MobileSignalsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.monitoring = false;\n this.cleanup = [];\n this.emitSignal = async (reason) => {\n if (!this.monitoring)\n return;\n const snapshot = await buildSnapshot(reason);\n this.notifyListeners(\"signal\", snapshot);\n this.notifyListeners(\"signal\", buildHealthSnapshot(reason));\n };\n }\n async checkPermissions() {\n return {\n status: \"not-applicable\",\n canRequest: false,\n screenTime: buildScreenTimeStatus(\"Web fallback has no Family Controls or DeviceActivity access.\"),\n setupActions: buildSetupActions(\"Web fallback has no HealthKit or Health Connect access.\"),\n permissions: {\n sleep: false,\n biometrics: false,\n },\n reason: \"Web fallback has no HealthKit or Health Connect access.\",\n };\n }\n async requestPermissions() {\n return this.checkPermissions();\n }\n async openSettings(options = {}) {\n return {\n opened: false,\n target: options.target ?? \"app\",\n actualTarget: \"app\",\n reason: \"Web fallback cannot open native device settings.\",\n };\n }\n attachListeners() {\n if (typeof document !== \"undefined\") {\n const handleVisibilityChange = () => {\n void this.emitSignal(\"visibilitychange\");\n };\n document.addEventListener(\"visibilitychange\", handleVisibilityChange);\n this.cleanup.push(() => document.removeEventListener(\"visibilitychange\", handleVisibilityChange));\n }\n if (typeof window !== \"undefined\") {\n const handleFocus = () => {\n void this.emitSignal(\"focus\");\n };\n const handleBlur = () => {\n void this.emitSignal(\"blur\");\n };\n window.addEventListener(\"focus\", handleFocus);\n window.addEventListener(\"blur\", handleBlur);\n this.cleanup.push(() => window.removeEventListener(\"focus\", handleFocus));\n this.cleanup.push(() => window.removeEventListener(\"blur\", handleBlur));\n }\n }\n clearListeners() {\n while (this.cleanup.length > 0) {\n const cleanup = this.cleanup.pop();\n cleanup?.();\n }\n }\n async startMonitoring(options = {}) {\n if (!this.monitoring) {\n this.monitoring = true;\n this.attachListeners();\n }\n const snapshot = await buildSnapshot(\"start\");\n const healthSnapshot = buildHealthSnapshot(\"start\");\n if (options.emitInitial ?? true) {\n this.notifyListeners(\"signal\", snapshot);\n this.notifyListeners(\"signal\", healthSnapshot);\n }\n return {\n enabled: this.monitoring,\n supported: true,\n platform: snapshot.platform,\n snapshot,\n healthSnapshot,\n };\n }\n async stopMonitoring() {\n this.monitoring = false;\n this.clearListeners();\n return { stopped: true };\n }\n async getSnapshot() {\n const snapshot = await buildSnapshot(\"snapshot\");\n return {\n supported: true,\n snapshot,\n healthSnapshot: buildHealthSnapshot(\"snapshot\"),\n };\n }\n async scheduleBackgroundRefresh() {\n return {\n scheduled: false,\n reason: \"Web fallback cannot schedule native background refresh tasks.\",\n };\n }\n async cancelBackgroundRefresh() {\n return {\n cancelled: false,\n reason: \"Web fallback has no native background refresh task to cancel.\",\n };\n }\n}\nexport const __internal = {\n buildScreenTimeStatus,\n};\n"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC/D,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AAC7D,IAAI,GAAG,EAAE,OAAO;AAChB,CAAC;;ACJD,MAAM,wBAAwB,GAAG;AACjC,IAAI,YAAY,EAAE;AAClB,QAAQ,cAAc,EAAE,qCAAqC;AAC7D,KAAK;AACL,IAAI,UAAU,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;AACpD,IAAI,6BAA6B,EAAE,KAAK;AACxC,IAAI,8BAA8B,EAAE,KAAK;AACzC,IAAI,OAAO,EAAE;AACb,QAAQ,oBAAoB,EAAE,wCAAwC;AACtE,QAAQ,yBAAyB,EAAE,wCAAwC;AAC3E,KAAK;AACL,CAAC;AACD,SAAS,WAAW,GAAG;AACvB,IAA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eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC;AACpD,YAAY,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC;AAC1D,QAAQ;AACR,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,IAAI,CAAC,UAAU;AACpC,YAAY,SAAS,EAAE,IAAI;AAC3B,YAAY,QAAQ,EAAE,QAAQ,CAAC,QAAQ;AACvC,YAAY,QAAQ;AACpB,YAAY,cAAc;AAC1B,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,IAAI,CAAC,UAAU,GAAG,KAAK;AAC/B,QAAQ,IAAI,CAAC,cAAc,EAAE;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAChC,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC;AACxD,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,IAAI;AAC3B,YAAY,QAAQ;AACpB,YAAY,cAAc,EAAE,mBAAmB,CAAC,UAAU,CAAC;AAC3D,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,yBAAyB,GAAG;AACtC,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,KAAK;AAC5B,YAAY,MAAM,EAAE,+DAA+D;AACnF,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,uBAAuB,GAAG;AACpC,QAAQ,OAAO;AACf,YAAY,SAAS,EAAE,KAAK;AAC5B,YAAY,MAAM,EAAE,+DAA+D;AACnF,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,288 @@
1
+ var capacitorElizaMobileSignals = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const loadWeb = () => Promise.resolve().then(function () { return web; }).then((m) => new m.MobileSignalsWeb());
5
+ const MobileSignals = core.registerPlugin("MobileSignals", {
6
+ web: loadWeb,
7
+ });
8
+
9
+ const SCREEN_TIME_REQUIREMENTS = {
10
+ entitlements: {
11
+ familyControls: "com.apple.developer.family-controls",
12
+ },
13
+ frameworks: ["FamilyControls", "DeviceActivity"],
14
+ deviceActivityReportExtension: false,
15
+ deviceActivityMonitorExtension: false,
16
+ android: {
17
+ usageStatsPermission: "android.permission.PACKAGE_USAGE_STATS",
18
+ usageAccessSettingsAction: "android.settings.USAGE_ACCESS_SETTINGS",
19
+ },
20
+ };
21
+ function getPlatform() {
22
+ if (typeof navigator === "undefined") {
23
+ return "web";
24
+ }
25
+ const ua = navigator.userAgent.toLowerCase();
26
+ if (ua.includes("android"))
27
+ return "android";
28
+ if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) {
29
+ return "ios";
30
+ }
31
+ return "web";
32
+ }
33
+ function buildScreenTimeStatus(reason) {
34
+ return {
35
+ supported: false,
36
+ requirements: SCREEN_TIME_REQUIREMENTS,
37
+ entitlements: {
38
+ familyControls: false,
39
+ },
40
+ provisioning: {
41
+ satisfied: false,
42
+ inspected: "not-inspectable",
43
+ reason,
44
+ },
45
+ authorization: {
46
+ status: "unavailable",
47
+ canRequest: false,
48
+ },
49
+ reportAvailable: false,
50
+ coarseSummaryAvailable: false,
51
+ thresholdEventsAvailable: false,
52
+ rawUsageExportAvailable: false,
53
+ android: {
54
+ usageAccessGranted: false,
55
+ packageUsageStatsPermissionDeclared: false,
56
+ canOpenUsageAccessSettings: false,
57
+ foregroundEventsAvailable: false,
58
+ totalTimeForegroundMs: null,
59
+ },
60
+ reason,
61
+ };
62
+ }
63
+ function buildSetupActions(reason) {
64
+ return [
65
+ {
66
+ id: "health_permissions",
67
+ label: "Health permissions",
68
+ status: "unavailable",
69
+ canRequest: false,
70
+ canOpenSettings: false,
71
+ settingsTarget: null,
72
+ reason,
73
+ },
74
+ {
75
+ id: "screen_time_authorization",
76
+ label: "Screen Time",
77
+ status: "unavailable",
78
+ canRequest: false,
79
+ canOpenSettings: false,
80
+ settingsTarget: null,
81
+ reason: "Web fallback cannot open native Screen Time settings.",
82
+ },
83
+ ];
84
+ }
85
+ async function getBatterySnapshot() {
86
+ const nav = typeof navigator !== "undefined"
87
+ ? navigator
88
+ : null;
89
+ if (!nav || typeof nav.getBattery !== "function") {
90
+ return { onBattery: null, batteryLevel: null, isCharging: null };
91
+ }
92
+ const battery = await nav.getBattery();
93
+ return {
94
+ onBattery: !battery.charging,
95
+ batteryLevel: typeof battery.level === "number"
96
+ ? Math.max(0, Math.min(1, battery.level))
97
+ : null,
98
+ isCharging: battery.charging,
99
+ };
100
+ }
101
+ async function buildSnapshot(reason) {
102
+ const isVisible = typeof document !== "undefined"
103
+ ? document.visibilityState === "visible"
104
+ : true;
105
+ const hasFocus = typeof document !== "undefined" && typeof document.hasFocus === "function"
106
+ ? document.hasFocus()
107
+ : true;
108
+ const battery = await getBatterySnapshot();
109
+ const state = isVisible && hasFocus ? "active" : "background";
110
+ const idleState = isVisible
111
+ ? "active"
112
+ : "idle";
113
+ return {
114
+ source: "mobile_device",
115
+ platform: getPlatform(),
116
+ state,
117
+ observedAt: Date.now(),
118
+ idleState,
119
+ idleTimeSeconds: null,
120
+ onBattery: battery.onBattery,
121
+ metadata: {
122
+ reason,
123
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : "visible",
124
+ hasFocus,
125
+ ...battery,
126
+ },
127
+ };
128
+ }
129
+ function buildHealthSnapshot(reason) {
130
+ return {
131
+ source: "mobile_health",
132
+ platform: getPlatform(),
133
+ state: "idle",
134
+ observedAt: Date.now(),
135
+ idleState: null,
136
+ idleTimeSeconds: null,
137
+ onBattery: null,
138
+ healthSource: "healthkit",
139
+ screenTime: buildScreenTimeStatus("Web fallback has no Family Controls or DeviceActivity access."),
140
+ permissions: {
141
+ sleep: false,
142
+ biometrics: false,
143
+ },
144
+ sleep: {
145
+ available: false,
146
+ isSleeping: false,
147
+ asleepAt: null,
148
+ awakeAt: null,
149
+ durationMinutes: null,
150
+ stage: null,
151
+ },
152
+ biometrics: {
153
+ sampleAt: null,
154
+ heartRateBpm: null,
155
+ restingHeartRateBpm: null,
156
+ heartRateVariabilityMs: null,
157
+ respiratoryRate: null,
158
+ bloodOxygenPercent: null,
159
+ },
160
+ warnings: [`web fallback has no health access (${reason})`],
161
+ metadata: {
162
+ reason,
163
+ platform: getPlatform(),
164
+ supported: false,
165
+ },
166
+ };
167
+ }
168
+ class MobileSignalsWeb extends core.WebPlugin {
169
+ constructor() {
170
+ super(...arguments);
171
+ this.monitoring = false;
172
+ this.cleanup = [];
173
+ this.emitSignal = async (reason) => {
174
+ if (!this.monitoring)
175
+ return;
176
+ const snapshot = await buildSnapshot(reason);
177
+ this.notifyListeners("signal", snapshot);
178
+ this.notifyListeners("signal", buildHealthSnapshot(reason));
179
+ };
180
+ }
181
+ async checkPermissions() {
182
+ return {
183
+ status: "not-applicable",
184
+ canRequest: false,
185
+ screenTime: buildScreenTimeStatus("Web fallback has no Family Controls or DeviceActivity access."),
186
+ setupActions: buildSetupActions("Web fallback has no HealthKit or Health Connect access."),
187
+ permissions: {
188
+ sleep: false,
189
+ biometrics: false,
190
+ },
191
+ reason: "Web fallback has no HealthKit or Health Connect access.",
192
+ };
193
+ }
194
+ async requestPermissions() {
195
+ return this.checkPermissions();
196
+ }
197
+ async openSettings(options = {}) {
198
+ return {
199
+ opened: false,
200
+ target: options.target ?? "app",
201
+ actualTarget: "app",
202
+ reason: "Web fallback cannot open native device settings.",
203
+ };
204
+ }
205
+ attachListeners() {
206
+ if (typeof document !== "undefined") {
207
+ const handleVisibilityChange = () => {
208
+ void this.emitSignal("visibilitychange");
209
+ };
210
+ document.addEventListener("visibilitychange", handleVisibilityChange);
211
+ this.cleanup.push(() => document.removeEventListener("visibilitychange", handleVisibilityChange));
212
+ }
213
+ if (typeof window !== "undefined") {
214
+ const handleFocus = () => {
215
+ void this.emitSignal("focus");
216
+ };
217
+ const handleBlur = () => {
218
+ void this.emitSignal("blur");
219
+ };
220
+ window.addEventListener("focus", handleFocus);
221
+ window.addEventListener("blur", handleBlur);
222
+ this.cleanup.push(() => window.removeEventListener("focus", handleFocus));
223
+ this.cleanup.push(() => window.removeEventListener("blur", handleBlur));
224
+ }
225
+ }
226
+ clearListeners() {
227
+ while (this.cleanup.length > 0) {
228
+ const cleanup = this.cleanup.pop();
229
+ cleanup?.();
230
+ }
231
+ }
232
+ async startMonitoring(options = {}) {
233
+ if (!this.monitoring) {
234
+ this.monitoring = true;
235
+ this.attachListeners();
236
+ }
237
+ const snapshot = await buildSnapshot("start");
238
+ const healthSnapshot = buildHealthSnapshot("start");
239
+ if (options.emitInitial ?? true) {
240
+ this.notifyListeners("signal", snapshot);
241
+ this.notifyListeners("signal", healthSnapshot);
242
+ }
243
+ return {
244
+ enabled: this.monitoring,
245
+ supported: true,
246
+ platform: snapshot.platform,
247
+ snapshot,
248
+ healthSnapshot,
249
+ };
250
+ }
251
+ async stopMonitoring() {
252
+ this.monitoring = false;
253
+ this.clearListeners();
254
+ return { stopped: true };
255
+ }
256
+ async getSnapshot() {
257
+ const snapshot = await buildSnapshot("snapshot");
258
+ return {
259
+ supported: true,
260
+ snapshot,
261
+ healthSnapshot: buildHealthSnapshot("snapshot"),
262
+ };
263
+ }
264
+ async scheduleBackgroundRefresh() {
265
+ return {
266
+ scheduled: false,
267
+ reason: "Web fallback cannot schedule native background refresh tasks.",
268
+ };
269
+ }
270
+ async cancelBackgroundRefresh() {
271
+ return {
272
+ cancelled: false,
273
+ reason: "Web fallback has no native background refresh task to cancel.",
274
+ };
275
+ }
276
+ }
277
+
278
+ var web = /*#__PURE__*/Object.freeze({
279
+ __proto__: null,
280
+ MobileSignalsWeb: MobileSignalsWeb
281
+ });
282
+
283
+ exports.MobileSignals = MobileSignals;
284
+
285
+ return exports;
286
+
287
+ })({}, capacitorExports);
288
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nexport * from \"./definitions\";\nconst loadWeb = () => import(\"./web\").then((m) => new m.MobileSignalsWeb());\nexport const MobileSignals = registerPlugin(\"MobileSignals\", {\n web: loadWeb,\n});\n","import { WebPlugin } from \"@capacitor/core\";\nconst SCREEN_TIME_REQUIREMENTS = {\n entitlements: {\n familyControls: \"com.apple.developer.family-controls\",\n },\n frameworks: [\"FamilyControls\", \"DeviceActivity\"],\n deviceActivityReportExtension: false,\n deviceActivityMonitorExtension: false,\n android: {\n usageStatsPermission: \"android.permission.PACKAGE_USAGE_STATS\",\n usageAccessSettingsAction: \"android.settings.USAGE_ACCESS_SETTINGS\",\n },\n};\nfunction getPlatform() {\n if (typeof navigator === \"undefined\") {\n return \"web\";\n }\n const ua = navigator.userAgent.toLowerCase();\n if (ua.includes(\"android\"))\n return \"android\";\n if (ua.includes(\"iphone\") || ua.includes(\"ipad\") || ua.includes(\"ipod\")) {\n return \"ios\";\n }\n return \"web\";\n}\nfunction buildScreenTimeStatus(reason) {\n return {\n supported: false,\n requirements: SCREEN_TIME_REQUIREMENTS,\n entitlements: {\n familyControls: false,\n },\n provisioning: {\n satisfied: false,\n inspected: \"not-inspectable\",\n reason,\n },\n authorization: {\n status: \"unavailable\",\n canRequest: false,\n },\n reportAvailable: false,\n coarseSummaryAvailable: false,\n thresholdEventsAvailable: false,\n rawUsageExportAvailable: false,\n android: {\n usageAccessGranted: false,\n packageUsageStatsPermissionDeclared: false,\n canOpenUsageAccessSettings: false,\n foregroundEventsAvailable: false,\n totalTimeForegroundMs: null,\n },\n reason,\n };\n}\nfunction buildSetupActions(reason) {\n return [\n {\n id: \"health_permissions\",\n label: \"Health permissions\",\n status: \"unavailable\",\n canRequest: false,\n canOpenSettings: false,\n settingsTarget: null,\n reason,\n },\n {\n id: \"screen_time_authorization\",\n label: \"Screen Time\",\n status: \"unavailable\",\n canRequest: false,\n canOpenSettings: false,\n settingsTarget: null,\n reason: \"Web fallback cannot open native Screen Time settings.\",\n },\n ];\n}\nasync function getBatterySnapshot() {\n const nav = typeof navigator !== \"undefined\"\n ? navigator\n : null;\n if (!nav || typeof nav.getBattery !== \"function\") {\n return { onBattery: null, batteryLevel: null, isCharging: null };\n }\n const battery = await nav.getBattery();\n return {\n onBattery: !battery.charging,\n batteryLevel: typeof battery.level === \"number\"\n ? Math.max(0, Math.min(1, battery.level))\n : null,\n isCharging: battery.charging,\n };\n}\nasync function buildSnapshot(reason) {\n const isVisible = typeof document !== \"undefined\"\n ? document.visibilityState === \"visible\"\n : true;\n const hasFocus = typeof document !== \"undefined\" && typeof document.hasFocus === \"function\"\n ? document.hasFocus()\n : true;\n const battery = await getBatterySnapshot();\n const state = isVisible && hasFocus ? \"active\" : \"background\";\n const idleState = isVisible\n ? \"active\"\n : \"idle\";\n return {\n source: \"mobile_device\",\n platform: getPlatform(),\n state,\n observedAt: Date.now(),\n idleState,\n idleTimeSeconds: null,\n onBattery: battery.onBattery,\n metadata: {\n reason,\n visibilityState: typeof document !== \"undefined\" ? document.visibilityState : \"visible\",\n hasFocus,\n ...battery,\n },\n };\n}\nfunction buildHealthSnapshot(reason) {\n return {\n source: \"mobile_health\",\n platform: getPlatform(),\n state: \"idle\",\n observedAt: Date.now(),\n idleState: null,\n idleTimeSeconds: null,\n onBattery: null,\n healthSource: \"healthkit\",\n screenTime: buildScreenTimeStatus(\"Web fallback has no Family Controls or DeviceActivity access.\"),\n permissions: {\n sleep: false,\n biometrics: false,\n },\n sleep: {\n available: false,\n isSleeping: false,\n asleepAt: null,\n awakeAt: null,\n durationMinutes: null,\n stage: null,\n },\n biometrics: {\n sampleAt: null,\n heartRateBpm: null,\n restingHeartRateBpm: null,\n heartRateVariabilityMs: null,\n respiratoryRate: null,\n bloodOxygenPercent: null,\n },\n warnings: [`web fallback has no health access (${reason})`],\n metadata: {\n reason,\n platform: getPlatform(),\n supported: false,\n },\n };\n}\nexport class MobileSignalsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.monitoring = false;\n this.cleanup = [];\n this.emitSignal = async (reason) => {\n if (!this.monitoring)\n return;\n const snapshot = await buildSnapshot(reason);\n this.notifyListeners(\"signal\", snapshot);\n this.notifyListeners(\"signal\", buildHealthSnapshot(reason));\n };\n }\n async checkPermissions() {\n return {\n status: \"not-applicable\",\n canRequest: false,\n screenTime: buildScreenTimeStatus(\"Web fallback has no Family Controls or DeviceActivity access.\"),\n setupActions: buildSetupActions(\"Web fallback has no HealthKit or Health Connect access.\"),\n permissions: {\n sleep: false,\n biometrics: false,\n },\n reason: \"Web fallback has no HealthKit or Health Connect access.\",\n };\n }\n async requestPermissions() {\n return this.checkPermissions();\n }\n async openSettings(options = {}) {\n return {\n opened: false,\n target: options.target ?? \"app\",\n actualTarget: \"app\",\n reason: \"Web fallback cannot open native device settings.\",\n };\n }\n attachListeners() {\n if (typeof document !== \"undefined\") {\n const handleVisibilityChange = () => {\n void this.emitSignal(\"visibilitychange\");\n };\n document.addEventListener(\"visibilitychange\", handleVisibilityChange);\n this.cleanup.push(() => document.removeEventListener(\"visibilitychange\", handleVisibilityChange));\n }\n if (typeof window !== \"undefined\") {\n const handleFocus = () => {\n void this.emitSignal(\"focus\");\n };\n const handleBlur = () => {\n void this.emitSignal(\"blur\");\n };\n window.addEventListener(\"focus\", handleFocus);\n window.addEventListener(\"blur\", handleBlur);\n this.cleanup.push(() => window.removeEventListener(\"focus\", handleFocus));\n this.cleanup.push(() => window.removeEventListener(\"blur\", handleBlur));\n }\n }\n clearListeners() {\n while (this.cleanup.length > 0) {\n const cleanup = this.cleanup.pop();\n cleanup?.();\n }\n }\n async startMonitoring(options = {}) {\n if (!this.monitoring) {\n this.monitoring = true;\n this.attachListeners();\n }\n const snapshot = await buildSnapshot(\"start\");\n const healthSnapshot = buildHealthSnapshot(\"start\");\n if (options.emitInitial ?? true) {\n this.notifyListeners(\"signal\", snapshot);\n this.notifyListeners(\"signal\", healthSnapshot);\n }\n return {\n enabled: this.monitoring,\n supported: true,\n platform: snapshot.platform,\n snapshot,\n healthSnapshot,\n };\n }\n async stopMonitoring() {\n this.monitoring = false;\n this.clearListeners();\n return { stopped: true };\n }\n async getSnapshot() {\n const snapshot = await buildSnapshot(\"snapshot\");\n return {\n supported: true,\n snapshot,\n healthSnapshot: buildHealthSnapshot(\"snapshot\"),\n };\n }\n async scheduleBackgroundRefresh() {\n return {\n scheduled: false,\n reason: \"Web fallback cannot schedule native background refresh tasks.\",\n };\n }\n async cancelBackgroundRefresh() {\n return {\n cancelled: false,\n reason: \"Web fallback has no native background refresh task to cancel.\",\n };\n }\n}\nexport const __internal = {\n buildScreenTimeStatus,\n};\n"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAEA,MAAM,OAAO,GAAG,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC/D,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IAC7D,IAAI,GAAG,EAAE,OAAO;IAChB,CAAC;;ICJD,MAAM,wBAAwB,GAAG;IACjC,IAAI,YAAY,EAAE;IAClB,QAAQ,cAAc,EAAE,qCAAqC;IAC7D,KAAK;IACL,IAAI,UAAU,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IACpD,IAAI,6BAA6B,EAAE,KAAK;IACxC,IAAI,8BAA8B,EAAE,KAAK;IACzC,IAAI,OAAO,EAAE;IACb,QAAQ,oBAAoB,EAAE,wCAAwC;IACtE,QAAQ,yBAAyB,EAAE,wCAAwC;IAC3E,KAAK;IACL,CAAC;IACD,SAAS,WAAW,GAAG;IACvB,IAAI,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE;IAC1C,QAAQ,OAAO,KAAK;IACpB,IAAI;IACJ,IAAI,MAAM,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE;IAChD,IAAI,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;IAC9B,QAAQ,OAAO,SAAS;IACxB,IAAI,IAAI,EAAE,CAAC,QAAQ,CAAC,QAA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