@threenative/runtime-native 0.3.3 → 0.3.4
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/android/app/src/main/java/com/mystral/engine/MystralActivity.java +35 -1
- package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +170 -8
- package/package.json +4 -2
- package/scripts/asset-manifest.mjs +38 -19
- package/scripts/inspect-macos-icon.mjs +169 -0
- package/scripts/install-prebuilt.mjs +6 -3
- package/scripts/package-android.mjs +1 -1
- package/scripts/package-desktop.mjs +1 -1
- package/scripts/package-ios.mjs +30 -31
- package/scripts/physical-device-evidence.mjs +135 -1
- package/scripts/production-evidence.mjs +36 -9
- package/scripts/profile-production.mjs +633 -138
- package/scripts/qualify-physical-mobile.mjs +286 -69
- package/scripts/verify-starter-consumer.mjs +58 -8
- package/scripts/verify-starter-desktop-base.mjs +12 -2
|
@@ -8,6 +8,7 @@ import android.os.Build;
|
|
|
8
8
|
import android.os.Bundle;
|
|
9
9
|
import android.util.Log;
|
|
10
10
|
import android.view.Choreographer;
|
|
11
|
+
import android.view.MotionEvent;
|
|
11
12
|
import android.view.Surface;
|
|
12
13
|
import android.view.SurfaceHolder;
|
|
13
14
|
import android.view.View;
|
|
@@ -135,6 +136,7 @@ public class MystralActivity extends SDLActivity {
|
|
|
135
136
|
// Belt and braces: a callback left registered when the native library unloads would call
|
|
136
137
|
// into freed code. onPause normally precedes this, so the guard makes it a no-op.
|
|
137
138
|
disarmPresentationFrames();
|
|
139
|
+
if (uiOverlay != null) uiOverlay.releaseProducer();
|
|
138
140
|
super.onDestroy();
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -208,7 +210,39 @@ public class MystralActivity extends SDLActivity {
|
|
|
208
210
|
private void attachUiOverlay(Bundle metadata) {
|
|
209
211
|
String renderer = metadata == null ? "native" : metadata.getString("TN_UI_RENDERER", "native");
|
|
210
212
|
if (!"web".equals(renderer)) return;
|
|
211
|
-
uiOverlay =
|
|
213
|
+
uiOverlay = inFrameRequested(metadata)
|
|
214
|
+
? TnUiOverlay.attachInFrame(this)
|
|
215
|
+
: TnUiOverlay.attach(this);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Whether this run opts into in-frame UI composition (`TN_UI_INFRAME`), default off.
|
|
220
|
+
*
|
|
221
|
+
* The intent extra is the device-run override the verification harness uses; the manifest
|
|
222
|
+
* metadata is the packaged switch the config writes. Both default false, so a game that did
|
|
223
|
+
* not ask for it runs exactly today's child-WebView path.
|
|
224
|
+
*/
|
|
225
|
+
private boolean inFrameRequested(Bundle metadata) {
|
|
226
|
+
boolean fromIntent = getIntent().getBooleanExtra("TN_UI_INFRAME", false);
|
|
227
|
+
boolean fromMetadata = metadata != null && metadata.getBoolean("TN_UI_INFRAME", false);
|
|
228
|
+
Log.i(LOG_TAG, "TN_UI_INFRAME_REQUEST:{\"intent\":" + fromIntent
|
|
229
|
+
+ ",\"metadata\":" + fromMetadata + "}");
|
|
230
|
+
if (fromIntent) return true;
|
|
231
|
+
return fromMetadata;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Keep the overlay's own hit test authoritative when it composites in-frame.
|
|
236
|
+
*
|
|
237
|
+
* The in-frame WebView is not a sibling view, so the system will not route touches to it. This
|
|
238
|
+
* forwards each gesture to the same WebView first — its published hit regions decide ownership,
|
|
239
|
+
* exactly as before — and only what it does not own reaches SDL and the game.
|
|
240
|
+
*/
|
|
241
|
+
@Override
|
|
242
|
+
public boolean dispatchTouchEvent(MotionEvent event) {
|
|
243
|
+
TnUiOverlay overlay = uiOverlay;
|
|
244
|
+
if (overlay != null && overlay.isInFrame() && overlay.dispatchTouchEvent(event)) return true;
|
|
245
|
+
return super.dispatchTouchEvent(event);
|
|
212
246
|
}
|
|
213
247
|
|
|
214
248
|
/**
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
package com.threenative.runtime;
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
|
+
import android.app.Presentation;
|
|
4
5
|
import android.graphics.Color;
|
|
6
|
+
import android.graphics.PixelFormat;
|
|
7
|
+
import android.hardware.HardwareBuffer;
|
|
8
|
+
import android.hardware.display.DisplayManager;
|
|
9
|
+
import android.hardware.display.VirtualDisplay;
|
|
10
|
+
import android.media.Image;
|
|
11
|
+
import android.media.ImageReader;
|
|
12
|
+
import android.os.Handler;
|
|
13
|
+
import android.os.HandlerThread;
|
|
14
|
+
import android.util.DisplayMetrics;
|
|
15
|
+
import android.view.Display;
|
|
5
16
|
import android.view.MotionEvent;
|
|
6
17
|
import android.view.View;
|
|
7
18
|
import android.view.ViewGroup;
|
|
@@ -73,6 +84,18 @@ public final class TnUiOverlay extends WebView {
|
|
|
73
84
|
|
|
74
85
|
private static native void nativeUiOverlayAttached(boolean attached);
|
|
75
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Publish one produced page frame to the native composite.
|
|
89
|
+
*
|
|
90
|
+
* `pixels` is the producer's direct `ImageReader` plane buffer; native copies it before this
|
|
91
|
+
* call returns, so the image can be closed immediately. `stride` is the row stride in bytes.
|
|
92
|
+
*/
|
|
93
|
+
private static native void nativeUiFrame(java.nio.ByteBuffer pixels, int width, int height,
|
|
94
|
+
int stride);
|
|
95
|
+
|
|
96
|
+
/** Name the composite path this run took: `in-frame-cpu` or `child-window`. */
|
|
97
|
+
private static native void nativeUiCompositePath(String path);
|
|
98
|
+
|
|
76
99
|
/**
|
|
77
100
|
* The published islands, flat as x, y, width, height per region, normalized to the viewport.
|
|
78
101
|
* Written by the message listener and read by touch dispatch, both on the UI thread; the
|
|
@@ -85,6 +108,19 @@ public final class TnUiOverlay extends WebView {
|
|
|
85
108
|
private String pendingFrame;
|
|
86
109
|
private boolean ownsGesture;
|
|
87
110
|
|
|
111
|
+
/**
|
|
112
|
+
* True when this overlay produces its pixels off-screen for the native composite instead of
|
|
113
|
+
* being a transparent sibling SurfaceFlinger layer. Selected by {@code TN_UI_INFRAME}.
|
|
114
|
+
*/
|
|
115
|
+
private boolean inFrame;
|
|
116
|
+
|
|
117
|
+
private ImageReader frameReader;
|
|
118
|
+
private VirtualDisplay frameDisplay;
|
|
119
|
+
private Presentation framePresentation;
|
|
120
|
+
private HandlerThread frameThread;
|
|
121
|
+
private Handler frameHandler;
|
|
122
|
+
private long frameCounter;
|
|
123
|
+
|
|
88
124
|
private TnUiOverlay(Activity activity) {
|
|
89
125
|
super(activity);
|
|
90
126
|
}
|
|
@@ -97,6 +133,38 @@ public final class TnUiOverlay extends WebView {
|
|
|
97
133
|
* game whose HUD code is broken.
|
|
98
134
|
*/
|
|
99
135
|
public static TnUiOverlay attach(Activity activity) {
|
|
136
|
+
requireMessageListener();
|
|
137
|
+
TnUiOverlay overlay = new TnUiOverlay(activity);
|
|
138
|
+
nativeUiOverlayAttached(false);
|
|
139
|
+
overlay.configure(activity);
|
|
140
|
+
activity.addContentView(
|
|
141
|
+
overlay,
|
|
142
|
+
new ViewGroup.LayoutParams(
|
|
143
|
+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
144
|
+
nativeUiCompositePath("child-window");
|
|
145
|
+
return overlay;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Build the overlay as an off-screen producer for the in-frame composite (`TN_UI_INFRAME`).
|
|
150
|
+
*
|
|
151
|
+
* The same WebView and the same bridge, but its pixels are produced into an `ImageReader`
|
|
152
|
+
* surface through a {@code VirtualDisplay}/{@code Presentation} instead of being composited as
|
|
153
|
+
* its own SurfaceFlinger layer, and each produced frame is handed to native. This is the
|
|
154
|
+
* Android counterpart of Linux's off-screen web view, and it is opt-in: the child-window path
|
|
155
|
+
* above is exactly what it was.
|
|
156
|
+
*/
|
|
157
|
+
public static TnUiOverlay attachInFrame(Activity activity) {
|
|
158
|
+
requireMessageListener();
|
|
159
|
+
TnUiOverlay overlay = new TnUiOverlay(activity);
|
|
160
|
+
overlay.inFrame = true;
|
|
161
|
+
nativeUiOverlayAttached(false);
|
|
162
|
+
overlay.configure(activity);
|
|
163
|
+
overlay.startProducer(activity);
|
|
164
|
+
return overlay;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private static void requireMessageListener() {
|
|
100
168
|
if (!WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
|
|
101
169
|
nativeUiOverlayAttached(false);
|
|
102
170
|
throw new IllegalStateException(
|
|
@@ -104,21 +172,115 @@ public final class TnUiOverlay extends WebView {
|
|
|
104
172
|
+ " UI layer has no bridge. Update Android System WebView, or build with"
|
|
105
173
|
+ " ui.renderer = \"native\".");
|
|
106
174
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Put the page on a display whose surface this host owns, and pump its frames to native.
|
|
179
|
+
*
|
|
180
|
+
* Fails closed and by name: an in-frame run that cannot build its surface must not leave the
|
|
181
|
+
* game with a silent black HUD. The reader uses {@code RGBA_8888} with
|
|
182
|
+
* {@code USAGE_GPU_SAMPLED_IMAGE} — the usage the GPU import will need once wgpu-native can
|
|
183
|
+
* import an {@code AHardwareBuffer}; the CPU readback now is the same buffer read back.
|
|
184
|
+
*/
|
|
185
|
+
private void startProducer(Activity activity) {
|
|
186
|
+
// The usage-parameter ImageReader and HardwareBuffer import are API 29; on anything older
|
|
187
|
+
// this fails closed and by name rather than silently dropping to the child-window path.
|
|
188
|
+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
|
|
189
|
+
throw new IllegalStateException(
|
|
190
|
+
"TN_UI_INFRAME_UNSUPPORTED: in-frame composition needs API 29 (this device is "
|
|
191
|
+
+ android.os.Build.VERSION.SDK_INT + ").");
|
|
192
|
+
}
|
|
193
|
+
DisplayManager displayManager = (DisplayManager) activity.getSystemService(
|
|
194
|
+
Activity.DISPLAY_SERVICE);
|
|
195
|
+
if (displayManager == null) {
|
|
196
|
+
throw new IllegalStateException("TN_UI_INFRAME_UNSUPPORTED: no DisplayManager.");
|
|
197
|
+
}
|
|
198
|
+
DisplayMetrics metrics = new DisplayMetrics();
|
|
199
|
+
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
|
200
|
+
final int width = metrics.widthPixels;
|
|
201
|
+
final int height = metrics.heightPixels;
|
|
202
|
+
frameThread = new HandlerThread("tn-ui-frame");
|
|
203
|
+
frameThread.start();
|
|
204
|
+
frameHandler = new Handler(frameThread.getLooper());
|
|
205
|
+
frameReader = ImageReader.newInstance(
|
|
206
|
+
width,
|
|
207
|
+
height,
|
|
208
|
+
PixelFormat.RGBA_8888,
|
|
209
|
+
2,
|
|
210
|
+
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE | HardwareBuffer.USAGE_CPU_READ_OFTEN);
|
|
211
|
+
frameReader.setOnImageAvailableListener(this::onFrameAvailable, frameHandler);
|
|
212
|
+
frameDisplay = displayManager.createVirtualDisplay(
|
|
213
|
+
"tn-ui-inframe", width, height, metrics.densityDpi, frameReader.getSurface(), 0);
|
|
214
|
+
if (frameDisplay == null) {
|
|
215
|
+
throw new IllegalStateException("TN_UI_INFRAME_UNSUPPORTED: no virtual display.");
|
|
216
|
+
}
|
|
217
|
+
framePresentation = new Presentation(activity, frameDisplay.getDisplay());
|
|
218
|
+
framePresentation.setContentView(
|
|
219
|
+
this,
|
|
112
220
|
new ViewGroup.LayoutParams(
|
|
113
221
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
114
|
-
|
|
222
|
+
framePresentation.show();
|
|
223
|
+
// wgpu-native, the default Android lane, has no external-texture import, so the produced
|
|
224
|
+
// buffer is read back to CPU and uploaded by the existing composite. Report the path by
|
|
225
|
+
// name rather than letting a reader infer it. Cost measured at ~1.1 ms/frame on the Pixel 8.
|
|
226
|
+
nativeUiCompositePath("in-frame-cpu");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Hand each produced frame to native, synchronously; the image can close on return. */
|
|
230
|
+
private void onFrameAvailable(ImageReader reader) {
|
|
231
|
+
Image image = null;
|
|
232
|
+
try {
|
|
233
|
+
image = reader.acquireLatestImage();
|
|
234
|
+
if (image == null) return;
|
|
235
|
+
Image.Plane plane = image.getPlanes()[0];
|
|
236
|
+
java.nio.ByteBuffer pixels = plane.getBuffer();
|
|
237
|
+
pixels.position(0);
|
|
238
|
+
frameCounter += 1;
|
|
239
|
+
if (frameCounter == 1) {
|
|
240
|
+
android.util.Log.i("Mystral", "TN_UI_INFRAME_FIRST_FRAME:{\"width\":" + image.getWidth()
|
|
241
|
+
+ ",\"height\":" + image.getHeight() + ",\"stride\":" + plane.getRowStride() + "}");
|
|
242
|
+
}
|
|
243
|
+
nativeUiFrame(pixels, image.getWidth(), image.getHeight(), plane.getRowStride());
|
|
244
|
+
} catch (Throwable error) {
|
|
245
|
+
android.util.Log.w("Mystral",
|
|
246
|
+
"TN_UI_INFRAME_FRAME:{\"error\":\"" + error.getClass().getSimpleName() + "\"}");
|
|
247
|
+
} finally {
|
|
248
|
+
if (image != null) image.close();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Whether this overlay composites in-frame. The activity routes touches on when it does. */
|
|
253
|
+
public boolean isInFrame() {
|
|
254
|
+
return inFrame;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Release the off-screen producer. Safe on the child-window path and when nothing started. */
|
|
258
|
+
public void releaseProducer() {
|
|
259
|
+
if (!inFrame) return;
|
|
260
|
+
if (framePresentation != null) {
|
|
261
|
+
framePresentation.dismiss();
|
|
262
|
+
framePresentation = null;
|
|
263
|
+
}
|
|
264
|
+
if (frameDisplay != null) {
|
|
265
|
+
frameDisplay.release();
|
|
266
|
+
frameDisplay = null;
|
|
267
|
+
}
|
|
268
|
+
if (frameReader != null) {
|
|
269
|
+
frameReader.close();
|
|
270
|
+
frameReader = null;
|
|
271
|
+
}
|
|
272
|
+
if (frameThread != null) {
|
|
273
|
+
frameThread.quitSafely();
|
|
274
|
+
frameThread = null;
|
|
275
|
+
}
|
|
115
276
|
}
|
|
116
277
|
|
|
117
278
|
private void configure(Activity activity) {
|
|
118
279
|
setBackgroundColor(Color.TRANSPARENT);
|
|
119
280
|
// A hardware layer is what lets SurfaceFlinger promote this view to an overlay plane
|
|
120
|
-
// instead of compositing it on the GPU the game is already saturating.
|
|
121
|
-
|
|
281
|
+
// instead of compositing it on the GPU the game is already saturating. In-frame the view
|
|
282
|
+
// is not a layer at all; it draws into the producer's surface, so the layer is left alone.
|
|
283
|
+
if (!inFrame) setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
122
284
|
getSettings().setJavaScriptEnabled(true);
|
|
123
285
|
getSettings().setDomStorageEnabled(true);
|
|
124
286
|
// The UI is a local bundle; nothing in it should be able to reach the network.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threenative/runtime-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "ThreeNative-owned native host for desktop and Android",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"threenative",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"scripts/windows-installer.nsi",
|
|
53
53
|
"scripts/device-preflight.mjs",
|
|
54
54
|
"scripts/inspect-container-brand.mjs",
|
|
55
|
+
"scripts/inspect-macos-icon.mjs",
|
|
55
56
|
"scripts/install-prebuilt.mjs",
|
|
56
57
|
"scripts/package-android.mjs",
|
|
57
58
|
"scripts/package-desktop.mjs",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"publint": "0.3.22",
|
|
72
73
|
"three": "0.185.1",
|
|
73
74
|
"vitest": "4.1.10",
|
|
74
|
-
"@threenative/playtest": "0.3.
|
|
75
|
+
"@threenative/playtest": "0.3.4"
|
|
75
76
|
},
|
|
76
77
|
"dependencies": {
|
|
77
78
|
"pngjs": "7.0.0"
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"native:physics:parity:device": "node scripts/verify-android-physics-parity.mjs",
|
|
92
93
|
"native:qualify:physical": "node scripts/qualify-physical-mobile.mjs",
|
|
93
94
|
"native:verify:desktop": "node scripts/verify-desktop-audio.mjs && node scripts/verify-desktop-stability.mjs && node scripts/verify-desktop-core.mjs && node scripts/verify-desktop-physics.mjs && sh ../../scripts/xvfb.sh node scripts/verify-native-contracts.mjs && pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs && sh ../../scripts/xvfb.sh node scripts/verify-desktop-ui-frame.mjs && vitest run --config vitest.config.ts tests/external-bundle-discovery.test.mjs",
|
|
95
|
+
"native:verify:metahuman": "node scripts/verify-desktop-metahuman.mjs",
|
|
94
96
|
"native:verify:loading": "pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-loading.mjs",
|
|
95
97
|
"native:verify:ui-frame": "pnpm --dir ../playtest build && sh ../../scripts/xvfb.sh node scripts/verify-desktop-ui-frame.mjs",
|
|
96
98
|
"native:verify:android:multitouch": "pnpm --dir ../playtest build && node scripts/verify-android-multitouch.mjs",
|
|
@@ -8,21 +8,27 @@
|
|
|
8
8
|
* including `audio/*.ogg`, fps-framework's 100 `.glb`/`.jpg`, lumen-hall's and menu-spike's
|
|
9
9
|
* `basis/basis_transcoder.*`. Dropping those breaks KTX2 on native.
|
|
10
10
|
*
|
|
11
|
-
* So the rule is inverted:
|
|
11
|
+
* So the rule is inverted: keep everything EXCEPT what is provably not shipped, and print every skip.
|
|
12
12
|
*
|
|
13
13
|
* 1. Editor and VCS leftovers anywhere in the tree, by basename — `*.orig`, `*.rej`, `*.bak`,
|
|
14
14
|
* `*.swp`, `*~`, `.DS_Store`, `Thumbs.db`, `.gitkeep`.
|
|
15
|
-
* 2.
|
|
16
|
-
* manifest
|
|
17
|
-
*
|
|
15
|
+
* 2. Digest outputs, only when a manifest is present: any `<stem>.<8 hex>.<ext>` the current
|
|
16
|
+
* manifest and receipt do not name. That is the compiler's own naming space, so a file wearing
|
|
17
|
+
* it is a cook output — and one this cook did not emit is a leftover of a previous one, whose
|
|
18
|
+
* bytes no game loads. It is reported with the file it would have replaced when a same-stem,
|
|
19
|
+
* same-extension sibling does exist.
|
|
18
20
|
* 3. Everything else, including hand-placed files and the bookkeeping the runtime needs
|
|
19
21
|
* (the manifest and the bake receipt both ship, as they did before this rule).
|
|
20
22
|
*
|
|
21
23
|
* A file the manifest names but disk lacks fails closed with `TN_ASSETS_MANIFEST_MISSING`. With
|
|
22
24
|
* no manifest, rule 1 still applies and rule 2 does not.
|
|
25
|
+
*
|
|
26
|
+
* One selector, every target: the three native packagers stage through this function, and
|
|
27
|
+
* `threenative build --target web` deletes the `dropped` set from the Vite outDir, which copies
|
|
28
|
+
* the whole output root.
|
|
23
29
|
*/
|
|
24
30
|
|
|
25
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
31
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
26
32
|
import { basename, dirname, join, posix } from "node:path";
|
|
27
33
|
|
|
28
34
|
export const ASSET_MANIFEST_NAME = "assets.manifest.json";
|
|
@@ -105,8 +111,7 @@ function digestParts(file) {
|
|
|
105
111
|
* The manifest-named path that supersedes `file`, or `null` when nothing does.
|
|
106
112
|
*
|
|
107
113
|
* Only a same-directory named file with the same `<stem>` and `<ext>` but a different hash
|
|
108
|
-
* supersedes;
|
|
109
|
-
* hand-placed rather than an older output.
|
|
114
|
+
* supersedes; the answer is only used to name the replacement in the skip line.
|
|
110
115
|
*/
|
|
111
116
|
function supersededBy(file, named) {
|
|
112
117
|
const digest = digestParts(file);
|
|
@@ -121,12 +126,9 @@ function supersededBy(file, named) {
|
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* digest output superseded by a differently-hashed sibling is skipped and printed with
|
|
128
|
-
* `(superseded by <path>)`, and a file the manifest named but disk lacks fails closed with
|
|
129
|
-
* `TN_ASSETS_MANIFEST_MISSING`. Without a manifest only the editor rule applies.
|
|
129
|
+
* What one packaging run stages: the files to copy, the files it dropped, and how many of the
|
|
130
|
+
* kept ones no manifest or receipt declared — a hand-placed runtime file, which is legitimate
|
|
131
|
+
* and is reported so the number is never a surprise inside an APK.
|
|
130
132
|
*/
|
|
131
133
|
export function selectManifestAssets(assets, { log = console.log } = {}) {
|
|
132
134
|
const manifestPath = join(assets, ASSET_MANIFEST_NAME);
|
|
@@ -168,6 +170,8 @@ export function selectManifestAssets(assets, { log = console.log } = {}) {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
const selected = [];
|
|
173
|
+
const dropped = [];
|
|
174
|
+
const unmanaged = [];
|
|
171
175
|
for (const file of present) {
|
|
172
176
|
if (hasManifest && named.has(file)) {
|
|
173
177
|
selected.push(file);
|
|
@@ -175,16 +179,31 @@ export function selectManifestAssets(assets, { log = console.log } = {}) {
|
|
|
175
179
|
}
|
|
176
180
|
if (isEditorLeftover(file)) {
|
|
177
181
|
log(`ThreeNative packaging: skipped ${file} (editor leftover)`);
|
|
182
|
+
dropped.push(file);
|
|
178
183
|
continue;
|
|
179
184
|
}
|
|
180
|
-
if (hasManifest) {
|
|
185
|
+
if (hasManifest && digestParts(file) !== null) {
|
|
181
186
|
const superseding = supersededBy(file, named);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
log(
|
|
188
|
+
`ThreeNative packaging: skipped ${file} (cook output this build does not declare${
|
|
189
|
+
superseding === null ? "" : `, superseded by ${superseding}`
|
|
190
|
+
})`,
|
|
191
|
+
);
|
|
192
|
+
dropped.push(file);
|
|
193
|
+
continue;
|
|
186
194
|
}
|
|
187
195
|
selected.push(file);
|
|
196
|
+
if (!named.has(file)) unmanaged.push(file);
|
|
197
|
+
}
|
|
198
|
+
// Only a project with a manifest can be unmanaged relative to one; without it, the whole
|
|
199
|
+
// directory is hand-placed by definition and the line would name every file in the game.
|
|
200
|
+
if (hasManifest && unmanaged.length > 0) {
|
|
201
|
+
const bytes = unmanaged.reduce((total, file) => total + statSync(join(assets, file)).size, 0);
|
|
202
|
+
log(
|
|
203
|
+
`ThreeNative packaging: ${unmanaged.length} unmanaged file(s), ${bytes} bytes, are not declared by ${ASSET_MANIFEST_NAME}.`,
|
|
204
|
+
);
|
|
205
|
+
return { dropped, selected, unmanagedBytes: bytes, unmanagedFiles: unmanaged.length };
|
|
188
206
|
}
|
|
189
|
-
return selected;
|
|
207
|
+
return { dropped, selected, unmanagedBytes: 0, unmanagedFiles: 0 };
|
|
190
208
|
}
|
|
209
|
+
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import {
|
|
4
|
+
lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync,
|
|
5
|
+
} from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { PNG } from 'pngjs';
|
|
9
|
+
|
|
10
|
+
const INVALID = 'TN_NATIVE_STARTER_CONTAINER_MACOS_ICON_INVALID';
|
|
11
|
+
const MISMATCH = 'TN_NATIVE_STARTER_CONTAINER_ICON_MISMATCH';
|
|
12
|
+
const PNG_SIGNATURE = Buffer.from('89504e470d0a1a0a', 'hex');
|
|
13
|
+
const GENERATED_NAMES = [16, 32, 128, 256, 512].flatMap((size) => [
|
|
14
|
+
`icon_${size}x${size}.png`, `icon_${size}x${size}@2x.png`,
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function assertIcns(bytes) {
|
|
18
|
+
if (bytes.length < 16 || bytes.toString('ascii', 0, 4) !== 'icns' ||
|
|
19
|
+
bytes.readUInt32BE(4) !== bytes.length) {
|
|
20
|
+
throw new Error(`${INVALID}: the packaged icon is not a complete, nonempty ICNS file.`);
|
|
21
|
+
}
|
|
22
|
+
for (let offset = 8; offset < bytes.length;) {
|
|
23
|
+
if (offset + 8 > bytes.length) throw new Error(`${INVALID}: truncated ICNS element.`);
|
|
24
|
+
const size = bytes.readUInt32BE(offset + 4);
|
|
25
|
+
if (size <= 8 || size > bytes.length - offset) {
|
|
26
|
+
throw new Error(`${INVALID}: invalid ICNS element length.`);
|
|
27
|
+
}
|
|
28
|
+
offset += size;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function iconTool(run, command, args) {
|
|
33
|
+
const result = run(command, args, { encoding: 'utf8', timeout: 30_000, maxBuffer: 1024 * 1024 });
|
|
34
|
+
if (result.error || result.status !== 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`${INVALID}: ${command} could not inspect the icon (${result.error?.message ?? result.status ?? 'no exit status'}). Run the brand verifier on macOS with iconutil and sips available; metadata alone is not icon proof.`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function pngImage(path, pixels) {
|
|
42
|
+
const bytes = readFileSync(path);
|
|
43
|
+
// Bound the decoder by the representation's dimensions, not by untrusted IHDR allocation sizes.
|
|
44
|
+
if (bytes.length < 33 || bytes.length > 32 * 1024 * 1024 ||
|
|
45
|
+
!bytes.subarray(0, 8).equals(PNG_SIGNATURE) || bytes.readUInt32BE(8) !== 13 ||
|
|
46
|
+
bytes.toString('ascii', 12, 16) !== 'IHDR' ||
|
|
47
|
+
bytes.readUInt32BE(16) !== pixels || bytes.readUInt32BE(20) !== pixels) {
|
|
48
|
+
throw new Error(`${INVALID}: ${path} is not a ${pixels}x${pixels} PNG representation.`);
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return PNG.sync.read(bytes);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new Error(`${INVALID}: cannot decode ${path}: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Compare decoded RGBA, never PNG encoding, ancillary metadata, or a source-hash assertion. */
|
|
58
|
+
export function assertIconPixels(actual, expected, name) {
|
|
59
|
+
for (const image of [actual, expected]) {
|
|
60
|
+
if (!image || !Number.isInteger(image.width) || !Number.isInteger(image.height) ||
|
|
61
|
+
image.width < 1 || image.width > 1024 || image.height < 1 || image.height > 1024 ||
|
|
62
|
+
!Buffer.isBuffer(image.data) || image.data.length !== image.width * image.height * 4) {
|
|
63
|
+
throw new Error(`${INVALID}: ${name} has no complete decoded RGBA image.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (actual.width !== expected.width || actual.height !== expected.height) {
|
|
67
|
+
throw new Error(`${MISMATCH}: decoded macOS icon ${name} dimensions differ from app.icon.`);
|
|
68
|
+
}
|
|
69
|
+
// Converters may discard hidden RGB beneath zero alpha. Canonicalize only invisible pixels;
|
|
70
|
+
// every visible channel, including partial transparency, must still match exactly.
|
|
71
|
+
const canonical = Buffer.from(actual.data);
|
|
72
|
+
for (let offset = 0; offset < canonical.length; offset += 4) {
|
|
73
|
+
const alpha = actual.data[offset + 3];
|
|
74
|
+
if (alpha !== expected.data[offset + 3] || (alpha !== 0 &&
|
|
75
|
+
!actual.data.subarray(offset, offset + 3).equals(expected.data.subarray(offset, offset + 3)))) {
|
|
76
|
+
throw new Error(`${MISMATCH}: decoded macOS icon ${name} differs from app.icon.`);
|
|
77
|
+
}
|
|
78
|
+
if (alpha === 0) canonical.fill(0, offset, offset + 3);
|
|
79
|
+
}
|
|
80
|
+
return createHash('sha256').update(canonical).digest('hex');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Compare at the same conversion boundary. iconutil can normalize even visible colour values
|
|
84
|
+
// while encoding/decoding ICNS. Resized source PNG pixels alone are therefore not its output.
|
|
85
|
+
// Build the reference independently from app.icon with the packager's existing recipe, then
|
|
86
|
+
// decode both ICNS files. Exact visible RGBA comparison remains unchanged; no tolerance is added.
|
|
87
|
+
function referenceIconset(source, scratch, run) {
|
|
88
|
+
const inputs = join(scratch, 'reference.iconset');
|
|
89
|
+
mkdirSync(inputs);
|
|
90
|
+
for (const name of GENERATED_NAMES) {
|
|
91
|
+
const match = /^icon_(\d+)x\1(@2x)?\.png$/u.exec(name);
|
|
92
|
+
const pixels = String(Number(match[1]) * (match[2] ? 2 : 1));
|
|
93
|
+
const target = join(inputs, name);
|
|
94
|
+
iconTool(run, 'sips', ['-z', pixels, pixels, source, '--out', target]);
|
|
95
|
+
pngImage(target, Number(pixels));
|
|
96
|
+
}
|
|
97
|
+
const reference = join(scratch, 'reference.icns');
|
|
98
|
+
iconTool(run, 'iconutil', ['-c', 'icns', inputs, '-o', reference]);
|
|
99
|
+
assertIcns(readFileSync(reference));
|
|
100
|
+
const decoded = join(scratch, 'reference-decoded.iconset');
|
|
101
|
+
iconTool(run, 'iconutil', ['-c', 'iconset', '-o', decoded, reference]);
|
|
102
|
+
if (!lstatSync(decoded).isDirectory() || lstatSync(decoded).isSymbolicLink()) {
|
|
103
|
+
throw new Error(`${INVALID}: iconutil did not produce a reference iconset directory.`);
|
|
104
|
+
}
|
|
105
|
+
return decoded;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Read back every iconutil representation of the final .icns. The packager's PNG -> sips ->
|
|
110
|
+
* iconutil round trip is independently repeated for the authored source, then compared at decoded
|
|
111
|
+
* RGBA. Compression/metadata differences cannot pass for artwork or reject identical artwork. Authored .icns inputs must remain byte-identical and still
|
|
112
|
+
* decode successfully. This proves artifact content, not Finder/Dock appearance or a GUI launch.
|
|
113
|
+
* `run` is the same command-boundary seam used by desktop-distribution.mjs; production uses the OS.
|
|
114
|
+
*/
|
|
115
|
+
export function inspectMacosIcon(icon, source, { run = spawnSync } = {}) {
|
|
116
|
+
const bytes = readFileSync(icon);
|
|
117
|
+
assertIcns(bytes);
|
|
118
|
+
const authoredIcns = source.endsWith('.icns'); // Match buildIcon's existing copy-vs-convert rule.
|
|
119
|
+
if (authoredIcns && !bytes.equals(readFileSync(source))) {
|
|
120
|
+
throw new Error(`${MISMATCH}: the packaged ICNS differs from the authored ICNS.`);
|
|
121
|
+
}
|
|
122
|
+
const scratch = mkdtempSync(join(tmpdir(), 'threenative-icon-inspection-'));
|
|
123
|
+
try {
|
|
124
|
+
const decoded = join(scratch, 'actual.iconset');
|
|
125
|
+
iconTool(run, 'iconutil', ['-c', 'iconset', '-o', decoded, icon]);
|
|
126
|
+
if (!lstatSync(decoded).isDirectory() || lstatSync(decoded).isSymbolicLink()) {
|
|
127
|
+
throw new Error(`${INVALID}: iconutil did not produce an iconset directory.`);
|
|
128
|
+
}
|
|
129
|
+
const entries = readdirSync(decoded, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
130
|
+
if (entries.length === 0 || entries.length > 32) {
|
|
131
|
+
throw new Error(`${INVALID}: iconutil produced no bounded set of icon representations.`);
|
|
132
|
+
}
|
|
133
|
+
if (!authoredIcns && GENERATED_NAMES.some((name) => !entries.some((entry) => entry.name === name))) {
|
|
134
|
+
throw new Error(`${INVALID}: the converted icon is missing a size or scale generated by the packager.`);
|
|
135
|
+
}
|
|
136
|
+
const references = authoredIcns ? undefined : referenceIconset(source, scratch, run);
|
|
137
|
+
const representations = [];
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
const match = /^icon_(\d+)x\1(@2x)?\.png$/u.exec(entry.name);
|
|
140
|
+
const pixels = match ? Number(match[1]) * (match[2] ? 2 : 1) : 0;
|
|
141
|
+
if (!entry.isFile() || !match || pixels < 1 || pixels > 1024) {
|
|
142
|
+
throw new Error(`${INVALID}: unexpected iconutil output ${entry.name}.`);
|
|
143
|
+
}
|
|
144
|
+
const actual = pngImage(join(decoded, entry.name), pixels);
|
|
145
|
+
let expected = actual;
|
|
146
|
+
if (references !== undefined) {
|
|
147
|
+
const reference = join(references, entry.name);
|
|
148
|
+
const info = lstatSync(reference);
|
|
149
|
+
if (!info.isFile() || info.isSymbolicLink()) {
|
|
150
|
+
throw new Error(`${INVALID}: unexpected reference output ${entry.name}.`);
|
|
151
|
+
}
|
|
152
|
+
expected = pngImage(reference, pixels);
|
|
153
|
+
}
|
|
154
|
+
representations.push({
|
|
155
|
+
name: entry.name,
|
|
156
|
+
width: actual.width,
|
|
157
|
+
height: actual.height,
|
|
158
|
+
rgbaSha256: assertIconPixels(actual, expected, entry.name),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return { method: 'iconutil-decoded-rgba', representations };
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error.message?.startsWith('TN_')) throw error;
|
|
164
|
+
throw new Error(`${INVALID}: could not read iconutil output: ${error.message}`);
|
|
165
|
+
} finally {
|
|
166
|
+
// Never modify the signed app or put scratch resources inside the distributed container.
|
|
167
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, resolve } from 'node:path';
|
|
6
|
-
import { fileURLToPath
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
7
|
|
|
8
8
|
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
9
|
const packageVersion = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')).version;
|
|
@@ -419,7 +419,10 @@ export async function installPrebuilt(options = {}) {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
|
|
422
|
+
// Real paths on both sides: pnpm runs this hook through a symlinked `node_modules` path, and a
|
|
423
|
+
// plain comparison with the module's real URL silently skipped the install.
|
|
424
|
+
if (process.argv[1] && existsSync(process.argv[1]) &&
|
|
425
|
+
realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1])) {
|
|
423
426
|
const sourceCheckout = existsSync(join(packageRoot, 'src')) && existsSync(join(packageRoot, 'CMakeLists.txt'));
|
|
424
427
|
if (sourceCheckout) {
|
|
425
428
|
console.log('ThreeNative runtime source checkout detected; prebuilt install is deferred to package testing.');
|
|
@@ -780,7 +780,7 @@ export function stageAndroidAssets(
|
|
|
780
780
|
// Derived from the runtime this build is about to pack, not declared here. A hardcoded claim
|
|
781
781
|
// goes stale the moment the build changes under it, which is exactly what happened to WebP.
|
|
782
782
|
assertAndroidAssetsDecodable(assets, { webp: deriveAndroidWebpSupport(runtimeSource) });
|
|
783
|
-
const files = selectManifestAssets(assets);
|
|
783
|
+
const { selected: files } = selectManifestAssets(assets);
|
|
784
784
|
for (const file of files) {
|
|
785
785
|
const output = join(destination, file);
|
|
786
786
|
mkdirSync(dirname(output), { recursive: true });
|
|
@@ -378,7 +378,7 @@ export function stageDesktopFiles(
|
|
|
378
378
|
if (existsSync(join(assets, '.threenative'))) {
|
|
379
379
|
throw new Error('TN_NATIVE_ASSET_RESERVED_PATH: public/.threenative is reserved.');
|
|
380
380
|
}
|
|
381
|
-
const selected = selectManifestAssets(assets);
|
|
381
|
+
const { selected } = selectManifestAssets(assets);
|
|
382
382
|
for (const file of selected) {
|
|
383
383
|
const output = join(staging, file);
|
|
384
384
|
mkdirSync(dirname(output), { recursive: true });
|