@livx.cc/appwrap 0.28.1 → 0.28.2
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.
- package/package.json +1 -1
- package/runtime/app/shell/background-worker.android.ts +47 -0
- package/runtime/app/shell/background-worker.ios.ts +5 -0
- package/runtime/app/shell/background-worker.ts +7 -0
- package/runtime/app/shell/handlers-background.ts +10 -42
- package/templates/ci/github/workflows/appwrap-pr.yml +3 -3
- package/templates/ci/github/workflows/appwrap-release-android.yml +2 -2
- package/templates/ci/github/workflows/appwrap-release-ios.yml +2 -2
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Utils } from '@nativescript/core';
|
|
2
|
+
import { runHeadless, finishRun } from './handlers-background';
|
|
3
|
+
|
|
4
|
+
// androidx (WorkManager) isn't in @nativescript/types-android — it's an AndroidX library, not the
|
|
5
|
+
// platform SDK — so it stays `any`. `java` resolves from the SDK typings; `NativeClass`/`JavaProxy`
|
|
6
|
+
// are ambient NativeScript runtime globals.
|
|
7
|
+
declare const androidx: any;
|
|
8
|
+
declare const java: any;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WorkManager headless Worker — created by WorkManager on a background launch. `doWork()` posts to the
|
|
12
|
+
* MAIN looper (the WebView must be built + driven on the UI thread), runs the headless WebView loop for
|
|
13
|
+
* the input task id, and blocks the worker thread on a `CountDownLatch` until `backgroundTask.finish`
|
|
14
|
+
* (or a timeout). Returns success/failure; WorkManager handles periodic rescheduling.
|
|
15
|
+
*
|
|
16
|
+
* ANDROID-ONLY (`.android.ts`): a top-level `@JavaProxy` / `extends androidx.work.Worker` class
|
|
17
|
+
* dereferences Android-only globals at module load. In a SHARED file that evaluates on iOS too, that
|
|
18
|
+
* throws during ES-module instantiation → hard launch crash. Isolating it here keeps it off iOS.
|
|
19
|
+
* ⚠ DEVICE-UNVERIFIED — compiles only (see handlers-background.ts header).
|
|
20
|
+
*/
|
|
21
|
+
@NativeClass()
|
|
22
|
+
@JavaProxy('cc.livx.appwrap.AppwrapBackgroundWorker')
|
|
23
|
+
export class AppwrapBackgroundWorker extends androidx.work.Worker {
|
|
24
|
+
constructor(context: any, params: any) {
|
|
25
|
+
super(context, params);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
doWork(): any {
|
|
29
|
+
const id = this.getInputData().getString('appwrap.taskId') ?? '';
|
|
30
|
+
if (!id) return androidx.work.ListenableWorker.Result.failure();
|
|
31
|
+
|
|
32
|
+
const latch = new java.util.concurrent.CountDownLatch(1);
|
|
33
|
+
const result = { success: false };
|
|
34
|
+
Utils.dispatchToMainThread(() => {
|
|
35
|
+
runHeadless(id)
|
|
36
|
+
.then((ok: boolean) => { result.success = ok; latch.countDown(); })
|
|
37
|
+
.catch(() => { latch.countDown(); });
|
|
38
|
+
});
|
|
39
|
+
// Block the worker thread (bounded — below the WorkManager 10-min ceiling) until the JS handler
|
|
40
|
+
// finishes. A timeout returns failure so WorkManager retries on its schedule.
|
|
41
|
+
const completed = latch.await(9, java.util.concurrent.TimeUnit.MINUTES);
|
|
42
|
+
if (!completed) finishRun(id, false);
|
|
43
|
+
return completed && result.success
|
|
44
|
+
? androidx.work.ListenableWorker.Result.success()
|
|
45
|
+
: androidx.work.ListenableWorker.Result.failure();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// iOS stub. The WorkManager Worker is Android-only; handlers-background.ts STATICALLY imports
|
|
2
|
+
// `AppwrapBackgroundWorker`, so the name must resolve on iOS too — but it must carry NO `@JavaProxy` /
|
|
3
|
+
// `androidx` references (those are undefined on iOS and would crash ES-module instantiation at launch).
|
|
4
|
+
// registerAndroid() is the only consumer and never runs on iOS, so this value is never dereferenced.
|
|
5
|
+
export const AppwrapBackgroundWorker: any = undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Base / iOS module for `./background-worker`. The WorkManager Worker is Android-only; the real
|
|
2
|
+
// `@JavaProxy` class lives in `background-worker.android.ts` (NS resolves the `.android.ts` override on
|
|
3
|
+
// Android). This base resolves for plain `tsc` (which doesn't know NS platform suffixes) AND serves as
|
|
4
|
+
// the iOS runtime impl — it must carry NO `@JavaProxy` / `androidx` references (undefined on iOS, they'd
|
|
5
|
+
// crash ES-module instantiation at launch). registerAndroid() — the only consumer — never runs on iOS,
|
|
6
|
+
// so this value is never dereferenced there.
|
|
7
|
+
export const AppwrapBackgroundWorker: any = undefined;
|
|
@@ -3,6 +3,11 @@ import { bridge } from './bridge';
|
|
|
3
3
|
import { SHELL_CONFIG } from './config';
|
|
4
4
|
import { setPendingBackgroundTaskId } from './background-context';
|
|
5
5
|
import { CustomWebView } from './custom-webview';
|
|
6
|
+
// Android-only WorkManager Worker (@JavaProxy + `extends androidx.work.Worker`). Kept in a `.android.ts`
|
|
7
|
+
// file so it's NEVER evaluated on iOS — a top-level Android native class in a shared module dereferences
|
|
8
|
+
// `@JavaProxy`/`androidx` at module load, which are undefined on iOS → the whole ES module graph fails to
|
|
9
|
+
// instantiate → hard launch crash. iOS resolves the `.ios.ts` stub; registerAndroid() is the only user.
|
|
10
|
+
import { AppwrapBackgroundWorker } from './background-worker';
|
|
6
11
|
|
|
7
12
|
// BackgroundTasks (iOS), NSDate, and the `android`/`java` namespaces resolve from the full SDK
|
|
8
13
|
// (@nativescript/types-ios + types-android) — no declares needed.
|
|
@@ -58,7 +63,7 @@ const pendingRuns = new Map<string, PendingRun>();
|
|
|
58
63
|
/** Build an offscreen WebView, attach the bridge, and load the app so its handshake reports `id`. The
|
|
59
64
|
* returned promise resolves when the JS handler calls `backgroundTask.finish` (or `abort()` fires).
|
|
60
65
|
* REUSES `CustomWebView` (scheme handler + bridge injection) — no duplicated transport. */
|
|
61
|
-
function runHeadless(id: string): Promise<boolean> {
|
|
66
|
+
export function runHeadless(id: string): Promise<boolean> {
|
|
62
67
|
return new Promise<boolean>((resolve) => {
|
|
63
68
|
setPendingBackgroundTaskId(id); // the next handshake reports this wake id
|
|
64
69
|
const webView = new CustomWebView();
|
|
@@ -109,7 +114,7 @@ function loadAppInto(webView: CustomWebView, id: string, attempt = 0): void {
|
|
|
109
114
|
|
|
110
115
|
/** Resolve an in-flight headless run (called by `backgroundTask.finish`, the safety abort, or a load
|
|
111
116
|
* failure). Tears the offscreen WebView's bridge attachment down. Idempotent. */
|
|
112
|
-
function finishRun(id: string, success: boolean): void {
|
|
117
|
+
export function finishRun(id: string, success: boolean): void {
|
|
113
118
|
const run = pendingRuns.get(id);
|
|
114
119
|
if (!run) return;
|
|
115
120
|
pendingRuns.delete(id);
|
|
@@ -222,7 +227,7 @@ function registerAndroid(): void {
|
|
|
222
227
|
// WorkManager periodic floor is 15 min; clamp a smaller hint up so enqueue doesn't reject it.
|
|
223
228
|
const ms = Math.max(15 * 60_000, Number(p?.minIntervalMs ?? 15 * 60_000));
|
|
224
229
|
const builder = new androidx.work.PeriodicWorkRequest.Builder(
|
|
225
|
-
AppwrapBackgroundWorker.class,
|
|
230
|
+
(AppwrapBackgroundWorker as any).class,
|
|
226
231
|
ms, java.util.concurrent.TimeUnit.MILLISECONDS
|
|
227
232
|
);
|
|
228
233
|
// The id rides as input data → the Worker reads it to drive the matching JS handler.
|
|
@@ -249,42 +254,5 @@ function registerAndroid(): void {
|
|
|
249
254
|
});
|
|
250
255
|
}
|
|
251
256
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
* MAIN looper (the WebView must be built + driven on the UI thread), runs the headless WebView loop for
|
|
255
|
-
* the input task id, and blocks the worker thread on a `CountDownLatch` until `backgroundTask.finish`
|
|
256
|
-
* (or a timeout). Returns success/failure; WorkManager handles periodic rescheduling.
|
|
257
|
-
*
|
|
258
|
-
* ⚠ DEVICE-UNVERIFIED — compiles only (see the file header).
|
|
259
|
-
*/
|
|
260
|
-
@NativeClass()
|
|
261
|
-
@JavaProxy('cc.livx.appwrap.AppwrapBackgroundWorker')
|
|
262
|
-
export class AppwrapBackgroundWorker extends androidx.work.Worker {
|
|
263
|
-
constructor(context: any, params: any) {
|
|
264
|
-
super(context, params);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
doWork(): any {
|
|
268
|
-
const id = this.getInputData().getString('appwrap.taskId') ?? '';
|
|
269
|
-
if (!id) return androidx.work.ListenableWorker.Result.failure();
|
|
270
|
-
|
|
271
|
-
const latch = new java.util.concurrent.CountDownLatch(1);
|
|
272
|
-
const result = { success: false };
|
|
273
|
-
Utils.dispatchToMainThread(() => {
|
|
274
|
-
runHeadless(id)
|
|
275
|
-
.then((ok: boolean) => { result.success = ok; latch.countDown(); })
|
|
276
|
-
.catch(() => { latch.countDown(); });
|
|
277
|
-
});
|
|
278
|
-
// Block the worker thread (bounded — below the WorkManager 10-min ceiling) until the JS handler
|
|
279
|
-
// finishes. A timeout returns failure so WorkManager retries on its schedule.
|
|
280
|
-
const completed = latch.await(9, java.util.concurrent.TimeUnit.MINUTES);
|
|
281
|
-
if (!completed) finishRun(id, false);
|
|
282
|
-
return completed && result.success
|
|
283
|
-
? androidx.work.ListenableWorker.Result.success()
|
|
284
|
-
: androidx.work.ListenableWorker.Result.failure();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Reference the Worker class so the bundler/NS metadata retains the JavaProxy (mirrors how the FCM
|
|
289
|
-
// service is kept alive via its import side-effect). Without a reference the class can be tree-shaken.
|
|
290
|
-
void AppwrapBackgroundWorker;
|
|
257
|
+
// The WorkManager headless Worker (@JavaProxy `AppwrapBackgroundWorker`) lives in
|
|
258
|
+
// `background-worker.android.ts` — see the import at the top of this file for WHY it can't be here.
|
|
@@ -7,7 +7,7 @@ jobs:
|
|
|
7
7
|
web:
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
|
-
- uses: actions/checkout@
|
|
10
|
+
- uses: actions/checkout@v5
|
|
11
11
|
- uses: oven-sh/setup-bun@v2
|
|
12
12
|
- run: bun install
|
|
13
13
|
- run: bun test || echo "no tests"
|
|
@@ -17,9 +17,9 @@ jobs:
|
|
|
17
17
|
runs-on: macos-15
|
|
18
18
|
needs: web
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v5
|
|
21
21
|
- uses: oven-sh/setup-bun@v2
|
|
22
|
-
- uses: actions/setup-node@
|
|
22
|
+
- uses: actions/setup-node@v5
|
|
23
23
|
with: { node-version: 22 }
|
|
24
24
|
- run: bun install && bun run build
|
|
25
25
|
# Pin global tools — unpinned installs can grab a breaking release mid-flight. Bump deliberately.
|
|
@@ -22,9 +22,9 @@ jobs:
|
|
|
22
22
|
play:
|
|
23
23
|
runs-on: ubuntu-latest
|
|
24
24
|
steps:
|
|
25
|
-
- uses: actions/checkout@
|
|
25
|
+
- uses: actions/checkout@v5
|
|
26
26
|
- uses: oven-sh/setup-bun@v2
|
|
27
|
-
- uses: actions/setup-node@
|
|
27
|
+
- uses: actions/setup-node@v5
|
|
28
28
|
with: { node-version: 22 }
|
|
29
29
|
- uses: actions/setup-java@v4
|
|
30
30
|
with: { distribution: temurin, java-version: 17 }
|
|
@@ -24,12 +24,12 @@ jobs:
|
|
|
24
24
|
testflight:
|
|
25
25
|
runs-on: macos-15
|
|
26
26
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
27
|
+
- uses: actions/checkout@v5
|
|
28
28
|
# Apple requires the iOS 26 SDK (Xcode 26+) for uploads — runners may default to older Xcode.
|
|
29
29
|
- uses: maxim-lobanov/setup-xcode@v1
|
|
30
30
|
with: { xcode-version: latest-stable }
|
|
31
31
|
- uses: oven-sh/setup-bun@v2
|
|
32
|
-
- uses: actions/setup-node@
|
|
32
|
+
- uses: actions/setup-node@v5
|
|
33
33
|
with: { node-version: 22 }
|
|
34
34
|
- run: bun install && bun run build
|
|
35
35
|
# Pin global tools — unpinned installs can grab a breaking release mid-flight. Bump deliberately.
|