@geastack/apple 0.2.16 → 0.2.19

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.
@@ -44,7 +44,7 @@ resolve_gea_package() {
44
44
  fi
45
45
  done
46
46
  }
47
- GEA_CORE="$(resolve_gea_package @geastack/core)"
47
+ GEA_CORE="${GEA_CORE:-$(resolve_gea_package @geastack/core)}"
48
48
  [ -n "$GEA_CORE" ] && [ -f "$GEA_CORE/package.json" ] || { echo "Cannot resolve @geastack/core from $BUILD_INVOCATION_CWD — add @geastack/apple to the app's dependencies and run 'npm install' there" >&2; exit 1; }
49
49
  GEA_COMPILER="$(resolve_gea_package @geastack/compiler)"
50
50
  [ -n "$GEA_COMPILER" ] && [ -f "$GEA_COMPILER/package.json" ] || { echo "Cannot resolve @geastack/compiler from $BUILD_INVOCATION_CWD — add @geastack/apple to the app's dependencies and run 'npm install' there" >&2; exit 1; }
@@ -87,9 +87,23 @@ export GEA_FW_C_SOURCES="$(gea_fw_c_sources)"
87
87
  export GEA_FW_INCLUDE_DIRS="$(gea_fw_include_flags | sed "s/^-I//")"
88
88
  APP_ID="${1:-bouncing-balls-jsx}"
89
89
  DESTINATION="${2:-simulator}"
90
+ export GEA_APPLE_UIKIT_PLATFORM="${3:-ios}"
91
+ PLATFORM_NAME=iOS
92
+ DEVICE_NAME=iPhone
93
+ SIMULATOR_SDK=iphonesimulator
94
+ DEVICE_SDK=iphoneos
95
+ FONT_WIDTHS=750,828,1125,1170,1290
96
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos ]]; then
97
+ PLATFORM_NAME=tvOS
98
+ DEVICE_NAME="Apple TV"
99
+ SIMULATOR_SDK=appletvsimulator
100
+ DEVICE_SDK=appletvos
101
+ FONT_WIDTHS=1920,3840
102
+ fi
90
103
 
91
- if [[ "$DESTINATION" != "simulator" && "$DESTINATION" != "device" ]]; then
92
- echo "usage: targets/ios/build-ios.sh [app-id] [simulator|device]" >&2
104
+ if [[ "$DESTINATION" != "simulator" && "$DESTINATION" != "device" ]] ||
105
+ [[ "$GEA_APPLE_UIKIT_PLATFORM" != ios && "$GEA_APPLE_UIKIT_PLATFORM" != tvos ]]; then
106
+ echo "usage: targets/ios/build-ios.sh [app-id] [simulator|device] [ios|tvos]" >&2
93
107
  exit 2
94
108
  fi
95
109
 
@@ -100,7 +114,7 @@ APP_INFO="$(node "$GEA_CLI" apps inspect "$APP_ID" --format shell)" || {
100
114
 
101
115
  IFS=$'\t' read -r APP_ROOT APP_ENTRY APP_RUNTIME APP_DISPLAY_NAME <<< "$APP_INFO"
102
116
  if [[ "$APP_RUNTIME" != "gea" ]]; then
103
- echo "iOS target only supports runtime=gea apps for now: $APP_ID is runtime=$APP_RUNTIME" >&2
117
+ echo "$PLATFORM_NAME target only supports runtime=gea apps for now: $APP_ID is runtime=$APP_RUNTIME" >&2
104
118
  exit 1
105
119
  fi
106
120
  APP_NAME="$(node -e "
@@ -114,7 +128,7 @@ BUNDLE_ID="${GEA_IOS_BUNDLE_IDENTIFIER:-com.gea.${APP_ID//[^A-Za-z0-9]/-}}"
114
128
  # next install. The invocation directory is the app the CLI resolved, so output
115
129
  # sources, the Xcode project and DerivedData land next to the app's source.
116
130
  # GEA_IOS_OUTPUT_DIR overrides the root for a caller that wants it elsewhere.
117
- IOS_OUTPUT_ROOT="${GEA_IOS_OUTPUT_DIR:-$BUILD_INVOCATION_CWD/dist/ios}"
131
+ IOS_OUTPUT_ROOT="${GEA_IOS_OUTPUT_DIR:-$BUILD_INVOCATION_CWD/dist/$GEA_APPLE_UIKIT_PLATFORM}"
118
132
  case "$IOS_OUTPUT_ROOT" in
119
133
  /*) ;;
120
134
  *) IOS_OUTPUT_ROOT="$(pwd -P)/$IOS_OUTPUT_ROOT" ;;
@@ -129,7 +143,7 @@ mkdir -p "$GENERATED_DIR"
129
143
 
130
144
  build_font_args=(
131
145
  --font-device-pixel-ratio "${GEA_IOS_FONT_DEVICE_PIXEL_RATIOS:-2,3}"
132
- --font-viewport-width "${GEA_IOS_FONT_VIEWPORT_WIDTHS:-750,828,1125,1170,1290}"
146
+ --font-viewport-width "${GEA_IOS_FONT_VIEWPORT_WIDTHS:-$FONT_WIDTHS}"
133
147
  )
134
148
 
135
149
  generate_app() {
@@ -142,7 +156,7 @@ generate_app() {
142
156
  info="$(node "$GEA_CLI" apps inspect "$app_id" --format shell)" || return 1
143
157
  IFS=$'\t' read -r root entry runtime _name <<< "$info"
144
158
  if [[ "$runtime" != "gea" ]]; then
145
- echo "iOS target only supports runtime=gea apps: $app_id is runtime=$runtime" >&2
159
+ echo "$PLATFORM_NAME target only supports runtime=gea apps: $app_id is runtime=$runtime" >&2
146
160
  return 1
147
161
  fi
148
162
  local args=(
@@ -162,7 +176,17 @@ generate_app() {
162
176
  --out-dir "$out_dir"
163
177
  "${build_font_args[@]}"
164
178
  )
165
- local native_plugin="$root/ios/geatsc-native-plugin.mjs"
179
+ local plugin_paths
180
+ local plugin_path
181
+ plugin_paths="$(node "$GEA_CLI" apps inspect "$app_id" --json | node -e '
182
+ const app = JSON.parse(require("node:fs").readFileSync(0, "utf8"));
183
+ for (const plugin of app.compilerPlugins || [])
184
+ console.log(require("node:path").resolve(app.root, plugin));
185
+ ')" || return 1
186
+ while IFS= read -r plugin_path; do
187
+ [[ -z "$plugin_path" ]] || args+=(--extra-geatsc-plugin "$plugin_path")
188
+ done <<< "$plugin_paths"
189
+ local native_plugin="$root/$GEA_APPLE_UIKIT_PLATFORM/geatsc-native-plugin.mjs"
166
190
  if [[ -f "$native_plugin" ]]; then
167
191
  args+=(--extra-geatsc-plugin "$native_plugin")
168
192
  fi
@@ -180,12 +204,12 @@ pick_simulator_device() {
180
204
  const input = fs.readFileSync(0, 'utf8');
181
205
  if (!input.trim()) process.exit(0);
182
206
  const data = JSON.parse(input);
183
- const devices = Object.values(data.devices || {}).flat();
184
- const iphones = devices.filter((d) => d.isAvailable && /^iPhone/.test(d.name));
185
- const booted = iphones.find((d) => d.state === 'Booted');
186
- const preferred = booted || iphones[iphones.length - 1];
207
+ const devices = Object.entries(data.devices || {}).filter(([runtime]) => runtime.includes('.' + process.argv[1] + '-')).flatMap(([, list]) => list);
208
+ const matching = devices.filter((d) => d.isAvailable && d.deviceTypeIdentifier?.includes(process.argv[2]));
209
+ const booted = matching.find((d) => d.state === 'Booted');
210
+ const preferred = booted || matching.find((d) => d.deviceTypeIdentifier?.endsWith('-4K')) || matching[matching.length - 1];
187
211
  if (preferred) console.log(preferred.udid);
188
- " <<< "$devices_json"
212
+ " "$PLATFORM_NAME" "${DEVICE_NAME// /-}" <<< "$devices_json"
189
213
  }
190
214
 
191
215
  # Build an xcodebuild -destination string for a simulator UDID using its
@@ -222,9 +246,9 @@ show_simulator_device() {
222
246
  /usr/bin/open -a Simulator --args -CurrentDeviceUDID "$udid"
223
247
  }
224
248
 
225
- pick_ios_device() {
249
+ pick_device() {
226
250
  local output_json
227
- output_json="$(mktemp "${TMPDIR:-/tmp}/gea-ios-devices.XXXXXX.json")"
251
+ output_json="$(mktemp "${TMPDIR:-/tmp}/gea-ios-devices.XXXXXX")"
228
252
  if ! xcrun devicectl list devices --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-30}" --json-output "$output_json" >/dev/null; then
229
253
  rm -f "$output_json"
230
254
  return 0
@@ -235,24 +259,33 @@ pick_ios_device() {
235
259
  const devices = data.result?.devices || [];
236
260
  const usable = devices.filter((device) => {
237
261
  const hardware = device.hardwareProperties || {};
262
+ const connection = device.connectionProperties || {};
263
+ if (process.argv[2] === 'tvOS') {
264
+ return hardware.platform === 'tvOS' &&
265
+ hardware.reality !== 'simulated' &&
266
+ connection.pairingState === 'paired';
267
+ }
238
268
  const props = device.deviceProperties || {};
239
269
  const capabilities = device.capabilities || [];
240
270
  const features = new Set(capabilities.map((capability) => capability.featureIdentifier));
241
- return hardware.platform === 'iOS' &&
271
+ return hardware.platform === process.argv[2] &&
242
272
  hardware.deviceType === 'iPhone' &&
243
273
  props.developerModeStatus === 'enabled' &&
244
- device.connectionProperties?.tunnelState === 'connected' &&
274
+ connection.tunnelState === 'connected' &&
245
275
  features.has('com.apple.coredevice.feature.installapp') &&
246
276
  features.has('com.apple.coredevice.feature.launchapplication');
247
277
  });
248
278
  usable.sort((a, b) => {
279
+ const aConnected = a.connectionProperties?.tunnelState === 'connected';
280
+ const bConnected = b.connectionProperties?.tunnelState === 'connected';
281
+ if (aConnected !== bConnected) return Number(aConnected) - Number(bConnected);
249
282
  const aDate = Date.parse(a.connectionProperties?.lastConnectionDate || '') || 0;
250
283
  const bDate = Date.parse(b.connectionProperties?.lastConnectionDate || '') || 0;
251
284
  return aDate - bDate;
252
285
  });
253
286
  const picked = usable[usable.length - 1];
254
287
  if (picked) console.log(picked.identifier || picked.hardwareProperties?.udid || picked.deviceProperties?.name || '');
255
- " "$output_json"
288
+ " "$output_json" "$PLATFORM_NAME"
256
289
  rm -f "$output_json"
257
290
  }
258
291
 
@@ -269,44 +302,43 @@ GEA_CLI_BIN="$GEA_CLI" node "$IOS_DIR/generate-xcode-project.mjs" \
269
302
  --generated-dir "$GENERATED_DIR" \
270
303
  --project-path "$PROJECT_PATH"
271
304
 
272
- SDK="iphonesimulator"
305
+ SDK="$SIMULATOR_SDK"
273
306
  SIMULATOR_DEVICE_ID="${GEA_IOS_SIMULATOR_UDID:-}"
274
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=iOS Simulator}"
275
- if [[ "$DESTINATION" == "simulator" ]]; then
276
- if [[ "$SKIP_LAUNCH" == "1" ]]; then
277
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=iOS Simulator}"
278
- else
279
- if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
280
- SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
281
- fi
282
- if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
283
- echo "No available iPhone simulator found." >&2
284
- exit 1
285
- fi
286
- # Resolve a name+OS destination (robust against the poisoned enumeration that
287
- # a connected real iPhone causes); fall back to id= if the lookup fails.
288
- XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-}"
289
- if [[ -z "$XCODE_DESTINATION" ]]; then
290
- XCODE_DESTINATION="$(sim_destination_for_udid "$SIMULATOR_DEVICE_ID")"
291
- [[ -z "$XCODE_DESTINATION" ]] && XCODE_DESTINATION="platform=iOS Simulator,id=$SIMULATOR_DEVICE_ID"
292
- fi
307
+ XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-generic/platform=$PLATFORM_NAME Simulator}"
308
+ if [[ "$DESTINATION" == "simulator" && "$SKIP_LAUNCH" != "1" ]]; then
309
+ if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
310
+ SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
311
+ fi
312
+ if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
313
+ echo "No available $DEVICE_NAME simulator found." >&2
314
+ exit 1
315
+ fi
316
+ XCODE_DESTINATION="${GEA_IOS_SIMULATOR_DESTINATION:-}"
317
+ if [[ -z "$XCODE_DESTINATION" && "$GEA_APPLE_UIKIT_PLATFORM" == ios ]]; then
318
+ XCODE_DESTINATION="$(sim_destination_for_udid "$SIMULATOR_DEVICE_ID")"
319
+ fi
320
+ if [[ -z "$XCODE_DESTINATION" ]]; then
321
+ XCODE_DESTINATION="platform=$PLATFORM_NAME Simulator,id=$SIMULATOR_DEVICE_ID"
293
322
  fi
294
323
  fi
295
324
  EXTRA_BUILD_SETTINGS=()
296
325
  EXTRA_XCODEBUILD_ARGS=()
297
326
  IOS_DEVICE_ID="${GEA_IOS_DEVICE_ID:-}"
298
327
  if [[ "$DESTINATION" == "device" ]]; then
299
- SDK="iphoneos"
300
- XCODE_DESTINATION="${GEA_IOS_DEVICE_DESTINATION:-generic/platform=iOS}"
328
+ SDK="$DEVICE_SDK"
329
+ XCODE_DESTINATION="${GEA_IOS_DEVICE_DESTINATION:-generic/platform=$PLATFORM_NAME}"
301
330
  if [[ -z "$IOS_DEVICE_ID" && "$SKIP_LAUNCH" != "1" ]]; then
302
- IOS_DEVICE_ID="$(pick_ios_device)"
331
+ IOS_DEVICE_ID="$(pick_device)"
303
332
  if [[ -n "$IOS_DEVICE_ID" ]]; then
304
- echo "Using iOS device $IOS_DEVICE_ID. Override with GEA_IOS_DEVICE_ID." >&2
333
+ echo "Using $PLATFORM_NAME device $IOS_DEVICE_ID. Override with GEA_IOS_DEVICE_ID." >&2
305
334
  fi
306
335
  fi
307
336
  if [[ -z "$IOS_DEVICE_ID" && "$SKIP_LAUNCH" != "1" ]]; then
308
- echo "No available iPhone device found for install or launch." >&2
309
- echo "Connect an iPhone with Developer Mode enabled, or set GEA_IOS_DEVICE_ID." >&2
337
+ echo "No available $DEVICE_NAME device found for install or launch." >&2
338
+ echo "Pair your $DEVICE_NAME with Xcode, or set GEA_IOS_DEVICE_ID." >&2
339
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == ios ]]; then
340
+ echo "Enable Developer Mode on the iPhone before launching." >&2
341
+ fi
310
342
  exit 1
311
343
  fi
312
344
  DEVELOPMENT_TEAM="${GEA_IOS_DEVELOPMENT_TEAM:-}"
@@ -321,15 +353,26 @@ if [[ "$DESTINATION" == "device" ]]; then
321
353
  if [[ "$SKIP_LAUNCH" != "1" ]]; then
322
354
  echo "Device builds require GEA_IOS_DEVELOPMENT_TEAM for Xcode automatic signing." >&2
323
355
  echo "The script also checks Xcode preferences and installed provisioning profiles, but no unambiguous team was found." >&2
324
- echo "Example: GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 targets/ios/build-ios.sh $APP_ID device" >&2
356
+ echo "Example: GEA_IOS_DEVELOPMENT_TEAM=ABCDE12345 gea run --target $GEA_APPLE_UIKIT_PLATFORM --mode device --app $APP_ID" >&2
325
357
  exit 1
326
358
  fi
327
- echo "GEA_IOS_DEVELOPMENT_TEAM is not set; building an unsigned iphoneos binary." >&2
328
- echo "Set GEA_IOS_DEVELOPMENT_TEAM to install or launch on an iPhone." >&2
359
+ echo "GEA_IOS_DEVELOPMENT_TEAM is not set; building an unsigned $DEVICE_SDK binary." >&2
360
+ echo "Set GEA_IOS_DEVELOPMENT_TEAM to install or launch on your $DEVICE_NAME." >&2
329
361
  EXTRA_BUILD_SETTINGS+=("CODE_SIGNING_ALLOWED=NO")
330
362
  EXTRA_BUILD_SETTINGS+=("CODE_SIGNING_REQUIRED=NO")
331
363
  EXTRA_BUILD_SETTINGS+=("CODE_SIGN_IDENTITY=")
332
364
  else
365
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos && -n "$IOS_DEVICE_ID" && -z "${GEA_IOS_DEVICE_DESTINATION:-}" ]]; then
366
+ DEVICE_UDID="$(xcrun devicectl device info details --device "$IOS_DEVICE_ID" \
367
+ --quiet --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-30}" --json-output /dev/stdout | node -e '
368
+ const device = JSON.parse(require("node:fs").readFileSync(0, "utf8")).result;
369
+ if (device.hardwareProperties?.platform !== "tvOS" || device.hardwareProperties.reality === "simulated") {
370
+ throw new Error("Select a physical Apple TV with GEA_IOS_DEVICE_ID.");
371
+ }
372
+ process.stdout.write(device.hardwareProperties.udid);
373
+ ')"
374
+ XCODE_DESTINATION="platform=tvOS,id=$DEVICE_UDID"
375
+ fi
333
376
  EXTRA_BUILD_SETTINGS+=("DEVELOPMENT_TEAM=$DEVELOPMENT_TEAM")
334
377
  EXTRA_BUILD_SETTINGS+=("CODE_SIGN_STYLE=Automatic")
335
378
  ALLOW_PROVISIONING_UPDATES="${GEA_IOS_ALLOW_PROVISIONING_UPDATES:-}"
@@ -337,9 +380,12 @@ if [[ "$DESTINATION" == "device" ]]; then
337
380
  ALLOW_PROVISIONING_UPDATES="1"
338
381
  fi
339
382
  if [[ "$ALLOW_PROVISIONING_UPDATES" == "1" ]]; then
340
- echo "Allowing Xcode to create or update iOS provisioning profiles." >&2
383
+ echo "Allowing Xcode to create or update $PLATFORM_NAME provisioning profiles." >&2
341
384
  echo "Set GEA_IOS_ALLOW_PROVISIONING_UPDATES=0 to disable this." >&2
342
385
  EXTRA_XCODEBUILD_ARGS+=("-allowProvisioningUpdates")
386
+ if [[ "$GEA_APPLE_UIKIT_PLATFORM" == tvos && "$XCODE_DESTINATION" != generic/* ]]; then
387
+ EXTRA_XCODEBUILD_ARGS+=("-allowProvisioningDeviceRegistration")
388
+ fi
343
389
  fi
344
390
  fi
345
391
  fi
@@ -348,7 +394,7 @@ fi
348
394
  # real iPhone lacks its device-support platform — even an explicit simulator
349
395
  # destination then fails to match. Retry on that specific flake (re-settling the
350
396
  # sim first); any other failure breaks out immediately.
351
- XCODEBUILD_LOG="$(mktemp "${TMPDIR:-/tmp}/gea-ios-xcodebuild.XXXXXX.log")"
397
+ XCODEBUILD_LOG="$(mktemp "${TMPDIR:-/tmp}/gea-ios-xcodebuild.XXXXXX")"
352
398
  XCODEBUILD_ATTEMPTS="${GEA_IOS_BUILD_ATTEMPTS:-3}"
353
399
  xcodebuild_status=1
354
400
  for ((xcodebuild_attempt = 1; xcodebuild_attempt <= XCODEBUILD_ATTEMPTS; xcodebuild_attempt++)); do
@@ -388,7 +434,7 @@ if [[ "$DESTINATION" == "simulator" && "$SKIP_LAUNCH" != "1" ]]; then
388
434
  SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
389
435
  fi
390
436
  if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
391
- echo "No available iPhone simulator found; build succeeded without launch." >&2
437
+ echo "No available $DEVICE_NAME simulator found; build succeeded without launch." >&2
392
438
  exit 0
393
439
  fi
394
440
  show_simulator_device "$SIMULATOR_DEVICE_ID"
@@ -400,10 +446,10 @@ fi
400
446
 
401
447
  if [[ "$DESTINATION" == "device" && "$SKIP_LAUNCH" != "1" ]]; then
402
448
  if [[ -z "$IOS_DEVICE_ID" ]]; then
403
- IOS_DEVICE_ID="$(pick_ios_device)"
449
+ IOS_DEVICE_ID="$(pick_device)"
404
450
  fi
405
451
  if [[ -z "$IOS_DEVICE_ID" ]]; then
406
- echo "No available iPhone device found; build succeeded without launch." >&2
452
+ echo "No available $DEVICE_NAME device found; build succeeded without launch." >&2
407
453
  exit 0
408
454
  fi
409
455
  xcrun devicectl --timeout "${GEA_IOS_DEVICECTL_TIMEOUT:-60}" device install app --device "$IOS_DEVICE_ID" "$APP_PRODUCT"
@@ -59,14 +59,22 @@ const appIconAssetsDir = path.join(generatedDir, 'Assets.xcassets')
59
59
  // compile a catalog unless an installed simulator runtime's build matches the SDK
60
60
  // exactly (e.g. SDK 23F81a needs a 23F81a runtime, not a 23F73 one) — a skew that
61
61
  // blocks otherwise-fine builds. Skipping it yields an app with the default icon.
62
- const skipAppIcon = process.env.GEA_IOS_SKIP_APP_ICON === '1'
62
+ const tvos = process.env.GEA_APPLE_UIKIT_PLATFORM === 'tvos'
63
+ const buildConfig = process.env.GEA_BUILD_CONFIG_JSON
64
+ ? JSON.parse(fs.readFileSync(process.env.GEA_BUILD_CONFIG_JSON, 'utf8'))
65
+ : {}
66
+ const viewport = buildConfig.settings?.display || {}
67
+ if ((viewport.width === undefined) !== (viewport.height === undefined))
68
+ fail('Set both display.width and display.height for the UIKit rendering resolution.')
69
+
70
+ const skipAppIcon = tvos || process.env.GEA_IOS_SKIP_APP_ICON === '1'
63
71
 
64
72
  fs.rmSync(projectPath, { recursive: true, force: true })
65
73
  fs.mkdirSync(path.join(projectPath, 'project.xcworkspace'), { recursive: true })
66
74
  fs.mkdirSync(path.join(projectPath, 'xcshareddata/xcschemes'), { recursive: true })
67
75
  if (!skipAppIcon) gea(['apps', 'apple-icons', appId, '--platform', 'ios', '--assets-dir', appIconAssetsDir])
68
76
 
69
- const plistTemplate = fs.readFileSync(path.join(iosDir, 'Info.plist.in'), 'utf8')
77
+ const plistTemplate = fs.readFileSync(path.join(iosDir, tvos ? 'Info-tvOS.plist.in' : 'Info.plist.in'), 'utf8')
70
78
  fs.writeFileSync(
71
79
  plistOut,
72
80
  plistTemplate
@@ -118,7 +126,7 @@ function nativeSourceKind(file) {
118
126
  }
119
127
 
120
128
  function findAppNativeSources() {
121
- const dir = path.join(appRoot, 'ios')
129
+ const dir = path.join(appRoot, tvos ? 'tvos' : 'ios')
122
130
  if (!fs.existsSync(dir)) return []
123
131
  const out = []
124
132
  const visit = (current) => {
@@ -157,7 +165,10 @@ const rendererSources = [
157
165
  'renderer/native_scroll_container.mm',
158
166
  'renderer/view_reconciler.mm',
159
167
  ].map((file) => source(path.join(iosDir, 'main', file), 'sourcecode.cpp.objcpp'))
160
- const appNativeSources = findAppNativeSources()
168
+ const appNativeSources = [...new Map([
169
+ ...findAppNativeSources(),
170
+ ...(appMeta.nativeSourcePaths || []).map((file) => source(file, nativeSourceKind(file))),
171
+ ].map((entry) => [entry.file, entry])).values()]
161
172
  const sources = [
162
173
  source(path.join(iosDir, 'main/ios_main.mm'), 'sourcecode.cpp.objcpp'),
163
174
  source(path.join(iosDir, 'main/ios_root_background.cpp')),
@@ -200,7 +211,7 @@ const fontResources = findFontResources().map((file) => resource(file))
200
211
  const appIconAssets = resource(appIconAssetsDir, 'folder.assetcatalog')
201
212
  const appIconResources = skipAppIcon ? [] : [appIconAssets]
202
213
  const uiTestSource = source(path.join(iosDir, 'test/GeaIosRubberBandUITests.swift'), 'sourcecode.swift')
203
- const uiTestSources = existing(uiTestSource) ? [uiTestSource] : []
214
+ const uiTestSources = tvos ? [] : existing(uiTestSource) ? [uiTestSource] : []
204
215
  const hasUiTests = uiTestSources.length > 0
205
216
 
206
217
  const frameworks = [
@@ -208,7 +219,7 @@ const frameworks = [
208
219
  'QuartzCore.framework',
209
220
  'CoreGraphics.framework',
210
221
  'CoreText.framework',
211
- 'CoreMotion.framework',
222
+ tvos ? 'GameController.framework' : 'CoreMotion.framework',
212
223
  'CoreLocation.framework',
213
224
  'CoreMedia.framework',
214
225
  'CoreVideo.framework',
@@ -218,6 +229,7 @@ const frameworks = [
218
229
  'Photos.framework',
219
230
  'Security.framework',
220
231
  'UserNotifications.framework',
232
+ ...(!tvos ? ['EventKit.framework'] : []),
221
233
  'Metal.framework',
222
234
  'MetalKit.framework',
223
235
  'Foundation.framework',
@@ -293,7 +305,8 @@ const uiTestProductRef = hasUiTests
293
305
  const includePaths = [
294
306
  path.join(iosDir, 'main'),
295
307
  generatedDir,
296
- path.join(appRoot, 'ios'),
308
+ path.join(appRoot, tvos ? 'tvos' : 'ios'),
309
+ ...new Set(appNativeSources.map(({ file }) => path.dirname(file))),
297
310
  // Framework include roots (core/host/engine includes + vendor/stb + AnimatedGIF)
298
311
  // from the shared manifest gea_sources.sh, passed by build-ios.sh via env.
299
312
  ...(process.env.GEA_FW_INCLUDE_DIRS || '').split('\n').filter(Boolean),
@@ -306,6 +319,10 @@ const includePaths = [
306
319
  function buildSettings(configuration) {
307
320
  const preprocessorDefinitions = [
308
321
  'GEA_EMBEDDED_GIF_C_API=1',
322
+ ...(viewport.width === undefined ? [] : [
323
+ `GEA_UIKIT_VIEWPORT_WIDTH=${viewport.width}`,
324
+ `GEA_UIKIT_VIEWPORT_HEIGHT=${viewport.height}`,
325
+ ]),
309
326
  'GEA_EMBEDDED_ENABLE_NATIVE_TEXT_INPUT=1',
310
327
  'GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD=0',
311
328
  'GEA_CPP_USE_TO_CHARS_DOUBLE=0',
@@ -332,16 +349,16 @@ function buildSettings(configuration) {
332
349
  GCC_PREPROCESSOR_DEFINITIONS = (${preprocessorDefinitions.map(q).join(', ')});
333
350
  HEADER_SEARCH_PATHS = (${includePaths.map(q).join(', ')});
334
351
  INFOPLIST_FILE = ${q(plistOut)};
335
- IPHONEOS_DEPLOYMENT_TARGET = 16.0;
352
+ ${tvos ? 'TVOS_DEPLOYMENT_TARGET = 17.0;' : 'IPHONEOS_DEPLOYMENT_TARGET = 16.0;'}
336
353
  LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
337
354
  ONLY_ACTIVE_ARCH = ${configuration === 'Debug' ? 'YES' : 'NO'};
338
355
  OTHER_LDFLAGS = ("$(inherited)", "-Wl,-no_deduplicate");
339
356
  PRODUCT_BUNDLE_IDENTIFIER = ${q(bundleId)};
340
357
  PRODUCT_NAME = ${q(appName)};
341
- SDKROOT = iphoneos;
342
- SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
358
+ SDKROOT = ${tvos ? 'appletvos' : 'iphoneos'};
359
+ SUPPORTED_PLATFORMS = "${tvos ? 'appletvos appletvsimulator' : 'iphoneos iphonesimulator'}";
343
360
  SUPPORTS_MACCATALYST = NO;
344
- TARGETED_DEVICE_FAMILY = "1,2";
361
+ TARGETED_DEVICE_FAMILY = "${tvos ? '3' : '1,2'}";
345
362
  }`
346
363
  }
347
364
 
@@ -6,18 +6,9 @@
6
6
 
7
7
  namespace {
8
8
 
9
- std::uint8_t *g_scratch = nullptr;
10
- std::size_t g_scratchBytes = 0;
11
-
12
- std::uint8_t *ensureScratch(std::size_t bytes)
9
+ void releaseFrame(void *, const void *data, std::size_t)
13
10
  {
14
- if (g_scratchBytes < bytes) {
15
- void *grown = std::realloc(g_scratch, bytes);
16
- if (!grown) return nullptr;
17
- g_scratch = static_cast<std::uint8_t *>(grown);
18
- g_scratchBytes = bytes;
19
- }
20
- return g_scratch;
11
+ std::free(const_cast<void *>(data));
21
12
  }
22
13
 
23
14
  } // namespace
@@ -50,7 +41,7 @@ std::uint8_t *ensureScratch(std::size_t bytes)
50
41
  if (!src || w <= 0 || h <= 0) return;
51
42
 
52
43
  const std::size_t bytes = static_cast<std::size_t>(w) * h * 4;
53
- std::uint8_t *dst = ensureScratch(bytes);
44
+ auto *dst = static_cast<std::uint8_t *>(std::malloc(bytes));
54
45
  if (!dst) return;
55
46
  #if GEA_EMBEDDED_PIXEL_FORMAT == GEA_PIXEL_RGBA8888
56
47
  // native_t is already RGBA8888 (R,G,B,A bytes per pixel) — exactly the
@@ -68,7 +59,7 @@ std::uint8_t *ensureScratch(std::size_t bytes)
68
59
  #endif
69
60
 
70
61
  CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
71
- CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, dst, bytes, nullptr);
62
+ CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, dst, bytes, releaseFrame);
72
63
  const uint32_t bitmapInfo = static_cast<uint32_t>(kCGImageAlphaNoneSkipLast) |
73
64
  static_cast<uint32_t>(kCGBitmapByteOrder32Big);
74
65
  CGImageRef image = CGImageCreate(static_cast<std::size_t>(w),
@@ -1,3 +1,5 @@
1
+ #include <TargetConditionals.h>
2
+
1
3
  #import <CoreText/CoreText.h>
2
4
  #import <Foundation/Foundation.h>
3
5
  #import <UIKit/UIKit.h>
@@ -79,7 +81,11 @@ UIFont *fontForFamily(NSString *family, CGFloat size)
79
81
 
80
82
  UIFont *fontForId(int fontId, CGFloat sizePt)
81
83
  {
84
+ #if TARGET_OS_TV
85
+ const CGFloat size = sizePt > 0 ? sizePt : [UIFont preferredFontForTextStyle:UIFontTextStyleBody].pointSize;
86
+ #else
82
87
  const CGFloat size = sizePt > 0 ? sizePt : [UIFont systemFontSize];
88
+ #endif
83
89
  ensureBundledFontsRegistered();
84
90
 
85
91
  const char *familyName = gea::framework::graphics::FontRegistry::familyName(fontId);
@@ -280,6 +280,16 @@ DeviceInfo Camera::deviceAt(int index)
280
280
  return {"back", Facing::Back, 0, 0};
281
281
  }
282
282
 
283
+ void Camera::drawPreview(int x, int y, int width, int height)
284
+ {
285
+ auto &camera = state();
286
+ std::lock_guard<std::mutex> lock(camera.frameMutex);
287
+ if (camera.latestFrame.empty()) return;
288
+ gea::platform::display::Display::blitImageScaled(
289
+ camera.latestFrame.data(), nullptr, camera.latestWidth, camera.latestHeight,
290
+ x, y, width > 0 ? width : camera.latestWidth, height > 0 ? height : camera.latestHeight);
291
+ }
292
+
283
293
  int Camera::previewMode() { return 1; } // NativeOverlay
284
294
 
285
295
  bool Camera::fillPreview(gea::framework::graphics::pixel::native_t *, int, int, int, bool)
@@ -100,10 +100,11 @@ void Display::clear() { canvas()->clear(0); }
100
100
  void Display::clearNoFlush() { canvas()->clear(0); }
101
101
  void Display::print(const char *) {}
102
102
 
103
- // No double-buffered framebuffer on the iOS host shim — the canvas is the
104
- // presented surface — so rebinding is a no-op (the embedded backends use this
105
- // to re-point the canvas at a freshly-allocated framebuffer).
106
- void Display::rebindCanvasToFramebuffer() {}
103
+ void Display::rebindCanvasToFramebuffer()
104
+ {
105
+ if (g_canvas.pixels() != g_framebuffer)
106
+ g_canvas.bindPixels(g_framebuffer, g_canvas_width, g_canvas_height);
107
+ }
107
108
 
108
109
  void Display::flush()
109
110
  {
@@ -132,10 +133,10 @@ void Display::flushRects(const DisplayFlushRect *rects, int count, bool)
132
133
  g_canvas.resetDirty();
133
134
  }
134
135
 
135
- bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user)
136
+ static bool rasterRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user)
136
137
  {
137
138
  ensure_canvas();
138
- if (!raster || w <= 0 || h <= 0) return false;
139
+ if (!g_framebuffer || !raster || w <= 0 || h <= 0) return false;
139
140
  int x0 = std::max(0, x);
140
141
  int y0 = std::max(0, y);
141
142
  int x1 = std::min(g_canvas_width - 1, x + w - 1);
@@ -154,15 +155,32 @@ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raste
154
155
  using native_t = gea::framework::graphics::pixel::native_t;
155
156
  std::vector<native_t> pixels(static_cast<std::size_t>(rw) * static_cast<std::size_t>(rh));
156
157
  raster(pixels.data(), rw, rh, x0, y0, user);
158
+ Display::rebindCanvasToFramebuffer();
157
159
  for (int row = 0; row < rh; row++) {
158
160
  std::copy_n(&pixels[static_cast<std::size_t>(row) * static_cast<std::size_t>(rw)], rw,
159
161
  &g_framebuffer[static_cast<std::size_t>((y0 + row) * g_canvas_width + x0)]);
160
162
  }
161
163
  g_canvas.markDirty(x0, y0, x1, y1);
164
+ return true;
165
+ }
166
+
167
+ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user)
168
+ {
169
+ if (!rasterRect(x, y, w, h, raster, user)) return false;
162
170
  flush();
163
171
  return true;
164
172
  }
165
173
 
174
+ void Display::flushRectsRasterized(const DisplayFlushRect *rects, int count, DisplayStreamRasterFn raster, void *user, bool allowPerChunkDrain)
175
+ {
176
+ if (!rects || count <= 0 || !raster) return;
177
+ for (int i = 0; i < count; i++) {
178
+ const auto &rect = rects[i];
179
+ rasterRect(rect.x0, rect.y0, rect.x1 - rect.x0 + 1, rect.y1 - rect.y0 + 1, raster, user);
180
+ }
181
+ flushRects(rects, count, allowPerChunkDrain);
182
+ }
183
+
166
184
  bool Display::present(const DisplayPresentCommand *commands, int command_count)
167
185
  {
168
186
  ensure_canvas();
@@ -325,6 +343,7 @@ DisplayFlushStageDetail Display::flushStageDetail() { return {}; }
325
343
  // Orientation is a device-panel concept; the iOS app rotates via UIKit, not by
326
344
  // rotating the framebuffer — so the framework rotation hook is a no-op here.
327
345
  void applyOrientation(gea::framework::display::DisplayOrientation) {}
346
+ bool autoRotateAllowed() { return false; }
328
347
 
329
348
  } // namespace gea::platform::display
330
349