@geastack/apple 0.2.34 → 0.2.36

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.34",
4
- "description": "Generated Apple SDK bindings plus the macOS, iOS and tvOS native build targets for Gea apps.",
3
+ "version": "0.2.36",
4
+ "description": "Generated Apple SDK bindings plus the macOS, iOS, tvOS and watchOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -118,7 +118,7 @@
118
118
  "@geastack/compiler": "^1.0.74",
119
119
  "@geastack/core": "^0.1.72",
120
120
  "@geastack/elements": "^0.1.7",
121
- "@geastack/engine": "^0.1.37",
121
+ "@geastack/engine": "^0.1.39",
122
122
  "@geastack/geatsc-plugin-apple-native": "^0.1.4",
123
123
  "@geastack/geatsc-plugin-gea": "^0.1.32",
124
124
  "@geastack/host": "^0.1.29"
@@ -73,6 +73,21 @@ The Xcode project is generated under
73
73
  if you want to inspect signing or launch through Xcode. Do not hand-edit it as
74
74
  the source of truth.
75
75
 
76
+ ## Info.plist keys
77
+
78
+ Usage descriptions and other per-app keys go in `ios.json` (`tvos.json` for
79
+ tvOS) next to the app's `package.json`. Its `infoPlist` object is merged over
80
+ the generated `Info.plist`, as with `macos.json`. An app that uses
81
+ `bluetooth.central` needs `NSBluetoothAlwaysUsageDescription`:
82
+
83
+ ```json
84
+ {
85
+ "infoPlist": {
86
+ "NSBluetoothAlwaysUsageDescription": "Connects to your heart-rate strap."
87
+ }
88
+ }
89
+ ```
90
+
76
91
  ## tvOS
77
92
 
78
93
  Apps that declare `gea.targets.tvos` can use the shared UIKit host on tvOS 17
@@ -84,6 +84,10 @@ source "$GEA_CORE/gea_sources.sh"
84
84
  export GEA_FW_CXX_SOURCES="$(gea_fw_cxx_sources | grep -vE "/(runtime|services/[a-z_]+)\.cpp\$")"
85
85
  export GEA_FW_C_SOURCES="$(gea_fw_c_sources)"
86
86
  export GEA_FW_INCLUDE_DIRS="$(gea_fw_include_flags | sed "s/^-I//")"
87
+ # The Objective-C++ host backends (CoreBluetooth central, Security P-256,
88
+ # AudioToolbox Opus, the data directory). ios_websocket.mm already includes
89
+ # websocket_apple.mm, so it is left out here.
90
+ export GEA_FW_OBJCXX_SOURCES="$(gea_fw_objcxx_sources | grep -v "/websocket_apple\.mm$")"
87
91
  # A single app never compiles, includes or links GeaOS. GEA_GEAOS=1 requests a
88
92
  # GeaOS build: generate-xcode-project.mjs then adds these sources and include
89
93
  # roots, GEA_GEAOS=1 and the iOS GeaOS app host (main/ios_app_platform.mm).
@@ -85,6 +85,13 @@ fs.writeFileSync(
85
85
  .replaceAll('@APP_NAME@', appName)
86
86
  .replaceAll('@BUNDLE_ID@', bundleId),
87
87
  )
88
+ // The app's own keys (usage descriptions such as NSBluetoothAlwaysUsageDescription)
89
+ // come from the optional `infoPlist` object of ios.json (tvos.json for tvOS) next to
90
+ // its package.json, merged the same way macOS merges macos.json.
91
+ const uikitConfig = path.join(appRoot, tvos ? 'tvos.json' : 'ios.json')
92
+ if (fs.existsSync(uikitConfig)) {
93
+ execFileSync(process.execPath, [path.join(iosDir, '../macos/merge-info-plist.mjs'), plistOut, uikitConfig], { stdio: 'inherit' })
94
+ }
88
95
 
89
96
  function id(label) {
90
97
  return crypto.createHash('sha1').update(label).digest('hex').slice(0, 24).toUpperCase()
@@ -223,6 +230,7 @@ const sources = [
223
230
  // shell excluded — iOS uses its own UIKit run loop). Single source of truth.
224
231
  ...(process.env.GEA_FW_C_SOURCES || '').split('\n').filter(Boolean).map((f) => source(f, 'sourcecode.c.c')),
225
232
  ...(process.env.GEA_FW_CXX_SOURCES || '').split('\n').filter(Boolean).map((f) => source(f)),
233
+ ...(process.env.GEA_FW_OBJCXX_SOURCES || '').split('\n').filter(Boolean).map((f) => source(f, 'sourcecode.cpp.objcpp')),
226
234
  // gea_app_entry.cpp provides Application::init/frame, which calls the one
227
235
  // __gea_top_level geatsc emitted (deliberately not in the manifest).
228
236
  source(path.join(geaCore, 'gea_app_entry.cpp')),
@@ -30,6 +30,9 @@ int g_flush_depth = 2;
30
30
  int g_flush_calls = 0;
31
31
  int g_flush_rects = 0;
32
32
  int g_flush_pixels = 0;
33
+ // Bumped whenever pixels reach the presented buffer, so a shell that snapshots
34
+ // it (the watchOS SwiftUI host) can skip frames where nothing was presented.
35
+ std::uint32_t g_presented_generation = 0;
33
36
 
34
37
  void ensure_canvas()
35
38
  {
@@ -49,6 +52,7 @@ void ensure_canvas()
49
52
  return;
50
53
  }
51
54
  g_canvas.bindPixels(g_framebuffer, g_canvas_width, g_canvas_height);
55
+ g_presented_generation++;
52
56
  }
53
57
 
54
58
  void count_rect(int x0, int y0, int x1, int y1)
@@ -76,6 +80,7 @@ void copy_rect_to_presented(int x0, int y0, int x1, int y1)
76
80
  const std::size_t offset = static_cast<std::size_t>(y) * g_canvas_width + x0;
77
81
  std::copy_n(g_framebuffer + offset, width, g_presented_framebuffer + offset);
78
82
  }
83
+ g_presented_generation++;
79
84
  }
80
85
 
81
86
  } // namespace
@@ -354,6 +359,11 @@ extern "C" const std::uint32_t *gea_ios_display_presented_pixels()
354
359
  return g_presented_framebuffer ? g_presented_framebuffer : g_framebuffer;
355
360
  }
356
361
 
362
+ extern "C" std::uint32_t gea_ios_display_presented_generation()
363
+ {
364
+ return g_presented_generation;
365
+ }
366
+
357
367
  extern "C" void gea_ios_display_set_viewport_size(int width, int height)
358
368
  {
359
369
  if (width <= 0 || height <= 0) return;
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Merge the optional `infoPlist` object of an app's macos.json into the
2
+ // Merge the optional `infoPlist` object of an app's macos.json (ios.json, tvos.json, watchos.json) into the
3
3
  // generated Info.plist, so an app can declare its own keys (for example
4
4
  // NSCalendarsFullAccessUsageDescription) without a per-app template. Each key
5
5
  // is written with `plutil -replace`, so values may be any JSON plutil accepts:
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key><string>en</string>
6
+ <key>CFBundleDisplayName</key><string>@APP_DISPLAY_NAME@</string>
7
+ <key>CFBundleExecutable</key><string>@APP_EXEC@</string>
8
+ <key>CFBundleIdentifier</key><string>@BUNDLE_ID@</string>
9
+ <key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
10
+ <key>CFBundleName</key><string>@APP_NAME@</string>
11
+ <key>CFBundleIconName</key><string>AppIcon</string>
12
+ <key>CFBundlePackageType</key><string>APPL</string>
13
+ <key>CFBundleShortVersionString</key><string>0.1.0</string>
14
+ <key>CFBundleVersion</key><string>1</string>
15
+ <key>WKApplication</key><true/>
16
+ <key>WKWatchOnly</key><true/>
17
+ </dict>
18
+ </plist>
@@ -0,0 +1,135 @@
1
+ # watchOS target
2
+
3
+ Build a gea-embedded JSX app as a watch-only Apple Watch app.
4
+
5
+ From an app that depends on `@geastack/apple` and declares
6
+ `gea.targets.watchos`, the CLI drives this target:
7
+
8
+ ```bash
9
+ npx gea build --target watchos # simulator .app, no launch
10
+ npx gea build --target watchos --mode device # watchos .app (unsigned without a team)
11
+ npx gea run --target watchos # build, install and launch on a watch simulator
12
+ npx gea run --target watchos --mode device # build, sign, install and launch on a watch
13
+ ```
14
+
15
+ The CLI runs `build-watchos.sh <app-id> simulator|device` from the app folder;
16
+ the script can be run directly the same way. Either way it needs a
17
+ `@geastack/cli` with watchOS support, which also builds the app icon
18
+ (`gea apps apple-icons --platform watchos`).
19
+
20
+ `counter-jsx` in the examples repository is the reference app for this target.
21
+
22
+ The script resolves `@geastack/core`, `@geastack/compiler` and `@geastack/cli`
23
+ by walking up `node_modules` from the app folder, as the iOS script does. Output
24
+ goes to `<app>/dist/watchos` (override with `GEA_WATCHOS_OUTPUT_DIR`); the Xcode
25
+ project is generated at `<app>/dist/watchos/<app-id>/GeaWatch.xcodeproj`. Do not
26
+ hand-edit it.
27
+
28
+ ## How it renders
29
+
30
+ watchOS gives an app no UIView hierarchy, so there is no native view renderer
31
+ like iOS has. The shell is a SwiftUI app (`main/watchos_app.swift`): gea lays
32
+ out and paints the whole UI into its RGBA8888 framebuffer, and the shell shows
33
+ each presented frame as an image covering the screen. Touches come back through
34
+ a drag gesture as gea touch events. Turning the Digital Crown scrolls the
35
+ first vertical scroll container, as the Up/Down buttons do on touchless boards;
36
+ `GeaWatchHost.crownPointsPerUnit` sets how far it moves. The Crown's range is
37
+ that container's scroll range, so the system Crown indicator shows the scroll
38
+ position, however the list was scrolled. The frame loop runs at 60 Hz while the app
39
+ is active and stops when the watch dims or the app goes to the background.
40
+
41
+ The C++ side (`main/watchos_host.mm`) reuses the iOS host backends for the
42
+ framebuffer, frame clock, allocator, touch state, CoreMotion and AVAudioEngine
43
+ audio, and drives CSS and `data-anim` animations each frame as the embedded
44
+ runtime loop does. `main/watchos_platform.mm` adds what is different on a
45
+ watch: battery level, charging state and haptics come from WatchKit, and the
46
+ camera reports itself unavailable, so camera apps build and a `<camera>`
47
+ renders nothing.
48
+
49
+ ## Sizing
50
+
51
+ The canvas is the panel's physical pixels. One CSS `px` is 1.5 physical pixels
52
+ by default, the ratio the ESP32 watch boards with the same panels (368x448,
53
+ 410x502) declare, so an app is the same size on either. That makes a 46mm watch
54
+ 277x331 CSS px and a 40mm SE 216x263. An app picks its own ratio with
55
+ `gea.targets.watchos.cssDevicePixelRatio` (an object target) or
56
+ `gea.cssDevicePixelRatio`; `GEA_WATCHOS_CSS_DEVICE_PIXEL_RATIO` overrides both
57
+ for one build. Font atlases are baked at the same ratio.
58
+
59
+ The canvas covers the whole screen, including the area under the system clock.
60
+ watchOS's safe area keeps about a fifth of the screen free at the top and
61
+ another at the bottom, which is too much to give up on a watch. Apps that need
62
+ the clock area clear lay themselves out around it, using the insets the shell
63
+ publishes as `:root` custom properties, in CSS px, measured for the watch it
64
+ runs on:
65
+
66
+ | Property | Meaning |
67
+ | --- | --- |
68
+ | `--gea-safe-top` | clears the system clock |
69
+ | `--gea-safe-left`, `--gea-safe-right` | how far the rounded corners cut in at that depth |
70
+ | `--gea-safe-bottom` | where the bottom corners cut in no further than the sides |
71
+ | `--gea-screen-radius` | how deep the corner curve runs |
72
+
73
+ Other targets don't set them, so read them with a fallback:
74
+ `padding-top: var(--gea-safe-top, 4px)`. The values come from a table in
75
+ `main/watchos_host.mm`, one row per panel size: corners from each Simulator
76
+ device type's `framebufferMask`, the clock measured from a blank app. A watch
77
+ with a new panel size gets the nearest row, scaled by height, until it has its
78
+ own.
79
+
80
+ ## Bluetooth and Info.plist keys
81
+
82
+ The host's Objective-C++ backends are compiled in, as on macOS: the
83
+ CoreBluetooth central (`bluetooth.central`), URLSession WebSockets, P-256 key
84
+ agreement and the Opus decoder. watchOS is central-only, so an app connects to
85
+ peripherals; it cannot advertise.
86
+
87
+ watchOS ends an app that touches Bluetooth without a usage description. Add the
88
+ keys an app needs to `watchos.json` next to its `package.json`. Its `infoPlist`
89
+ object is merged over the generated `Info.plist`, as with `macos.json`:
90
+
91
+ ```json
92
+ {
93
+ "infoPlist": {
94
+ "NSBluetoothAlwaysUsageDescription": "Connects to the bridge on your Mac."
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## Limits
100
+
101
+ - Runtime `gea` apps only. Apple SDK bindings (`@geastack/apple/UIKit` and the
102
+ rest) are not available: they drive UIKit views, and the build compiles with
103
+ `--no-apple-native`.
104
+ - No text input or virtual keyboard.
105
+ - Apps with their own ESP32 native code (`diagnostics`, `e-reader`,
106
+ `gea3d-cube`, `gea-bench`, `ttf-bench`), GPIO hardware (`headless-led`) or a
107
+ board-specific bitmap font (`m5-stopwatch`) do not build here.
108
+ - Only 40mm and larger watches are tested. Fixed-pixel layouts drawn for 245x299 (such as
109
+ `counter-jsx`) clip slightly on the 40mm SE.
110
+
111
+ ## Simulator and device
112
+
113
+ The simulator path picks a booted Apple Watch simulator, otherwise an Apple
114
+ Watch Series model. Set `GEA_WATCHOS_SIMULATOR_UDID` to choose one, and
115
+ `GEA_WATCHOS_OPEN_SIMULATOR=0` to leave the simulator window (Simulator.app, or DeviceHub.app on Xcode 27) closed.
116
+
117
+ Device builds go through the paired iPhone. Name the watch with
118
+ `GEA_WATCHOS_DEVICE_ID` (from `xcrun devicectl list devices`) and the team with
119
+ `GEA_WATCHOS_DEVELOPMENT_TEAM` (`GEA_IOS_DEVELOPMENT_TEAM` and Xcode's last
120
+ selected team also work):
121
+
122
+ ```bash
123
+ GEA_WATCHOS_DEVICE_ID=<id> GEA_WATCHOS_DEVELOPMENT_TEAM=ABCDE12345 npx gea run --target watchos --mode device
124
+ ```
125
+
126
+ `gea build --target watchos --mode device` without a team builds an unsigned
127
+ `watchos` binary, which is enough to check that the app compiles for hardware.
128
+
129
+ ## Test
130
+
131
+ `test/run-watchos-counter-ui-test.sh <path/to/examples/apps/counter-jsx>` builds
132
+ the counter for a watch simulator and runs `GeaWatchCounterUITests`. The test
133
+ checks that tapping `+` repaints the counter and that a tap on empty background
134
+ changes nothing. The test files only exist in a checkout of this repository. The
135
+ generator adds the UI-test target when it finds them.
@@ -0,0 +1,258 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ WATCHOS_DIR="$ROOT_DIR/targets/watchos"
6
+
7
+ # The project is the directory this script was started in, as for iOS: the app
8
+ # folder, which every nested `gea` call resolves from too.
9
+ BUILD_INVOCATION_CWD="$(pwd -P)"
10
+
11
+ # Resolve the gea framework through npm the way build-ios.sh does: walk the
12
+ # node_modules chain from the app first (a hoisted install), then from this
13
+ # package (a linked checkout).
14
+ resolve_gea_package_from() {
15
+ node -e '
16
+ const fs = require("node:fs")
17
+ const path = require("node:path")
18
+ let dir = process.argv[1]
19
+ while (true) {
20
+ const candidate = path.join(dir, "node_modules", process.argv[2])
21
+ if (fs.existsSync(path.join(candidate, "package.json"))) {
22
+ process.stdout.write(fs.realpathSync(candidate))
23
+ break
24
+ }
25
+ const parent = path.dirname(dir)
26
+ if (parent === dir) break
27
+ dir = parent
28
+ }
29
+ ' "$1" "$2" 2>/dev/null || true
30
+ }
31
+ resolve_gea_package() {
32
+ local start found
33
+ for start in "$BUILD_INVOCATION_CWD" "$ROOT_DIR"; do
34
+ found="$(resolve_gea_package_from "$start" "$1")"
35
+ if [[ -n "$found" ]]; then
36
+ printf '%s' "$found"
37
+ return 0
38
+ fi
39
+ done
40
+ }
41
+ GEA_CORE="$(resolve_gea_package @geastack/core)"
42
+ [ -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; }
43
+ GEA_COMPILER="$(resolve_gea_package @geastack/compiler)"
44
+ [ -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; }
45
+ GEA_HOST_DIR="${GEA_HOST_DIR:-$GEA_CORE/../host}"
46
+ GEA_ENGINE_DIR="${GEA_ENGINE_DIR:-$GEA_CORE/../engine}"
47
+ GEA_ELEMENTS_DIR="${GEA_ELEMENTS_DIR:-$GEA_CORE/../elements}"
48
+ GEA_GEAOS_PACKAGE_DIR="${GEA_GEAOS_PACKAGE_DIR:-$GEA_CORE/../geaos}"
49
+ # gea_sources.mjs runs as a child process and reads these from the environment.
50
+ export GEA_CORE GEA_HOST_DIR GEA_ENGINE_DIR GEA_ELEMENTS_DIR GEA_GEAOS_PACKAGE_DIR
51
+ GEA_CLI="${GEA_CLI_BIN:-}"
52
+ if [[ -z "$GEA_CLI" ]]; then
53
+ GEA_CLI="$(node -e 'process.stdout.write(require("path").join(process.argv[1], "bin", "gea.mjs"))' "$(resolve_gea_package @geastack/cli)" 2>/dev/null || true)"
54
+ if [[ ! -f "$GEA_CLI" ]]; then
55
+ GEA_CLI="$(command -v gea || true)"
56
+ fi
57
+ fi
58
+ [ -n "$GEA_CLI" ] && [ -f "$GEA_CLI" ] || { echo "Cannot locate GeaStack CLI — set GEA_CLI_BIN to gea.mjs, install @geastack/cli locally, or add gea to PATH" >&2; exit 1; }
59
+
60
+ # Framework sources from the shared manifest, curated like iOS: no OTA or
61
+ # diagnostics services, no single-app runtime shell -- SwiftUI owns the run
62
+ # loop. The camera bridge stays: watchos_platform.mm answers it with "no camera".
63
+ # shellcheck source=/dev/null
64
+ source "$GEA_CORE/gea_sources.sh"
65
+ export GEA_FW_CXX_SOURCES="$(gea_fw_cxx_sources | grep -vE "/(runtime|services/[a-z_]+)\.cpp\$")"
66
+ export GEA_FW_C_SOURCES="$(gea_fw_c_sources)"
67
+ export GEA_FW_INCLUDE_DIRS="$(gea_fw_include_flags | sed "s/^-I//")"
68
+ # The Objective-C++ host backends: CoreBluetooth central (navigator.bluetooth.central),
69
+ # URLSession WebSocket, Security P-256, AudioToolbox Opus and the data directory.
70
+ export GEA_FW_OBJCXX_SOURCES="$(gea_fw_objcxx_sources)"
71
+ APP_ID="${1:-counter-jsx}"
72
+ DESTINATION="${2:-simulator}"
73
+
74
+ if [[ "$DESTINATION" != "simulator" && "$DESTINATION" != "device" ]]; then
75
+ echo "usage: targets/watchos/build-watchos.sh [app-id] [simulator|device]" >&2
76
+ exit 2
77
+ fi
78
+
79
+ APP_INFO="$(node "$GEA_CLI" apps inspect "$APP_ID" --format shell)" || {
80
+ echo "Unknown app id: $APP_ID" >&2
81
+ exit 1
82
+ }
83
+
84
+ IFS=$'\t' read -r APP_ROOT APP_ENTRY APP_RUNTIME APP_DISPLAY_NAME <<< "$APP_INFO"
85
+ if [[ "$APP_RUNTIME" != "gea" ]]; then
86
+ echo "watchOS target only supports runtime=gea apps: $APP_ID is runtime=$APP_RUNTIME" >&2
87
+ exit 1
88
+ fi
89
+ APP_NAME="$(node -e "
90
+ const raw = process.argv[1] || process.argv[2];
91
+ console.log(raw.replace(/(^|[-_\\s])([a-z])/g, (_, p, c) => c.toUpperCase()).replace(/[-_\\s]+/g, ''));
92
+ " "$APP_DISPLAY_NAME" "$APP_ID")"
93
+ BUNDLE_ID="${GEA_WATCHOS_BUNDLE_IDENTIFIER:-com.gea.watch.${APP_ID//[^A-Za-z0-9]/-}}"
94
+ # Output belongs to the app being built, never to this package (see build-ios.sh).
95
+ WATCHOS_OUTPUT_ROOT="${GEA_WATCHOS_OUTPUT_DIR:-$BUILD_INVOCATION_CWD/dist/watchos}"
96
+ case "$WATCHOS_OUTPUT_ROOT" in
97
+ /*) ;;
98
+ *) WATCHOS_OUTPUT_ROOT="$(pwd -P)/$WATCHOS_OUTPUT_ROOT" ;;
99
+ esac
100
+ GENERATED_DIR="$WATCHOS_OUTPUT_ROOT/.generated/$APP_ID"
101
+ PROJECT_PATH="$WATCHOS_OUTPUT_ROOT/$APP_ID/GeaWatch.xcodeproj"
102
+ DERIVED_DATA="$WATCHOS_OUTPUT_ROOT/.derived-data/$APP_ID-$DESTINATION"
103
+ CONFIGURATION="${GEA_WATCHOS_CONFIGURATION:-Debug}"
104
+ SKIP_LAUNCH="${GEA_WATCHOS_SKIP_LAUNCH:-0}"
105
+
106
+ mkdir -p "$GENERATED_DIR"
107
+
108
+ # How many physical pixels one CSS px covers. Apple Watch panels are the same
109
+ # class as the ESP32 watch boards (368x448, 410x502 ...), which declare 1.5, so
110
+ # an app looks the same size on either. An app overrides it the way the CLI's
111
+ # build config reads it: gea.targets.watchos.cssDevicePixelRatio, then
112
+ # gea.cssDevicePixelRatio.
113
+ CSS_DEVICE_PIXEL_RATIO="${GEA_WATCHOS_CSS_DEVICE_PIXEL_RATIO:-$(node -e '
114
+ const gea = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).gea || {}
115
+ const target = gea.targets && typeof gea.targets.watchos === "object" ? gea.targets.watchos : {}
116
+ const ratio = Number(target.cssDevicePixelRatio || gea.cssDevicePixelRatio || 1.5)
117
+ process.stdout.write(String(ratio > 0 ? ratio : 1.5))
118
+ ' "$APP_ROOT/package.json")}"
119
+
120
+ # Bake glyph atlases at the layout ratio, and give vw/vh-sized text the
121
+ # physical panel sizes of current watches (40mm SE .. 49mm Ultra 3).
122
+ build_font_args=(
123
+ --font-device-pixel-ratio "${GEA_WATCHOS_FONT_DEVICE_PIXEL_RATIOS:-$CSS_DEVICE_PIXEL_RATIO}"
124
+ --font-viewport-width "${GEA_WATCHOS_FONT_VIEWPORT_WIDTHS:-324,352,368,374,396,410,416,422}"
125
+ --font-viewport-height "${GEA_WATCHOS_FONT_VIEWPORT_HEIGHTS:-394,430,446,448,484,496,502,514}"
126
+ )
127
+
128
+ # watchOS has no UIView tree for the Apple SDK bindings to drive, so apps are
129
+ # compiled without them (no native bridge, no apple-native geatsc plugin).
130
+ args=(
131
+ --no-apple-native
132
+ --app-dir "$APP_ROOT"
133
+ --entry "$APP_ENTRY"
134
+ --out-dir "$GENERATED_DIR"
135
+ "${build_font_args[@]}"
136
+ )
137
+ if [[ -f "$APP_ROOT/watchos/geatsc-native-plugin.mjs" ]]; then
138
+ args+=(--extra-geatsc-plugin "$APP_ROOT/watchos/geatsc-native-plugin.mjs")
139
+ fi
140
+ node "$GEA_CORE/scripts/build-gea-vite-geatsc.mjs" "${args[@]}"
141
+
142
+ if [[ ! -f "$GENERATED_DIR/gea_runtime.cpp" ]]; then
143
+ echo "#include \"$GEA_COMPILER/dist/targets/cpp/runtime/runtime.cpp\"" > "$GENERATED_DIR/gea_runtime.cpp"
144
+ fi
145
+
146
+ GEA_CLI_BIN="$GEA_CLI" node "$WATCHOS_DIR/generate-xcode-project.mjs" \
147
+ --app-id "$APP_ID" \
148
+ --app-name "$APP_NAME" \
149
+ --display-name "$APP_DISPLAY_NAME" \
150
+ --bundle-id "$BUNDLE_ID" \
151
+ --css-device-pixel-ratio "$CSS_DEVICE_PIXEL_RATIO" \
152
+ --generated-dir "$GENERATED_DIR" \
153
+ --project-path "$PROJECT_PATH"
154
+
155
+ # Picks a booted Apple Watch simulator, else a mid-size Series model: the
156
+ # 40mm SE is smaller than most gea layouts are drawn for.
157
+ pick_simulator_device() {
158
+ local devices_json
159
+ devices_json="$(xcrun simctl list devices available --json 2>/dev/null || true)"
160
+ [[ -z "$devices_json" ]] && return 0
161
+ node -e "
162
+ const data = JSON.parse(require('fs').readFileSync(0, 'utf8'));
163
+ const watches = Object.entries(data.devices || {})
164
+ .filter(([runtime]) => /watchOS/.test(runtime))
165
+ .flatMap(([, list]) => list)
166
+ .filter((d) => d.isAvailable && /^Apple Watch/.test(d.name));
167
+ const preferred = watches.find((d) => d.state === 'Booted') || watches.find((d) => /Series/.test(d.name)) || watches[0];
168
+ if (preferred) console.log(preferred.udid);
169
+ " <<< "$devices_json"
170
+ }
171
+
172
+ show_simulator_device() {
173
+ [[ "${GEA_WATCHOS_OPEN_SIMULATOR:-1}" == "1" ]] || return 0
174
+ # Only a convenience: the device boots, installs and launches without the
175
+ # GUI. Xcode 27 replaced Simulator.app with DeviceHub.app (bundle id
176
+ # com.apple.dt.Devices), which shows every booted simulator.
177
+ /usr/bin/open -a Simulator --args -CurrentDeviceUDID "$1" 2>/dev/null ||
178
+ /usr/bin/open -b com.apple.dt.Devices 2>/dev/null ||
179
+ echo "Could not open Simulator.app or DeviceHub.app; the simulator runs without a window." >&2
180
+ }
181
+
182
+ SDK="watchsimulator"
183
+ XCODE_DESTINATION="${GEA_WATCHOS_SIMULATOR_DESTINATION:-generic/platform=watchOS Simulator}"
184
+ SIMULATOR_DEVICE_ID="${GEA_WATCHOS_SIMULATOR_UDID:-}"
185
+ EXTRA_BUILD_SETTINGS=()
186
+ EXTRA_XCODEBUILD_ARGS=()
187
+ WATCH_DEVICE_ID="${GEA_WATCHOS_DEVICE_ID:-}"
188
+ if [[ "$DESTINATION" == "simulator" && "$SKIP_LAUNCH" != "1" && -z "$SIMULATOR_DEVICE_ID" ]]; then
189
+ SIMULATOR_DEVICE_ID="$(pick_simulator_device)"
190
+ if [[ -z "$SIMULATOR_DEVICE_ID" ]]; then
191
+ echo "No available Apple Watch simulator found. Add one in Xcode > Window > Devices and Simulators." >&2
192
+ exit 1
193
+ fi
194
+ fi
195
+ if [[ "$DESTINATION" == "simulator" && -n "$SIMULATOR_DEVICE_ID" && -z "${GEA_WATCHOS_SIMULATOR_DESTINATION:-}" ]]; then
196
+ XCODE_DESTINATION="platform=watchOS Simulator,id=$SIMULATOR_DEVICE_ID"
197
+ fi
198
+ if [[ "$DESTINATION" == "device" ]]; then
199
+ SDK="watchos"
200
+ XCODE_DESTINATION="${GEA_WATCHOS_DEVICE_DESTINATION:-generic/platform=watchOS}"
201
+ # A watch is reached through its paired iPhone, so there is no reliable way
202
+ # to pick one automatically: name it with GEA_WATCHOS_DEVICE_ID (the
203
+ # identifier `xcrun devicectl list devices` prints) to install and launch.
204
+ if [[ -z "$WATCH_DEVICE_ID" && "$SKIP_LAUNCH" != "1" ]]; then
205
+ echo "Set GEA_WATCHOS_DEVICE_ID to the watch's identifier from 'xcrun devicectl list devices' to install and launch," >&2
206
+ echo "or GEA_WATCHOS_SKIP_LAUNCH=1 to only build." >&2
207
+ exit 1
208
+ fi
209
+ DEVELOPMENT_TEAM="${GEA_WATCHOS_DEVELOPMENT_TEAM:-${GEA_IOS_DEVELOPMENT_TEAM:-}}"
210
+ if [[ -z "$DEVELOPMENT_TEAM" && "$SKIP_LAUNCH" != "1" ]]; then
211
+ if DEVELOPMENT_TEAM="$(node "$ROOT_DIR/targets/ios/detect-development-team.mjs")"; then
212
+ echo "Using Xcode development team $DEVELOPMENT_TEAM. Override with GEA_WATCHOS_DEVELOPMENT_TEAM." >&2
213
+ else
214
+ DEVELOPMENT_TEAM=""
215
+ fi
216
+ fi
217
+ if [[ -z "$DEVELOPMENT_TEAM" ]]; then
218
+ if [[ "$SKIP_LAUNCH" != "1" ]]; then
219
+ echo "Device builds require GEA_WATCHOS_DEVELOPMENT_TEAM for Xcode automatic signing." >&2
220
+ exit 1
221
+ fi
222
+ echo "GEA_WATCHOS_DEVELOPMENT_TEAM is not set; building an unsigned watchos binary." >&2
223
+ EXTRA_BUILD_SETTINGS+=("CODE_SIGNING_ALLOWED=NO" "CODE_SIGNING_REQUIRED=NO" "CODE_SIGN_IDENTITY=")
224
+ else
225
+ EXTRA_BUILD_SETTINGS+=("DEVELOPMENT_TEAM=$DEVELOPMENT_TEAM" "CODE_SIGN_STYLE=Automatic")
226
+ if [[ "${GEA_WATCHOS_ALLOW_PROVISIONING_UPDATES:-1}" == "1" ]]; then
227
+ EXTRA_XCODEBUILD_ARGS+=("-allowProvisioningUpdates")
228
+ fi
229
+ fi
230
+ fi
231
+
232
+ xcodebuild \
233
+ ${EXTRA_XCODEBUILD_ARGS[@]+"${EXTRA_XCODEBUILD_ARGS[@]}"} \
234
+ -project "$PROJECT_PATH" \
235
+ -scheme GeaWatch \
236
+ -configuration "$CONFIGURATION" \
237
+ -sdk "$SDK" \
238
+ -destination "$XCODE_DESTINATION" \
239
+ -derivedDataPath "$DERIVED_DATA" \
240
+ PRODUCT_BUNDLE_IDENTIFIER="$BUNDLE_ID" \
241
+ ${EXTRA_BUILD_SETTINGS[@]+"${EXTRA_BUILD_SETTINGS[@]}"} \
242
+ build
243
+
244
+ APP_PRODUCT="$DERIVED_DATA/Build/Products/$CONFIGURATION-$SDK/$APP_NAME.app"
245
+ echo "Built $APP_PRODUCT"
246
+
247
+ [[ "$SKIP_LAUNCH" == "1" ]] && exit 0
248
+
249
+ if [[ "$DESTINATION" == "simulator" ]]; then
250
+ show_simulator_device "$SIMULATOR_DEVICE_ID"
251
+ xcrun simctl boot "$SIMULATOR_DEVICE_ID" >/dev/null 2>&1 || true
252
+ xcrun simctl bootstatus "$SIMULATOR_DEVICE_ID" -b >/dev/null || true
253
+ xcrun simctl install "$SIMULATOR_DEVICE_ID" "$APP_PRODUCT"
254
+ xcrun simctl launch "$SIMULATOR_DEVICE_ID" "$BUNDLE_ID"
255
+ else
256
+ xcrun devicectl --timeout "${GEA_WATCHOS_DEVICECTL_TIMEOUT:-120}" device install app --device "$WATCH_DEVICE_ID" "$APP_PRODUCT"
257
+ xcrun devicectl --timeout "${GEA_WATCHOS_DEVICECTL_TIMEOUT:-120}" device process launch --terminate-existing --device "$WATCH_DEVICE_ID" "$BUNDLE_ID"
258
+ fi