peachsim 0.1.687 → 0.1.689
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/cli/cloud-client.ts +3 -3
- package/cli/command-registry.ts +2 -0
- package/cli/commands/control.ts +1 -0
- package/cli/commands/debug.ts +10 -33
- package/cli/commands/do-chain.ts +56 -6
- package/cli/commands/inspect/core.ts +2 -0
- package/cli/commands/inspect/list.ts +2 -1
- package/cli/commands/inspect/settling.ts +17 -3
- package/cli/commands/inspect/shared.ts +2 -0
- package/cli/commands/inspect/wait-idle.ts +2 -2
- package/cli/commands/inspect/wait-ready.ts +3 -3
- package/cli/commands/inspect.ts +33 -7
- package/cli/commands/location.ts +164 -0
- package/cli/commands/platform.ts +1 -1
- package/cli/drivers/playwright-sim-host.ts +46 -25
- package/cli/main.ts +6 -0
- package/detox/index.ts +13 -8
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +4 -3
- package/dist-lib/bridge-contract-input.cjs +12 -1
- package/dist-lib/bridge-contract-input.mjs +12 -1
- package/dist-lib/bridge-contract.cjs +4 -3
- package/dist-lib/bridge-contract.mjs +4 -3
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +2 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +2 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1197 -65
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +362 -108
- package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
- package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +29 -11
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +89 -13
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +5 -3
- package/dist-lib/native-app-identity.cjs +8 -3
- package/dist-lib/native-app-identity.mjs +8 -3
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +21 -6
- package/dist-lib/sdk.mjs +21 -6
- package/dist-lib/skills.cjs +401 -130
- package/dist-lib/swift-compile.cjs +277 -22
- package/dist-lib/swift-compile.mjs +275 -22
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +10 -10
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +280 -44
- package/dist-lib/vite.cjs +1 -1
- package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
- package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
- package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
- package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
- package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
- package/package.json +2 -2
- package/scripts/dev-server-scanner.ts +3 -1
- package/skills/contrast/SKILL.md +1 -0
- package/src/android-drawables.ts +315 -0
- package/src/android-theme.ts +9 -0
- package/src/bridge-constants.ts +3 -2
- package/src/bridge-contract-input.ts +11 -0
- package/src/bridge-contract.ts +45 -3
- package/src/cloud-contract.ts +1 -0
- package/src/host/fetch-proxy-handler.ts +13 -49
- package/src/host/fetch-proxy-overrides.ts +69 -12
- package/src/kotlin-app.ts +6 -0
- package/src/kotlin-host.ts +103 -15
- package/src/native-app-identity.ts +16 -3
- package/src/swift-compile.ts +366 -24
- package/src/swift-distribution-contract.ts +11 -4
- package/src/swift-distribution.lock.json +11 -9
- package/src/swift-distribution.ts +4 -4
- package/src/swift-icu.ts +8 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +17 -9
- package/src/vite-plugin.ts +86 -34
package/src/bridge-contract.ts
CHANGED
|
@@ -40,6 +40,7 @@ export type BridgeCommandType =
|
|
|
40
40
|
| 'resolve'
|
|
41
41
|
| 'reset'
|
|
42
42
|
| 'camera'
|
|
43
|
+
| 'location'
|
|
43
44
|
| 'diagnostics'
|
|
44
45
|
| 'storageSnapshot'
|
|
45
46
|
|
|
@@ -109,6 +110,8 @@ export interface WsCommand {
|
|
|
109
110
|
resetOptions?: ResetOptions
|
|
110
111
|
// camera — fixture injection into the host camera pipeline
|
|
111
112
|
camera?: CameraCommand
|
|
113
|
+
// location — the simulated device location (simctl location equivalent)
|
|
114
|
+
location?: LocationCommand
|
|
112
115
|
// diagnostics — read-only engine debug state: channel recording, the sheet /
|
|
113
116
|
// portal / boundary finders, and the recent event ring.
|
|
114
117
|
diagnostics?: DiagnosticsOptions
|
|
@@ -172,6 +175,7 @@ export type PerformStep =
|
|
|
172
175
|
}
|
|
173
176
|
| { type: 'scroll'; id: string; x?: number; y?: number; animated?: boolean }
|
|
174
177
|
| { type: 'type'; text: string }
|
|
178
|
+
| { type: 'typeInto'; text: string; nodeId: number }
|
|
175
179
|
| { type: 'key'; key: string }
|
|
176
180
|
| { type: 'dismissKeyboard' }
|
|
177
181
|
| { type: 'wait'; ms: number }
|
|
@@ -289,6 +293,7 @@ export function performStepRefusal(type: PerformStep['type']): string | null {
|
|
|
289
293
|
case 'pinch':
|
|
290
294
|
case 'scroll':
|
|
291
295
|
case 'type':
|
|
296
|
+
case 'typeInto':
|
|
292
297
|
case 'key':
|
|
293
298
|
case 'dismissKeyboard':
|
|
294
299
|
case 'setElementValue':
|
|
@@ -348,6 +353,7 @@ export interface SemanticReadyProbe {
|
|
|
348
353
|
nodes: number
|
|
349
354
|
targets: number
|
|
350
355
|
liveFrameActive: boolean
|
|
356
|
+
browserSurfaceCount: number
|
|
351
357
|
liveFrameChannels: number
|
|
352
358
|
liveFramePublishes: number
|
|
353
359
|
errors: number
|
|
@@ -373,9 +379,10 @@ export const HEADLESS_TENANT_FETCH_HUNG_MARKER = 'headless tenant fetch hung'
|
|
|
373
379
|
|
|
374
380
|
export function readyProbeHasContent(
|
|
375
381
|
probe: Pick<SemanticReadyProbe, 'nodes' | 'targets'> &
|
|
376
|
-
Partial<Pick<SemanticReadyProbe, 'liveFrameActive'>>,
|
|
382
|
+
Partial<Pick<SemanticReadyProbe, 'liveFrameActive' | 'browserSurfaceCount'>>,
|
|
377
383
|
): boolean {
|
|
378
384
|
return (
|
|
385
|
+
(probe.browserSurfaceCount ?? 0) > 0 ||
|
|
379
386
|
probe.liveFrameActive ||
|
|
380
387
|
probe.targets > 0 ||
|
|
381
388
|
probe.nodes >= SEMANTIC_READY_CONTENT_NODE_FLOOR
|
|
@@ -384,9 +391,11 @@ export function readyProbeHasContent(
|
|
|
384
391
|
|
|
385
392
|
export function readyProbeHasTargetContent(
|
|
386
393
|
probe: Pick<SemanticReadyProbe, 'targets'> &
|
|
387
|
-
Partial<Pick<SemanticReadyProbe, 'liveFrameActive'>>,
|
|
394
|
+
Partial<Pick<SemanticReadyProbe, 'liveFrameActive' | 'browserSurfaceCount'>>,
|
|
388
395
|
): boolean {
|
|
389
|
-
return
|
|
396
|
+
return (
|
|
397
|
+
(probe.browserSurfaceCount ?? 0) > 0 || probe.liveFrameActive || probe.targets > 0
|
|
398
|
+
)
|
|
390
399
|
}
|
|
391
400
|
|
|
392
401
|
// one probe shows a ready app: it has said so with content behind it, or it
|
|
@@ -605,3 +614,36 @@ export interface CameraResult {
|
|
|
605
614
|
rate?: number
|
|
606
615
|
error?: string
|
|
607
616
|
}
|
|
617
|
+
|
|
618
|
+
// ---------------------------------------------------------------------------
|
|
619
|
+
// location — simulated device location (simctl location equivalent)
|
|
620
|
+
// ---------------------------------------------------------------------------
|
|
621
|
+
|
|
622
|
+
// the host thread owns the simulated location, matching iOS: a device has one
|
|
623
|
+
// current location regardless of how many apps watch it. tenant and shell
|
|
624
|
+
// workers reach it through the same host-service geolocation seam that used
|
|
625
|
+
// to forward to the host browser's real navigator.geolocation (leaking the
|
|
626
|
+
// operator's real position). a cleared device reports iOS's own default, not
|
|
627
|
+
// an empty/pending state invented here.
|
|
628
|
+
export interface LocationFix {
|
|
629
|
+
latitude: number
|
|
630
|
+
longitude: number
|
|
631
|
+
altitude?: number
|
|
632
|
+
accuracy?: number
|
|
633
|
+
heading?: number
|
|
634
|
+
speed?: number
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export type LocationCommand =
|
|
638
|
+
| ({ action: 'set' } & LocationFix)
|
|
639
|
+
| { action: 'clear' }
|
|
640
|
+
| { action: 'get' }
|
|
641
|
+
|
|
642
|
+
export interface LocationResult {
|
|
643
|
+
ok: boolean
|
|
644
|
+
// 'custom' = an app or `peach location set` chose this fix, 'default' = iOS's
|
|
645
|
+
// own un-set simulator location
|
|
646
|
+
source: 'custom' | 'default'
|
|
647
|
+
fix?: LocationFix
|
|
648
|
+
error?: string
|
|
649
|
+
}
|
package/src/cloud-contract.ts
CHANGED
|
@@ -77,6 +77,7 @@ export const RNX_CLOUD_COMMAND_SCOPES = {
|
|
|
77
77
|
flowStatus: 'drive',
|
|
78
78
|
reset: 'reset',
|
|
79
79
|
camera: 'media',
|
|
80
|
+
location: 'media',
|
|
80
81
|
// string evaluation and arbitrary bridge calls are maestro's boundary: the
|
|
81
82
|
// customer sdk never carries this scope, and the service grants it only to
|
|
82
83
|
// the account api key caller. close rides along, since ending the page ends
|
|
@@ -28,8 +28,8 @@ import https from 'https'
|
|
|
28
28
|
import { finished, pipeline } from 'stream/promises'
|
|
29
29
|
import { isLoopbackHost, normalizeHostname } from '../backend-origin.ts'
|
|
30
30
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
buildFetchProxyUpstreamHeaders,
|
|
32
|
+
nodeRequestHeaderEntries,
|
|
33
33
|
resolveFetchProxyTargetUrl,
|
|
34
34
|
} from './fetch-proxy-overrides.ts'
|
|
35
35
|
|
|
@@ -50,27 +50,6 @@ function fetchProxyAgentFor(targetUrl: URL): http.Agent | https.Agent {
|
|
|
50
50
|
return targetUrl.protocol === 'https:' ? fetchProxyHttpsAgent : fetchProxyHttpAgent
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const STRIP_FETCH_PROXY_HEADERS = new Set([
|
|
54
|
-
'host',
|
|
55
|
-
'origin',
|
|
56
|
-
'referer',
|
|
57
|
-
'user-agent',
|
|
58
|
-
'accept-encoding',
|
|
59
|
-
'cookie',
|
|
60
|
-
'connection',
|
|
61
|
-
'keep-alive',
|
|
62
|
-
'transfer-encoding',
|
|
63
|
-
'upgrade',
|
|
64
|
-
'content-length',
|
|
65
|
-
'sec-fetch-site',
|
|
66
|
-
'sec-fetch-mode',
|
|
67
|
-
'sec-fetch-dest',
|
|
68
|
-
'sec-ch-ua',
|
|
69
|
-
'sec-ch-ua-mobile',
|
|
70
|
-
'sec-ch-ua-platform',
|
|
71
|
-
FETCH_PROXY_NATIVE_USER_AGENT_HEADER,
|
|
72
|
-
])
|
|
73
|
-
|
|
74
53
|
const FETCH_PROXY_CORS_HEADERS: Record<string, string> = {
|
|
75
54
|
'access-control-allow-origin': '*',
|
|
76
55
|
'access-control-allow-methods': 'GET,POST,PUT,DELETE,PATCH,OPTIONS',
|
|
@@ -108,21 +87,7 @@ export function buildFetchProxyHeaders(
|
|
|
108
87
|
reqHeaders: Record<string, string | string[] | undefined>,
|
|
109
88
|
targetUrl?: URL,
|
|
110
89
|
): Record<string, string> {
|
|
111
|
-
|
|
112
|
-
for (const [key, value] of Object.entries(reqHeaders)) {
|
|
113
|
-
if (!value) continue
|
|
114
|
-
if (STRIP_FETCH_PROXY_HEADERS.has(key.toLowerCase())) continue
|
|
115
|
-
headers[key] = Array.isArray(value) ? value.join(', ') : value
|
|
116
|
-
}
|
|
117
|
-
const rawNativeUserAgent = reqHeaders[FETCH_PROXY_NATIVE_USER_AGENT_HEADER]
|
|
118
|
-
const nativeUserAgent = Array.isArray(rawNativeUserAgent)
|
|
119
|
-
? rawNativeUserAgent[0]
|
|
120
|
-
: rawNativeUserAgent
|
|
121
|
-
Object.assign(
|
|
122
|
-
headers,
|
|
123
|
-
targetUrl ? getFetchProxyTargetHeaders(targetUrl, nativeUserAgent) : {},
|
|
124
|
-
)
|
|
125
|
-
return headers
|
|
90
|
+
return buildFetchProxyUpstreamHeaders(nodeRequestHeaderEntries(reqHeaders), targetUrl)
|
|
126
91
|
}
|
|
127
92
|
|
|
128
93
|
export function buildAppApiProxyHeaders(
|
|
@@ -188,17 +153,6 @@ export async function handleFetchProxyRequest(
|
|
|
188
153
|
return
|
|
189
154
|
}
|
|
190
155
|
|
|
191
|
-
let body: Buffer | undefined
|
|
192
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
193
|
-
const chunks: Buffer[] = []
|
|
194
|
-
for await (const chunk of req) {
|
|
195
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
|
|
196
|
-
}
|
|
197
|
-
if (chunks.length > 0) {
|
|
198
|
-
body = Buffer.concat(chunks)
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
156
|
const originalMethod = req.method || 'GET'
|
|
203
157
|
const proxy = async (
|
|
204
158
|
targetUrl: URL,
|
|
@@ -300,7 +254,17 @@ export async function handleFetchProxyRequest(
|
|
|
300
254
|
await pipeline(proxyRes, res)
|
|
301
255
|
}
|
|
302
256
|
|
|
257
|
+
let body: Buffer | undefined
|
|
303
258
|
try {
|
|
259
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
260
|
+
const chunks: Buffer[] = []
|
|
261
|
+
for await (const chunk of req) {
|
|
262
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
|
|
263
|
+
}
|
|
264
|
+
if (chunks.length > 0) {
|
|
265
|
+
body = Buffer.concat(chunks)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
304
268
|
await proxy(upstreamUrl, originalMethod, body, 0)
|
|
305
269
|
} catch (err) {
|
|
306
270
|
const norm = normalizeHostname(upstreamUrl.hostname)
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// shared upstream header policy for
|
|
1
|
+
// shared upstream header policy for Peach's CORS-bypassing fetch proxy.
|
|
2
2
|
// requests still forward tenant auth and app headers, but the proxy transport
|
|
3
3
|
// defaults to native-app semantics: no browser Origin, Referer, Sec-Fetch-*.
|
|
4
|
-
// the User-Agent an NSURLSession request on a real device sends is
|
|
5
|
-
//
|
|
6
|
-
// browser string; the engine computes
|
|
7
|
-
//
|
|
8
|
-
// header, since `fetch()` cannot set `User-Agent` itself (forbidden header
|
|
4
|
+
// the User-Agent an NSURLSession request on a real device sends is CFNetwork's
|
|
5
|
+
// default (`<CFBundleName>/<CFBundleVersion> CFNetwork/<cf> Darwin/<darwin>`),
|
|
6
|
+
// never a browser string; the engine computes it from the app identity
|
|
7
|
+
// (packages/peach-engine/src/ios/native-user-agent.ts) and hands it to the
|
|
8
|
+
// proxy through this header, since `fetch()` cannot set `User-Agent` itself (forbidden header
|
|
9
9
|
// name). web-backed mobile APIs that require a specific web origin opt in
|
|
10
10
|
// below.
|
|
11
11
|
|
|
12
12
|
// the engine attaches the native-shaped User-Agent it computed under this
|
|
13
13
|
// name; the proxy moves it onto the real `user-agent` header and never lets
|
|
14
|
-
// the name itself reach upstream (see
|
|
14
|
+
// the name itself reach upstream (see buildFetchProxyUpstreamHeaders).
|
|
15
15
|
export const FETCH_PROXY_NATIVE_USER_AGENT_HEADER = 'x-sootsim-native-user-agent'
|
|
16
16
|
|
|
17
17
|
const HOST_HEADER_OVERRIDES: Array<{
|
|
@@ -82,14 +82,71 @@ export function resolveFetchProxyTargetUrl(requested: URL): URL {
|
|
|
82
82
|
return replacement ? new URL(replacement) : requested
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
// browser-context and hop headers a native NSURLSession request never sends.
|
|
86
|
+
// the inbound reverse-proxy hop headers (x-forwarded-*, x-real-ip, forwarded)
|
|
87
|
+
// describe the browser→proxy hop: Clerk's FAPI attributes a request to an
|
|
88
|
+
// instance via x-forwarded-host and rejects a foreign one as "Invalid host",
|
|
89
|
+
// and the client-ip variants would leak the viewer's IP.
|
|
90
|
+
const STRIP_FETCH_PROXY_REQUEST_HEADERS = new Set([
|
|
91
|
+
'host',
|
|
92
|
+
'x-forwarded',
|
|
93
|
+
'x-real-ip',
|
|
94
|
+
'forwarded',
|
|
95
|
+
'origin',
|
|
96
|
+
'referer',
|
|
97
|
+
'user-agent',
|
|
98
|
+
'accept-encoding',
|
|
99
|
+
'cookie',
|
|
100
|
+
'connection',
|
|
101
|
+
'keep-alive',
|
|
102
|
+
'transfer-encoding',
|
|
103
|
+
'upgrade',
|
|
104
|
+
'content-length',
|
|
105
|
+
'sec-fetch-site',
|
|
106
|
+
'sec-fetch-mode',
|
|
107
|
+
'sec-fetch-dest',
|
|
108
|
+
'sec-ch-ua',
|
|
109
|
+
'sec-ch-ua-mobile',
|
|
110
|
+
'sec-ch-ua-platform',
|
|
111
|
+
FETCH_PROXY_NATIVE_USER_AGENT_HEADER,
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
// the one upstream request header policy every fetch-proxy receiver applies
|
|
115
|
+
// (the local dev/daemon handler, the hosted Contrast /__proxy, the demo
|
|
116
|
+
// gateway), so they cannot diverge: forward app headers, drop browser and hop
|
|
117
|
+
// headers and the carrier, and move the carrier's native User-Agent onto
|
|
118
|
+
// `user-agent`. header names arrive lowercased from both node and fetch.
|
|
119
|
+
export function buildFetchProxyUpstreamHeaders(
|
|
120
|
+
requestHeaders: Iterable<readonly [string, string]>,
|
|
121
|
+
targetUrl?: URL,
|
|
88
122
|
): Record<string, string> {
|
|
89
|
-
const
|
|
123
|
+
const headers: Record<string, string> = {}
|
|
124
|
+
let nativeUserAgent: string | undefined
|
|
125
|
+
for (const [rawKey, value] of requestHeaders) {
|
|
126
|
+
const key = rawKey.toLowerCase()
|
|
127
|
+
if (key === FETCH_PROXY_NATIVE_USER_AGENT_HEADER) nativeUserAgent = value
|
|
128
|
+
if (STRIP_FETCH_PROXY_REQUEST_HEADERS.has(key) || key.startsWith('x-forwarded-')) {
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
headers[key] = value
|
|
132
|
+
}
|
|
133
|
+
if (!targetUrl) return headers
|
|
90
134
|
return {
|
|
135
|
+
...headers,
|
|
91
136
|
'accept-encoding': 'identity',
|
|
92
137
|
...(nativeUserAgent ? { 'user-agent': nativeUserAgent } : {}),
|
|
93
|
-
...
|
|
138
|
+
...headerOverridesFor(targetUrl.hostname)?.headers,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// node's IncomingMessage headers as the entries the policy reads.
|
|
143
|
+
export function nodeRequestHeaderEntries(
|
|
144
|
+
headers: Record<string, string | string[] | undefined>,
|
|
145
|
+
): Array<[string, string]> {
|
|
146
|
+
const entries: Array<[string, string]> = []
|
|
147
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
148
|
+
if (!value) continue
|
|
149
|
+
entries.push([key, Array.isArray(value) ? value.join(', ') : value])
|
|
94
150
|
}
|
|
151
|
+
return entries
|
|
95
152
|
}
|
package/src/kotlin-app.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import fs from 'node:fs'
|
|
7
7
|
import path from 'node:path'
|
|
8
|
+
import { readAndroidDrawables, type AndroidDrawable } from './android-drawables'
|
|
8
9
|
import { readAndroidStrings, type AndroidStringResources } from './android-strings'
|
|
9
10
|
import {
|
|
10
11
|
readResourceValues,
|
|
@@ -52,6 +53,7 @@ export interface KotlinAppProject {
|
|
|
52
53
|
// the module's string resources, which its R class names
|
|
53
54
|
strings: AndroidStringResources
|
|
54
55
|
colors: KotlinAppColor[]
|
|
56
|
+
drawables: AndroidDrawable[]
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// a color resource's ARGB in the day and the night configuration
|
|
@@ -543,5 +545,9 @@ export function readKotlinApp(
|
|
|
543
545
|
softInputAdjust,
|
|
544
546
|
strings: readAndroidStrings(moduleDir),
|
|
545
547
|
colors: readAppColors(moduleDir),
|
|
548
|
+
drawables: readAndroidDrawables(moduleDir, {
|
|
549
|
+
day: themeSources(moduleDir, false),
|
|
550
|
+
night: themeSources(moduleDir, true),
|
|
551
|
+
}),
|
|
546
552
|
}
|
|
547
553
|
}
|
package/src/kotlin-host.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
viewModelClasses,
|
|
18
18
|
type ViewModelClass,
|
|
19
19
|
} from './kotlin-view-models'
|
|
20
|
+
import type { DayNight, DrawableFile } from './android-drawables'
|
|
20
21
|
import type { KotlinAppProject, KotlinWindowTheme } from './kotlin-app'
|
|
21
22
|
import type { ServerResponse } from 'node:http'
|
|
22
23
|
|
|
@@ -436,25 +437,27 @@ export async function kotlinAppArtifact(
|
|
|
436
437
|
)
|
|
437
438
|
}
|
|
438
439
|
|
|
439
|
-
//
|
|
440
|
-
|
|
440
|
+
// a Kotlin string literal of any text
|
|
441
|
+
const escapes: Record<string, string> = {
|
|
442
|
+
'\\': '\\\\',
|
|
443
|
+
'"': '\\"',
|
|
444
|
+
$: '\\$',
|
|
445
|
+
'\n': '\\n',
|
|
446
|
+
'\r': '\\r',
|
|
447
|
+
'\t': '\\t',
|
|
448
|
+
}
|
|
449
|
+
const literal = (value: string) =>
|
|
450
|
+
`"${value.replace(
|
|
451
|
+
/[\\"$\u0000-\u001f]/g,
|
|
452
|
+
(char) => escapes[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`,
|
|
453
|
+
)}"`
|
|
454
|
+
|
|
455
|
+
// the module's R class in its namespace and the string, plurals, array,
|
|
456
|
+
// drawable and color tables Resources reads. an id is 0x7f, the type, then the entry in name
|
|
441
457
|
// order. a device's ids also count the module's other resource types and the
|
|
442
458
|
// resources its libraries merge in, which Peach does not build, so the
|
|
443
459
|
// numbers themselves differ
|
|
444
460
|
function appResourceSources(app: KotlinAppProject): Record<string, string> {
|
|
445
|
-
const escapes: Record<string, string> = {
|
|
446
|
-
'\\': '\\\\',
|
|
447
|
-
'"': '\\"',
|
|
448
|
-
$: '\\$',
|
|
449
|
-
'\n': '\\n',
|
|
450
|
-
'\r': '\\r',
|
|
451
|
-
'\t': '\\t',
|
|
452
|
-
}
|
|
453
|
-
const literal = (value: string) =>
|
|
454
|
-
`"${value.replace(
|
|
455
|
-
/[\\"$\u0000-\u001f]/g,
|
|
456
|
-
(char) => escapes[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`,
|
|
457
|
-
)}"`
|
|
458
461
|
// aapt2 writes a resource name's dots and dashes as underscores in R
|
|
459
462
|
const field = (name: string) => `\`${name.replace(/[.-]/g, '_')}\``
|
|
460
463
|
const id = (type: number, entry: number) =>
|
|
@@ -499,6 +502,17 @@ function appResourceSources(app: KotlinAppProject): Record<string, string> {
|
|
|
499
502
|
(items) => `listOf(${items.map(literal).join(', ')})`,
|
|
500
503
|
),
|
|
501
504
|
},
|
|
505
|
+
{
|
|
506
|
+
type: 'drawable',
|
|
507
|
+
table: 'peachAppDrawables',
|
|
508
|
+
value: 'List<PeachDrawable>',
|
|
509
|
+
entries: app.drawables.map((drawable) => ({
|
|
510
|
+
name: drawable.name,
|
|
511
|
+
init: `listOf(\n${drawable.files
|
|
512
|
+
.map((file) => drawableInit(file, path.relative(app.moduleDir, file.file)))
|
|
513
|
+
.join(',\n')}\n)`,
|
|
514
|
+
})),
|
|
515
|
+
},
|
|
502
516
|
// the day and the night ARGB
|
|
503
517
|
{
|
|
504
518
|
type: 'color',
|
|
@@ -534,6 +548,17 @@ function appResourceSources(app: KotlinAppProject): Record<string, string> {
|
|
|
534
548
|
'PeachAppResources.kt': [
|
|
535
549
|
'package dev.peach.app',
|
|
536
550
|
'',
|
|
551
|
+
...[
|
|
552
|
+
'androidx.compose.ui.graphics.BlendMode',
|
|
553
|
+
'androidx.compose.ui.graphics.Color',
|
|
554
|
+
'androidx.compose.ui.graphics.PathFillType',
|
|
555
|
+
'androidx.compose.ui.graphics.StrokeCap',
|
|
556
|
+
'androidx.compose.ui.graphics.StrokeJoin',
|
|
557
|
+
'androidx.compose.ui.graphics.vector.ImageVector',
|
|
558
|
+
'androidx.compose.ui.graphics.vector.addPathNodes',
|
|
559
|
+
'androidx.compose.ui.unit.Dp',
|
|
560
|
+
].map((name) => `import ${name}`),
|
|
561
|
+
'',
|
|
537
562
|
...kinds.flatMap((kind) => [
|
|
538
563
|
`internal val ${kind.table}: Map<Int, ${kind.value}> = mapOf(`,
|
|
539
564
|
...kind.entries.map((entry) => ` ${entry.id} to ${entry.init},`),
|
|
@@ -544,6 +569,69 @@ function appResourceSources(app: KotlinAppProject): Record<string, string> {
|
|
|
544
569
|
}
|
|
545
570
|
}
|
|
546
571
|
|
|
572
|
+
// a drawable file's table entry: a vector as the ImageVector.Builder calls
|
|
573
|
+
// XmlVectorParser makes, its colors chosen by the configuration's night
|
|
574
|
+
// mode; a bitmap as its encoded bytes
|
|
575
|
+
function drawableInit(drawable: DrawableFile, file: string): string {
|
|
576
|
+
const where = `${literal(file)}, ${drawable.density}, ${drawable.version}`
|
|
577
|
+
if (drawable.kind === 'xml') return `PeachDrawable.Xml(${where})`
|
|
578
|
+
if (drawable.kind === 'bitmap')
|
|
579
|
+
return `PeachDrawable.Bitmap(${where}, ${drawable.ninePatch}, ${literal(
|
|
580
|
+
fs.readFileSync(drawable.file).toString('base64'),
|
|
581
|
+
)})`
|
|
582
|
+
const vector = drawable.vector
|
|
583
|
+
const float = (value: number) => `${value}f`
|
|
584
|
+
const argb = (value: number) =>
|
|
585
|
+
`0x${value.toString(16).padStart(8, '0').toUpperCase()}.toInt()`
|
|
586
|
+
const pick = (value: DayNight) =>
|
|
587
|
+
value.day === value.night
|
|
588
|
+
? argb(value.day)
|
|
589
|
+
: `if (night) ${argb(value.night)} else ${argb(value.day)}`
|
|
590
|
+
const nodes = (pathData: string) =>
|
|
591
|
+
pathData ? `addPathNodes(${literal(pathData)})` : 'emptyList()'
|
|
592
|
+
const calls = vector.calls.map((call) => {
|
|
593
|
+
if (call.call === 'clear') return '.clearGroup()'
|
|
594
|
+
if (call.call === 'clip')
|
|
595
|
+
return `.addGroup(name = ${literal(call.name)}, clipPathData = ${nodes(call.pathData)})`
|
|
596
|
+
if (call.call === 'group')
|
|
597
|
+
return `.addGroup(${[
|
|
598
|
+
literal(call.name),
|
|
599
|
+
...[
|
|
600
|
+
call.rotate,
|
|
601
|
+
call.pivotX,
|
|
602
|
+
call.pivotY,
|
|
603
|
+
call.scaleX,
|
|
604
|
+
call.scaleY,
|
|
605
|
+
call.translateX,
|
|
606
|
+
call.translateY,
|
|
607
|
+
].map(float),
|
|
608
|
+
].join(', ')})`
|
|
609
|
+
return `.addPath(${[
|
|
610
|
+
nodes(call.pathData),
|
|
611
|
+
`PathFillType.${call.fillType}`,
|
|
612
|
+
literal(call.name),
|
|
613
|
+
`peachBrush(${pick(call.fill)})`,
|
|
614
|
+
float(call.fillAlpha),
|
|
615
|
+
`peachBrush(${pick(call.stroke)})`,
|
|
616
|
+
float(call.strokeAlpha),
|
|
617
|
+
float(call.strokeWidth),
|
|
618
|
+
`StrokeCap.${call.cap}`,
|
|
619
|
+
`StrokeJoin.${call.join}`,
|
|
620
|
+
...[call.miter, call.trimStart, call.trimEnd, call.trimOffset].map(float),
|
|
621
|
+
].join(', ')})`
|
|
622
|
+
})
|
|
623
|
+
return [
|
|
624
|
+
`PeachDrawable.Vector(${where}) { night -> ImageVector.Builder(`,
|
|
625
|
+
` defaultWidth = Dp(${float(vector.width)}), defaultHeight = Dp(${float(vector.height)}),`,
|
|
626
|
+
` viewportWidth = ${float(vector.viewportWidth)}, viewportHeight = ${float(vector.viewportHeight)},`,
|
|
627
|
+
` tintColor = ${vector.tint ? `Color(${pick(vector.tint)})` : 'Color.Unspecified'},`,
|
|
628
|
+
` tintBlendMode = BlendMode.${vector.tintMode}, autoMirror = ${vector.autoMirror},`,
|
|
629
|
+
` )`,
|
|
630
|
+
...calls.map((call) => ` ${call}`),
|
|
631
|
+
' .build() }',
|
|
632
|
+
].join('\n')
|
|
633
|
+
}
|
|
634
|
+
|
|
547
635
|
async function compileKotlin(
|
|
548
636
|
input: {
|
|
549
637
|
root: string
|
|
@@ -12,7 +12,12 @@
|
|
|
12
12
|
export type NativeAppIdentityPlatform = 'ios' | 'android'
|
|
13
13
|
|
|
14
14
|
export interface NativeAppIdentity {
|
|
15
|
+
// the user-facing name (CFBundleDisplayName, else CFBundleName).
|
|
15
16
|
applicationName: string | null
|
|
17
|
+
// CFBundleName, which CFNetwork stamps into the default User-Agent and iOS's
|
|
18
|
+
// own prompts use (the ASWebAuthenticationSession consent alert); distinct
|
|
19
|
+
// from the display name. absent in footers built before it was carried.
|
|
20
|
+
bundleName?: string
|
|
16
21
|
appVersion: string
|
|
17
22
|
buildVersion: string
|
|
18
23
|
bundleIdentifier: string
|
|
@@ -46,6 +51,8 @@ export function isNativeAppIdentity(value: unknown): value is NativeAppIdentity
|
|
|
46
51
|
if (platform !== 'ios' && platform !== 'android') return false
|
|
47
52
|
const applicationName = value.applicationName
|
|
48
53
|
if (applicationName !== null && nonEmptyString(applicationName) === null) return false
|
|
54
|
+
if (value.bundleName !== undefined && nonEmptyString(value.bundleName) === null)
|
|
55
|
+
return false
|
|
49
56
|
if (nonEmptyString(value.appVersion) === null) return false
|
|
50
57
|
if (nonEmptyString(value.bundleIdentifier) === null) return false
|
|
51
58
|
const buildVersion = nonEmptyString(value.buildVersion)
|
|
@@ -63,6 +70,7 @@ export function readNativeAppIdentity(value: unknown): NativeAppIdentity | null
|
|
|
63
70
|
}
|
|
64
71
|
return {
|
|
65
72
|
applicationName: value.applicationName,
|
|
73
|
+
...(value.bundleName === undefined ? {} : { bundleName: value.bundleName }),
|
|
66
74
|
appVersion: value.appVersion,
|
|
67
75
|
buildVersion: value.buildVersion,
|
|
68
76
|
bundleIdentifier: value.bundleIdentifier,
|
|
@@ -349,8 +357,9 @@ function nativeAppIdentityFromIos(
|
|
|
349
357
|
)
|
|
350
358
|
if (!appVersion || !buildVersion) return null
|
|
351
359
|
|
|
352
|
-
|
|
353
|
-
|
|
360
|
+
// CFNetwork names the bundle by CFBundleName, else the executable, which
|
|
361
|
+
// Xcode names after PRODUCT_NAME.
|
|
362
|
+
const bundleName =
|
|
354
363
|
identityFieldFrom(
|
|
355
364
|
settings,
|
|
356
365
|
plistString(plist, 'CFBundleName'),
|
|
@@ -358,7 +367,10 @@ function nativeAppIdentityFromIos(
|
|
|
358
367
|
) ??
|
|
359
368
|
resolvedIdentityField(resolveBuildSetting(settings.PRODUCT_NAME ?? '', settings)) ??
|
|
360
369
|
resolvedIdentityField(targetName)
|
|
361
|
-
if (!
|
|
370
|
+
if (!bundleName) return null
|
|
371
|
+
const applicationName =
|
|
372
|
+
identityFieldFrom(settings, plistString(plist, 'CFBundleDisplayName'), undefined) ??
|
|
373
|
+
bundleName
|
|
362
374
|
|
|
363
375
|
// only native privacy purpose strings travel here, not an invented Bundle
|
|
364
376
|
// dictionary. parse XML with the build-side parser so entities and empty
|
|
@@ -393,6 +405,7 @@ function nativeAppIdentityFromIos(
|
|
|
393
405
|
|
|
394
406
|
return {
|
|
395
407
|
applicationName,
|
|
408
|
+
bundleName,
|
|
396
409
|
appVersion,
|
|
397
410
|
buildVersion,
|
|
398
411
|
bundleIdentifier,
|