@agimon-ai/po-ios 0.0.1-alpha.2 → 0.0.1-alpha.21

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.
@@ -0,0 +1,1310 @@
1
+ import { defineActivityGroup, defineChannelFile, defineFill, defineGlobalStore, defineNativePlugin, defineSessionStore, defineSettingsPanel, defineWebLifecycle } from "@agimon-ai/po-core/native";
2
+ import { createElement, useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
3
+ import { View } from "react-native-unistyles/components/native/View";
4
+ import { Text } from "react-native-unistyles/components/native/Text";
5
+ import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
6
+ import { KeyboardAvoidingView } from "react-native-unistyles/components/native/KeyboardAvoidingView";
7
+ import { ActivityIcon, Button, DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Input, Panel, fontOf } from "@agimon-ai/po-native-components";
8
+ import { StyleSheet } from "react-native-unistyles";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { AppState, Share } from "react-native";
11
+ import { Image } from "react-native-unistyles/components/native/Image";
12
+ //#region src/extensions/(frontend)/setting/_lib/settingsRuntime.native.ts
13
+ const settingsRuntime = defineGlobalStore(void 0);
14
+ function startSettingsRuntime(runtime) {
15
+ const invoke = (call) => runtime.invokeServerMethod(call);
16
+ settingsRuntime.update(() => invoke);
17
+ return () => settingsRuntime.update((current) => current === invoke ? void 0 : current);
18
+ }
19
+ //#endregion
20
+ //#region src/extensions/(frontend)/lifecycle/start.native.ts
21
+ var start_native_default$1 = defineWebLifecycle(startSettingsRuntime);
22
+ //#endregion
23
+ //#region src/constants/ios.ts
24
+ const IOS_POOL_DEFAULTS = {
25
+ minBooted: 0,
26
+ maxBooted: 2,
27
+ maxDevices: 4,
28
+ idleShutdownMinutes: 10,
29
+ waitTimeoutSeconds: 120
30
+ };
31
+ //#endregion
32
+ //#region src/extensions/(frontend)/setting/_lib/settingsModel.ts
33
+ const poolFields = [
34
+ {
35
+ key: "maxRunning",
36
+ path: "maxBooted",
37
+ label: "Running limit",
38
+ detail: "Maximum simulators running at once."
39
+ },
40
+ {
41
+ key: "maxStored",
42
+ path: "maxDevices",
43
+ label: "Stored limit",
44
+ detail: "Maximum Po-owned simulators kept on this computer."
45
+ },
46
+ {
47
+ key: "warmCount",
48
+ path: "minBooted",
49
+ label: "Keep warm",
50
+ detail: "Idle simulators to keep ready."
51
+ },
52
+ {
53
+ key: "idleMinutes",
54
+ path: "idleShutdownMinutes",
55
+ label: "Idle timeout (minutes)",
56
+ detail: "Stop an unused Po-owned simulator after this long."
57
+ },
58
+ {
59
+ key: "queueSeconds",
60
+ path: "waitTimeoutSeconds",
61
+ label: "Queue timeout (seconds)",
62
+ detail: "How long a session can wait for a simulator."
63
+ }
64
+ ];
65
+ const physicalAvailabilityNote = "Every acquisition still asks for human approval. Excluding a phone does not revoke an active lease. Phones are never erased.";
66
+ const simulatorOwnershipNote = "Only Po-owned simulators are managed. Your personal simulators are left alone.";
67
+ const safeUdid = (value) => /^(?:[a-fA-F0-9]{8}-[a-fA-F0-9]{16}|[a-fA-F0-9]{40})$/.test(value);
68
+ const settingPaths = {
69
+ teamId: [
70
+ "ios",
71
+ "device",
72
+ "developmentTeam"
73
+ ],
74
+ model: [
75
+ "ios",
76
+ "pool",
77
+ "deviceType"
78
+ ],
79
+ runtime: [
80
+ "ios",
81
+ "pool",
82
+ "runtime"
83
+ ]
84
+ };
85
+ const emptyDraft = () => ({
86
+ teamId: "",
87
+ model: "",
88
+ runtime: "",
89
+ availability: {},
90
+ maxRunning: String(IOS_POOL_DEFAULTS.maxBooted),
91
+ maxStored: String(IOS_POOL_DEFAULTS.maxDevices),
92
+ warmCount: String(IOS_POOL_DEFAULTS.minBooted),
93
+ idleMinutes: String(IOS_POOL_DEFAULTS.idleShutdownMinutes),
94
+ queueSeconds: String(IOS_POOL_DEFAULTS.waitTimeoutSeconds)
95
+ });
96
+ function record(value) {
97
+ return typeof value === "object" && value !== null && !Array.isArray(value);
98
+ }
99
+ async function readSettings(request, udids) {
100
+ const search = new URLSearchParams({ repoRoot: "" });
101
+ const paths = [...Object.entries(settingPaths).map(([key, path]) => ({
102
+ key,
103
+ path
104
+ })), ...poolFields.map((field) => ({
105
+ key: field.key,
106
+ path: [
107
+ "ios",
108
+ "pool",
109
+ field.path
110
+ ]
111
+ }))];
112
+ for (const { path } of paths) search.append("key", path.join("."));
113
+ for (const udid of udids.filter(safeUdid)) search.append("key", `ios.device.availability.${udid}`);
114
+ const response = await request(`/api/settings?${search}`);
115
+ const body = await response.json();
116
+ if (!response.ok || !record(body) || !record(body.values) || !record(body.hashes) || typeof body.hashes.global !== "string") throw new Error("Could not read global iOS settings. Your draft is unchanged.");
117
+ const values = body.values;
118
+ const draft = emptyDraft();
119
+ const valueAt = (path) => {
120
+ const entry = values[path.join(".")];
121
+ return record(entry) && typeof entry.value === "string" ? entry.value : void 0;
122
+ };
123
+ for (const { key, path } of paths) draft[key] = valueAt(path) ?? draft[key];
124
+ for (const udid of udids.filter(safeUdid)) draft.availability[udid] = valueAt([
125
+ "ios",
126
+ "device",
127
+ "availability",
128
+ udid
129
+ ]) === "excluded" ? "excluded" : "available";
130
+ return {
131
+ draft,
132
+ hash: body.hashes.global
133
+ };
134
+ }
135
+ /** Scalar edits only. The host validates and atomically writes the complete document. */
136
+ function settingsEdits(draft, saved) {
137
+ const edits = [];
138
+ if (draft.teamId && !/^[A-Z0-9]{10}$/.test(draft.teamId)) throw new Error("Team ID must contain 10 uppercase letters or digits.");
139
+ for (const [key, keyPath] of Object.entries(settingPaths)) if (draft[key] !== saved[key]) edits.push({
140
+ keyPath,
141
+ value: draft[key] || null
142
+ });
143
+ for (const field of poolFields) {
144
+ const value = Number(draft[field.key]);
145
+ const minimum = field.key === "warmCount" || field.key === "queueSeconds" ? 0 : 1;
146
+ if (!/^\d+$/.test(draft[field.key]) || !Number.isSafeInteger(value) || value < minimum) throw new Error(`${field.label} must be a whole number of at least ${minimum}.`);
147
+ if (draft[field.key] !== saved[field.key]) edits.push({
148
+ keyPath: [
149
+ "ios",
150
+ "pool",
151
+ field.path
152
+ ],
153
+ value
154
+ });
155
+ }
156
+ if (Number(draft.warmCount) > Number(draft.maxRunning) || Number(draft.maxRunning) > Number(draft.maxStored)) throw new Error("Keep warm must not exceed the running limit, and the running limit must not exceed the stored limit.");
157
+ for (const [udid, value] of Object.entries(draft.availability)) {
158
+ if (!safeUdid(udid) || value !== "available" && value !== "excluded") throw new Error("Invalid phone availability.");
159
+ if (value !== (saved.availability[udid] ?? "available")) edits.push({
160
+ keyPath: [
161
+ "ios",
162
+ "device",
163
+ "availability",
164
+ udid
165
+ ],
166
+ value
167
+ });
168
+ }
169
+ if (edits.length > 100) throw new Error("Save at most 100 settings at a time.");
170
+ return edits;
171
+ }
172
+ function pendingActivation(draft, status) {
173
+ if (!status?.active || !status.applied) return true;
174
+ const applied = status.applied;
175
+ return draft.teamId !== (applied.developmentTeam ?? "") || draft.model !== (applied.pool.deviceType ?? "") || draft.runtime !== (applied.pool.runtime ?? "") || poolFields.some((field) => Number(draft[field.key]) !== applied.pool[field.path]) || Object.entries(draft.availability).some(([udid, state]) => state !== (applied.availability[udid] ?? "available"));
176
+ }
177
+ /** The settings host may reconnect to a different version, so reject malformed replies. */
178
+ function parseSettingsStatus(value) {
179
+ if (!record(value) || typeof value.active !== "boolean" || typeof value.configFile !== "string" || !Array.isArray(value.phones) || !Array.isArray(value.runtimes)) return void 0;
180
+ if (value.inventoryError !== void 0 && typeof value.inventoryError !== "string") return void 0;
181
+ if (value.runtimeError !== void 0 && typeof value.runtimeError !== "string") return void 0;
182
+ const choice = (item) => record(item) && typeof item.identifier === "string" && typeof item.name === "string";
183
+ if (value.phones.some((phone) => !record(phone) || typeof phone.udid !== "string" || typeof phone.name !== "string" || typeof phone.paired !== "boolean" || typeof phone.connected !== "boolean" || typeof phone.leased !== "boolean" || phone.availability !== "available" && phone.availability !== "excluded")) return void 0;
184
+ if (value.runtimes.some((runtime) => !record(runtime) || !choice(runtime) || typeof runtime.isAvailable !== "boolean" || !Array.isArray(runtime.models) || runtime.models.some((model) => !choice(model)))) return void 0;
185
+ if (value.applied !== void 0) {
186
+ const applied = value.applied;
187
+ if (!record(applied) || !record(applied.pool) || !record(applied.availability)) return void 0;
188
+ const pool = applied.pool;
189
+ if (poolFields.some((field) => typeof pool[field.path] !== "number" || !Number.isSafeInteger(pool[field.path]))) return void 0;
190
+ if (pool.deviceType !== void 0 && typeof pool.deviceType !== "string" || pool.runtime !== void 0 && typeof pool.runtime !== "string") return void 0;
191
+ if (applied.developmentTeam !== void 0 && typeof applied.developmentTeam !== "string") return void 0;
192
+ if (Object.entries(applied.availability).some(([udid, state]) => !safeUdid(udid) || state !== "available" && state !== "excluded")) return void 0;
193
+ }
194
+ return value;
195
+ }
196
+ //#endregion
197
+ //#region src/extensions/(frontend)/setting/_lib/useIosSettings.ts
198
+ function useIosSettings({ request, requestWithStepUp }, invoke) {
199
+ const [saved, setSaved] = useState();
200
+ const [draft, setDraft] = useState(emptyDraft);
201
+ const [status, setStatus] = useState();
202
+ const [loading, setLoading] = useState(true);
203
+ const [saving, setSaving] = useState(false);
204
+ const [conflict, setConflict] = useState(false);
205
+ const [notice, setNotice] = useState("Loading iOS settings.");
206
+ const generation = useRef(0);
207
+ const mounted = useRef(false);
208
+ const draftRef = useRef(draft);
209
+ draftRef.current = draft;
210
+ const savedRef = useRef(saved);
211
+ savedRef.current = saved;
212
+ const busy = useRef(false);
213
+ const edited = useRef(false);
214
+ const load = useCallback(async () => {
215
+ const run = ++generation.current;
216
+ setLoading(true);
217
+ try {
218
+ let current;
219
+ if (invoke) try {
220
+ current = parseSettingsStatus(await invoke({
221
+ mount: { scope: "global" },
222
+ service: "ios",
223
+ method: "settings",
224
+ input: {}
225
+ }));
226
+ } catch {}
227
+ const fresh = await readSettings(request, [.../* @__PURE__ */ new Set([
228
+ ...Object.keys(draftRef.current.availability),
229
+ ...Object.keys(current?.applied?.availability ?? {}),
230
+ ...current?.phones.map((phone) => phone.udid) ?? []
231
+ ])]);
232
+ if (generation.current !== run) return;
233
+ const hadDraft = edited.current && (savedRef.current === void 0 || JSON.stringify(draftRef.current) !== JSON.stringify(savedRef.current.draft));
234
+ setSaved(fresh);
235
+ setStatus(current);
236
+ if (!hadDraft) setDraft(fresh.draft);
237
+ setConflict(false);
238
+ setNotice(hadDraft ? `Current saved settings: ${JSON.stringify(fresh.draft)}. Your draft is retained. Review before saving again.` : pendingActivation(fresh.draft, current) ? "Saved settings are pending activation. The active service has not been restarted." : "Saved settings match the active iOS service. Signing has not been checked.");
239
+ } catch {
240
+ if (generation.current === run) {
241
+ setStatus(void 0);
242
+ setNotice("Could not reach global iOS settings. Your draft is retained. Try again.");
243
+ }
244
+ } finally {
245
+ if (generation.current === run) setLoading(false);
246
+ }
247
+ }, [request, invoke]);
248
+ useEffect(() => {
249
+ mounted.current = true;
250
+ load();
251
+ return () => {
252
+ mounted.current = false;
253
+ generation.current++;
254
+ };
255
+ }, [load]);
256
+ const dirty = saved !== void 0 && JSON.stringify(draft) !== JSON.stringify(saved.draft);
257
+ const save = async () => {
258
+ if (!saved || busy.current || conflict || loading) return;
259
+ busy.current = true;
260
+ setSaving(true);
261
+ const run = generation.current;
262
+ let wrote = false;
263
+ try {
264
+ const edits = settingsEdits(draft, saved.draft);
265
+ if (!edits.length) return;
266
+ const response = await requestWithStepUp("/api/settings/value", {
267
+ method: "PUT",
268
+ headers: { "content-type": "application/json" },
269
+ body: JSON.stringify({
270
+ repoRoot: "",
271
+ scope: "global",
272
+ expectedHash: saved.hash,
273
+ edits
274
+ })
275
+ });
276
+ if (run !== generation.current) return;
277
+ if (response.status === 409) {
278
+ setConflict(true);
279
+ setNotice("Settings changed on your computer. Review current settings before saving again. Your draft is retained.");
280
+ return;
281
+ }
282
+ if (!response.ok) {
283
+ setNotice(`Settings were not saved (Po answered ${response.status}). Your draft is retained.`);
284
+ return;
285
+ }
286
+ wrote = true;
287
+ const fresh = await readSettings(request, Object.keys(draft.availability));
288
+ if (run !== generation.current) return;
289
+ setSaved(fresh);
290
+ if (settingsEdits(draft, fresh.draft).length) {
291
+ setConflict(true);
292
+ setNotice("Settings changed again after saving. Your draft is retained. Review current settings.");
293
+ } else {
294
+ edited.current = false;
295
+ setDraft(fresh.draft);
296
+ setNotice(pendingActivation(fresh.draft, status) ? "Saved. Pending activation: restart the iOS service explicitly when ready. Saving did not restart it or interrupt leases." : "Saved settings match the active iOS service. Signing has not been checked.");
297
+ }
298
+ } catch (error) {
299
+ if (run === generation.current) {
300
+ if (wrote) setConflict(true);
301
+ setNotice(wrote ? "The write succeeded, but current settings could not be confirmed. Your draft is retained. Review current settings before saving again." : error instanceof Error ? error.message : "Could not save settings. Your draft is retained.");
302
+ }
303
+ } finally {
304
+ busy.current = false;
305
+ if (mounted.current) setSaving(false);
306
+ }
307
+ };
308
+ return {
309
+ draft,
310
+ status,
311
+ loading,
312
+ saving,
313
+ dirty,
314
+ conflict,
315
+ notice,
316
+ onChange: (key, value) => {
317
+ edited.current = true;
318
+ setDraft((current) => ({
319
+ ...current,
320
+ [key]: value
321
+ }));
322
+ setNotice("Unsaved changes.");
323
+ },
324
+ onSave: () => {
325
+ save();
326
+ },
327
+ onDiscard: () => {
328
+ edited.current = false;
329
+ if (saved) setDraft(saved.draft);
330
+ setNotice("Draft discarded. Saved settings are unchanged.");
331
+ },
332
+ onReload: () => {
333
+ if (!busy.current) load();
334
+ }
335
+ };
336
+ }
337
+ //#endregion
338
+ //#region src/extensions/(frontend)/setting/_components/IosSettingsView.native.tsx
339
+ function Field({ label, detail, children }) {
340
+ return /* @__PURE__ */ jsxs(View, {
341
+ style: styles$3.field,
342
+ children: [
343
+ /* @__PURE__ */ jsx(Text, {
344
+ style: styles$3.label,
345
+ children: label
346
+ }),
347
+ /* @__PURE__ */ jsx(Text, {
348
+ style: styles$3.dim,
349
+ children: detail
350
+ }),
351
+ children
352
+ ]
353
+ });
354
+ }
355
+ function IosSettingsView({ draft, status, loading, saving, dirty, conflict, notice, onChange: change, onSave, onDiscard, onReload }) {
356
+ const blocked = loading || saving;
357
+ const [advanced, setAdvanced] = useState(false);
358
+ const simulatorFields = poolFields.slice(0, 2);
359
+ const advancedFields = poolFields.slice(2);
360
+ const phones = [...status?.phones ?? [], ...Object.keys(draft.availability).filter((udid) => !status?.phones.some((phone) => phone.udid === udid)).map((udid) => ({
361
+ udid,
362
+ name: udid,
363
+ paired: false,
364
+ connected: false,
365
+ leased: false
366
+ }))];
367
+ const runtimes = status?.runtimes ?? [];
368
+ const models = [...new Map(runtimes.filter((runtime) => runtime.identifier === draft.runtime || !draft.runtime).flatMap((runtime) => runtime.models).map((model) => [model.identifier, model])).values()];
369
+ return /* @__PURE__ */ jsx(KeyboardAvoidingView, {
370
+ behavior: "padding",
371
+ style: styles$3.phone,
372
+ children: /* @__PURE__ */ jsxs(ScrollView, {
373
+ contentContainerStyle: styles$3.page,
374
+ keyboardShouldPersistTaps: "handled",
375
+ children: [
376
+ /* @__PURE__ */ jsxs(View, {
377
+ style: styles$3.section,
378
+ children: [
379
+ /* @__PURE__ */ jsx(Text, {
380
+ accessibilityRole: "header",
381
+ style: styles$3.title,
382
+ children: "iOS"
383
+ }),
384
+ /* @__PURE__ */ jsx(Text, {
385
+ style: styles$3.body,
386
+ children: "Signing, phone availability and simulator pools for every workspace on this computer."
387
+ }),
388
+ /* @__PURE__ */ jsx(Text, {
389
+ accessibilityLiveRegion: "polite",
390
+ style: styles$3.dim,
391
+ children: notice
392
+ }),
393
+ /* @__PURE__ */ jsx(Text, {
394
+ style: styles$3.dim,
395
+ children: status?.applied ? `Active: Team ID ${status.applied.developmentTeam || "not set"}, running limit ${status.applied.pool.maxBooted}, stored limit ${status.applied.pool.maxDevices}.` : "Active configuration is unavailable."
396
+ }),
397
+ /* @__PURE__ */ jsx(Button, {
398
+ variant: "outline",
399
+ style: styles$3.control,
400
+ onPress: onReload,
401
+ disabled: blocked,
402
+ children: conflict ? "Review current settings" : !status ? "Try again" : "Refresh settings"
403
+ })
404
+ ]
405
+ }),
406
+ /* @__PURE__ */ jsxs(View, {
407
+ style: styles$3.section,
408
+ children: [
409
+ /* @__PURE__ */ jsx(Text, {
410
+ accessibilityRole: "header",
411
+ style: styles$3.heading,
412
+ children: "Development signing"
413
+ }),
414
+ /* @__PURE__ */ jsx(Panel, {
415
+ style: styles$3.card,
416
+ children: /* @__PURE__ */ jsx(Field, {
417
+ label: "Apple Development Team ID",
418
+ detail: "Used to sign Po’s physical-device runner. Not an Apple account sign-in.",
419
+ children: /* @__PURE__ */ jsx(Input, {
420
+ accessibilityLabel: "Apple Development Team ID",
421
+ style: styles$3.literal,
422
+ autoCapitalize: "characters",
423
+ value: draft.teamId,
424
+ disabled: blocked,
425
+ onChangeText: (value) => change("teamId", value)
426
+ })
427
+ })
428
+ }),
429
+ /* @__PURE__ */ jsx(Text, {
430
+ style: styles$3.dim,
431
+ children: "Signing has not been checked. Saving a Team ID does not check certificates, provisioning or build installation eligibility."
432
+ })
433
+ ]
434
+ }),
435
+ /* @__PURE__ */ jsxs(View, {
436
+ style: styles$3.section,
437
+ children: [
438
+ /* @__PURE__ */ jsx(Text, {
439
+ accessibilityRole: "header",
440
+ style: styles$3.heading,
441
+ children: "Physical iPhones"
442
+ }),
443
+ /* @__PURE__ */ jsxs(Panel, {
444
+ style: styles$3.card,
445
+ children: [
446
+ status?.inventoryError ? /* @__PURE__ */ jsx(Text, {
447
+ style: styles$3.dim,
448
+ children: status.inventoryError
449
+ }) : null,
450
+ !status ? /* @__PURE__ */ jsx(Text, {
451
+ style: styles$3.dim,
452
+ children: "Phone inventory is unavailable. Try again to reconnect."
453
+ }) : null,
454
+ status && !status.inventoryError && !phones.length ? /* @__PURE__ */ jsx(Text, {
455
+ style: styles$3.dim,
456
+ children: "No physical phones are visible."
457
+ }) : null,
458
+ phones.map((phone) => /* @__PURE__ */ jsx(Field, {
459
+ label: phone.name || phone.udid,
460
+ detail: `${phone.paired ? "Paired" : "Not paired"} · ${phone.connected ? "Reachable" : "Offline"}${phone.leased ? " · In use" : ""}. Availability applies to this phone only.`,
461
+ children: /* @__PURE__ */ jsx(Button, {
462
+ variant: "outline",
463
+ style: styles$3.control,
464
+ accessibilityRole: "checkbox",
465
+ accessibilityLabel: `Available to Po: ${phone.name || phone.udid}`,
466
+ "aria-checked": (draft.availability[phone.udid] ?? "available") === "available",
467
+ disabled: blocked,
468
+ onPress: () => change("availability", {
469
+ ...draft.availability,
470
+ [phone.udid]: (draft.availability[phone.udid] ?? "available") === "available" ? "excluded" : "available"
471
+ }),
472
+ children: (draft.availability[phone.udid] ?? "available") === "available" ? "Available to Po" : "Excluded from Po"
473
+ })
474
+ }, phone.udid))
475
+ ]
476
+ }),
477
+ /* @__PURE__ */ jsx(Text, {
478
+ style: styles$3.dim,
479
+ children: physicalAvailabilityNote
480
+ })
481
+ ]
482
+ }),
483
+ /* @__PURE__ */ jsxs(View, {
484
+ style: styles$3.section,
485
+ children: [
486
+ /* @__PURE__ */ jsx(Text, {
487
+ accessibilityRole: "header",
488
+ style: styles$3.heading,
489
+ children: "Simulator pool"
490
+ }),
491
+ /* @__PURE__ */ jsxs(Panel, {
492
+ style: styles$3.card,
493
+ children: [simulatorFields.map((field) => /* @__PURE__ */ jsx(Field, {
494
+ label: field.label,
495
+ detail: field.detail,
496
+ children: /* @__PURE__ */ jsx(Input, {
497
+ accessibilityLabel: field.label,
498
+ keyboardType: "number-pad",
499
+ value: draft[field.key],
500
+ disabled: blocked,
501
+ onChangeText: (value) => change(field.key, value)
502
+ })
503
+ }, field.key)), ["model", "runtime"].map((key) => /* @__PURE__ */ jsx(Field, {
504
+ label: key === "model" ? "Default model" : "Default runtime",
505
+ detail: "Used for the next simulator Po creates.",
506
+ children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
507
+ variant: "outline",
508
+ style: styles$3.control,
509
+ disabled: blocked,
510
+ accessibilityLabel: `${key === "model" ? "Default model" : "Default runtime"}, ${draft[key] || "Automatic"}`,
511
+ children: draft[key] || "Automatic"
512
+ }), /* @__PURE__ */ jsx(DropdownMenuContent, { children: /* @__PURE__ */ jsxs(DropdownMenuRadioGroup, {
513
+ value: draft[key] || "Automatic",
514
+ onValueChange: (value) => change(key, value),
515
+ children: [
516
+ /* @__PURE__ */ jsx(DropdownMenuRadioItem, {
517
+ value: "__automatic__",
518
+ children: "Automatic"
519
+ }),
520
+ draft[key] && !(key === "model" ? models : runtimes).some((item) => item.identifier === draft[key]) ? /* @__PURE__ */ jsxs(DropdownMenuRadioItem, {
521
+ value: draft[key],
522
+ children: [draft[key], " (not discovered)"]
523
+ }) : null,
524
+ (key === "model" ? models : runtimes).map((item) => /* @__PURE__ */ jsx(DropdownMenuRadioItem, {
525
+ value: item.identifier,
526
+ disabled: "isAvailable" in item && !item.isAvailable,
527
+ children: item.name
528
+ }, item.identifier))
529
+ ]
530
+ }) })] })
531
+ }, key))]
532
+ }),
533
+ /* @__PURE__ */ jsxs(Text, {
534
+ style: styles$3.dim,
535
+ children: [
536
+ simulatorOwnershipNote,
537
+ " ",
538
+ status?.runtimeError ?? (!status ? "Model and runtime discovery is unavailable." : "Choices use discovered identifiers.")
539
+ ]
540
+ }),
541
+ /* @__PURE__ */ jsx(Button, {
542
+ variant: "ghost",
543
+ style: styles$3.control,
544
+ "aria-expanded": advanced,
545
+ onPress: () => setAdvanced(!advanced),
546
+ children: advanced ? "Hide advanced pool settings" : "Advanced pool settings"
547
+ }),
548
+ advanced ? /* @__PURE__ */ jsx(Panel, {
549
+ style: styles$3.card,
550
+ children: advancedFields.map((field) => /* @__PURE__ */ jsx(Field, {
551
+ label: field.label,
552
+ detail: field.detail,
553
+ children: /* @__PURE__ */ jsx(Input, {
554
+ accessibilityLabel: field.label,
555
+ keyboardType: "number-pad",
556
+ value: draft[field.key],
557
+ disabled: blocked,
558
+ onChangeText: (value) => change(field.key, value)
559
+ })
560
+ }, field.key))
561
+ }) : null
562
+ ]
563
+ }),
564
+ /* @__PURE__ */ jsxs(View, {
565
+ style: styles$3.section,
566
+ children: [
567
+ /* @__PURE__ */ jsx(Button, {
568
+ variant: "primary",
569
+ style: styles$3.control,
570
+ disabled: blocked || !dirty || conflict,
571
+ onPress: onSave,
572
+ children: saving ? "Saving…" : "Save changes"
573
+ }),
574
+ /* @__PURE__ */ jsx(Button, {
575
+ variant: "ghost",
576
+ style: styles$3.control,
577
+ disabled: blocked || !dirty,
578
+ onPress: onDiscard,
579
+ children: "Discard changes"
580
+ }),
581
+ /* @__PURE__ */ jsx(Text, {
582
+ style: styles$3.dim,
583
+ children: "Changes require an iOS service restart. Saving never restarts a service or interrupts an active lease."
584
+ })
585
+ ]
586
+ })
587
+ ]
588
+ })
589
+ });
590
+ }
591
+ const styles$3 = StyleSheet.create((theme) => ({
592
+ phone: {
593
+ flex: 1,
594
+ backgroundColor: theme.colors.bg,
595
+ uni__dependencies: [0]
596
+ },
597
+ page: {
598
+ padding: theme.spacing(5),
599
+ paddingBottom: theme.spacing(10),
600
+ gap: theme.spacing(8),
601
+ uni__dependencies: [0]
602
+ },
603
+ section: {
604
+ gap: theme.spacing(3),
605
+ uni__dependencies: [0]
606
+ },
607
+ card: {
608
+ borderRadius: theme.borderRadius.lg,
609
+ uni__dependencies: [0]
610
+ },
611
+ field: {
612
+ padding: theme.spacing(4),
613
+ gap: theme.spacing(2),
614
+ borderBottomWidth: 1,
615
+ borderBottomColor: theme.colors["border-soft"],
616
+ uni__dependencies: [0]
617
+ },
618
+ control: {
619
+ minHeight: 44,
620
+ alignSelf: "stretch"
621
+ },
622
+ literal: {
623
+ fontFamily: fontOf(theme.fontFamily.mono),
624
+ uni__dependencies: [0]
625
+ },
626
+ title: {
627
+ fontFamily: fontOf(theme.fontFamily.sans),
628
+ fontSize: theme.fontSize["2xl"],
629
+ lineHeight: theme.lineHeight["2xl"],
630
+ fontWeight: "600",
631
+ color: theme.colors.hi,
632
+ uni__dependencies: [0]
633
+ },
634
+ heading: {
635
+ fontFamily: fontOf(theme.fontFamily.sans),
636
+ fontSize: theme.fontSize.lg,
637
+ lineHeight: theme.lineHeight.lg,
638
+ fontWeight: "600",
639
+ color: theme.colors.hi,
640
+ uni__dependencies: [0]
641
+ },
642
+ label: {
643
+ fontFamily: fontOf(theme.fontFamily.sans),
644
+ fontSize: theme.fontSize.base,
645
+ lineHeight: theme.lineHeight.base,
646
+ fontWeight: "500",
647
+ color: theme.colors.hi,
648
+ uni__dependencies: [0]
649
+ },
650
+ body: {
651
+ fontFamily: fontOf(theme.fontFamily.sans),
652
+ fontSize: theme.fontSize.base,
653
+ lineHeight: theme.lineHeight.base,
654
+ color: theme.colors.text,
655
+ uni__dependencies: [0]
656
+ },
657
+ dim: {
658
+ fontFamily: fontOf(theme.fontFamily.sans),
659
+ fontSize: theme.fontSize.sm,
660
+ lineHeight: theme.lineHeight.sm,
661
+ color: theme.colors.dim,
662
+ uni__dependencies: [0]
663
+ }
664
+ }));
665
+ //#endregion
666
+ //#region src/extensions/(frontend)/setting/_components/IosSettingsPanel.native.tsx
667
+ function IosSettingsPanel(props) {
668
+ const subscribe = useCallback((listener) => {
669
+ const subscription = settingsRuntime.store.subscribe(listener);
670
+ return () => subscription.unsubscribe();
671
+ }, []);
672
+ const snapshot = () => settingsRuntime.store.state;
673
+ const invoke = useSyncExternalStore(subscribe, snapshot, snapshot);
674
+ return /* @__PURE__ */ jsx(IosSettingsView, { ...useIosSettings(props, invoke) });
675
+ }
676
+ //#endregion
677
+ //#region src/extensions/(frontend)/setting/ios.panel.native.tsx
678
+ var ios_panel_native_default = defineSettingsPanel({
679
+ label: "iOS",
680
+ detail: "Global signing, phone availability and simulator pool settings.",
681
+ order: 65,
682
+ component: IosSettingsPanel
683
+ });
684
+ //#endregion
685
+ //#region src/types/iosUi.ts
686
+ /** JSON-only iOS UI contracts. Lease ownership and paths are resolved by the server. */
687
+ const iosActivityChannel$1 = "ios_activity";
688
+ //#endregion
689
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/iosActivityStore.native.ts
690
+ const iosActivity = defineSessionStore({
691
+ supported: false,
692
+ devices: []
693
+ });
694
+ function useIosActivity(sessionId) {
695
+ const snapshot = () => iosActivity.select(iosActivity.store.state, sessionId);
696
+ return useSyncExternalStore(iosActivitySource.subscribe, snapshot, snapshot);
697
+ }
698
+ const iosActivityChannel = iosActivity.channel({
699
+ channel: iosActivityChannel$1,
700
+ parse(input) {
701
+ if (typeof input !== "object" || input === null) return null;
702
+ const value = input;
703
+ if (typeof value.supported !== "boolean" || !Array.isArray(value.devices)) return null;
704
+ if (!value.devices.every((device) => device && typeof device.id === "string" && typeof device.name === "string" && typeof device.detail === "string" && ["simulator", "device"].includes(device.kind) && [
705
+ "owned",
706
+ "other-session",
707
+ "available",
708
+ "disconnected"
709
+ ].includes(device.state) && ["available", "unsupported"].includes(device.capture) && (device.leaseId === void 0 || typeof device.leaseId === "string"))) return null;
710
+ if (value.build && (typeof value.build.id !== "string" || typeof value.build.name !== "string" || typeof value.build.artifactPath !== "string" || typeof value.build.size !== "number" || typeof value.build.registeredAt !== "string")) return null;
711
+ return {
712
+ supported: value.supported,
713
+ devices: value.devices.map(({ id, name, detail, kind, state, capture, leaseId }) => ({
714
+ id,
715
+ name,
716
+ detail,
717
+ kind,
718
+ state,
719
+ capture,
720
+ ...state === "owned" && leaseId ? { leaseId } : {}
721
+ })),
722
+ ...value.build ? { build: {
723
+ id: value.build.id,
724
+ name: value.build.name,
725
+ size: value.build.size,
726
+ artifactPath: value.build.artifactPath,
727
+ registeredAt: value.build.registeredAt
728
+ } } : {},
729
+ ...typeof value.error === "string" ? { error: value.error } : {}
730
+ };
731
+ },
732
+ reduce: (_current, payload) => payload
733
+ });
734
+ const iosActivitySource = {
735
+ subscribe: (listener) => {
736
+ const subscription = iosActivity.store.subscribe(listener);
737
+ return () => subscription.unsubscribe();
738
+ },
739
+ isActive(sessionId) {
740
+ return iosActivity.select(iosActivity.store.state, sessionId).devices.some((device) => device.state === "owned");
741
+ }
742
+ };
743
+ const invoker = defineGlobalStore(void 0);
744
+ function startIosRuntime(runtime) {
745
+ const invoke = (call) => runtime.invokeServerMethod(call);
746
+ invoker.update(() => invoke);
747
+ return () => invoker.update((current) => current === invoke ? void 0 : current);
748
+ }
749
+ async function call(sessionId, method, input) {
750
+ const invoke = invoker.store.state;
751
+ if (!invoke) throw new Error("iOS is not connected.");
752
+ return invoke({
753
+ mount: {
754
+ scope: "session",
755
+ sessionId
756
+ },
757
+ service: "ios",
758
+ method,
759
+ input
760
+ });
761
+ }
762
+ async function fetchIosFrame(sessionId, leaseId, since) {
763
+ try {
764
+ const reply = await call(sessionId, "frame", {
765
+ leaseId,
766
+ ...since ? { since } : {}
767
+ });
768
+ if (reply?.state === "ok" && typeof reply.src === "string" && /^data:image\/png;base64,[A-Za-z0-9+/=]+$/.test(reply.src) && typeof reply.hash === "string" && typeof reply.capturedAt === "number") return reply;
769
+ if (reply?.state === "unchanged" && since !== void 0 && typeof reply.hash === "string" && typeof reply.capturedAt === "number") return reply;
770
+ if (reply?.state === "released") return { state: "released" };
771
+ if (reply?.state === "capture-unavailable") return {
772
+ state: "capture-unavailable",
773
+ message: "Screen capture is unavailable."
774
+ };
775
+ } catch {}
776
+ return {
777
+ state: "error",
778
+ message: "Could not reach the simulator. Waiting to reconnect."
779
+ };
780
+ }
781
+ /** Action-local only. The ephemeral URL is never written to plugin state or logs. */
782
+ async function shareIosBuild(sessionId, buildId) {
783
+ try {
784
+ const reply = await call(sessionId, "shareBuild", { buildId });
785
+ if (reply?.ok === true && typeof reply.url === "string" && /^https?:\/\//.test(reply.url) && typeof reply.expiresAt === "number" && reply.expiresAt > Date.now()) return reply;
786
+ if (reply?.ok === false && reply.reason === "remote-off") return {
787
+ ok: false,
788
+ reason: "remote-off",
789
+ message: "Remote access is off. Open the build in Po locally."
790
+ };
791
+ } catch {}
792
+ return {
793
+ ok: false,
794
+ reason: "unavailable",
795
+ message: "The build is unavailable or changed. Try again when the current build appears."
796
+ };
797
+ }
798
+ /** Inventory is not permission to capture. Only an owned simulator lease can open. */
799
+ function canViewDevice(device) {
800
+ return device.state === "owned" && !!device.leaseId && device.kind === "simulator" && device.capture === "available";
801
+ }
802
+ function deviceDetail(device) {
803
+ const state = device.state === "owned" ? "This session" : device.state === "other-session" ? "Another session" : device.state === "disconnected" ? "Disconnected" : "Available";
804
+ return `${device.detail} · ${state}${device.capture === "unsupported" ? " · Screen capture unsupported" : ""}`;
805
+ }
806
+ //#endregion
807
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/IosActivityView.native.tsx
808
+ function IosActivityView({ devices, build, details, install, notice, footer, installExpanded = false, busy = false, canOpen = false, onView, onDownload, onCopy, onOpen, onInstall }) {
809
+ const [installation, setInstallation] = useState(installExpanded);
810
+ return /* @__PURE__ */ jsx(ScrollView, {
811
+ contentContainerStyle: styles$2.content,
812
+ children: /* @__PURE__ */ jsxs(View, {
813
+ style: styles$2.card,
814
+ children: [
815
+ /* @__PURE__ */ jsx(Text, {
816
+ accessibilityRole: "header",
817
+ style: styles$2.heading,
818
+ children: "iOS"
819
+ }),
820
+ devices.length === 0 ? /* @__PURE__ */ jsx(Text, {
821
+ style: styles$2.dim,
822
+ children: "No device is leased to this session."
823
+ }) : devices.map((device) => /* @__PURE__ */ jsxs(View, {
824
+ style: styles$2.group,
825
+ children: [
826
+ /* @__PURE__ */ jsx(Text, {
827
+ style: styles$2.title,
828
+ children: device.name
829
+ }),
830
+ /* @__PURE__ */ jsx(Text, {
831
+ style: styles$2.dim,
832
+ children: device.detail
833
+ }),
834
+ device.canView && /* @__PURE__ */ jsx(Button, {
835
+ style: styles$2.touch,
836
+ onPress: () => onView(device.id),
837
+ children: "View screen"
838
+ })
839
+ ]
840
+ }, device.id)),
841
+ build && /* @__PURE__ */ jsxs(View, {
842
+ style: styles$2.build,
843
+ children: [
844
+ /* @__PURE__ */ jsx(Text, {
845
+ accessibilityRole: "header",
846
+ style: styles$2.title,
847
+ children: "Latest build"
848
+ }),
849
+ /* @__PURE__ */ jsx(Text, {
850
+ style: styles$2.literal,
851
+ children: build.name
852
+ }),
853
+ /* @__PURE__ */ jsx(Text, {
854
+ style: styles$2.dim,
855
+ children: build.detail
856
+ }),
857
+ /* @__PURE__ */ jsx(Text, {
858
+ style: styles$2.dim,
859
+ children: details.note
860
+ }),
861
+ !details.blocked && /* @__PURE__ */ jsx(Text, {
862
+ style: styles$2.dim,
863
+ children: "Links expire after 10 minutes. Anyone with the link can download."
864
+ }),
865
+ /* @__PURE__ */ jsx(Button, {
866
+ style: styles$2.touch,
867
+ variant: "primary",
868
+ disabled: details.blocked,
869
+ loading: busy,
870
+ onPress: onDownload,
871
+ children: details.action
872
+ }),
873
+ /* @__PURE__ */ jsx(Button, {
874
+ style: styles$2.touch,
875
+ variant: "link",
876
+ disabled: details.blocked,
877
+ onPress: onCopy,
878
+ children: "Copy download link"
879
+ }),
880
+ /* @__PURE__ */ jsx(Button, {
881
+ style: styles$2.touch,
882
+ variant: "link",
883
+ disabled: !canOpen,
884
+ onPress: onOpen,
885
+ children: "Open in Po"
886
+ }),
887
+ /* @__PURE__ */ jsx(Button, {
888
+ style: styles$2.touch,
889
+ variant: "ghost",
890
+ "aria-expanded": installation,
891
+ onPress: () => setInstallation(!installation),
892
+ children: "Install on iPhone"
893
+ }),
894
+ installation && /* @__PURE__ */ jsxs(View, {
895
+ style: styles$2.group,
896
+ children: [/* @__PURE__ */ jsx(Text, {
897
+ style: styles$2.dim,
898
+ children: install.note
899
+ }), /* @__PURE__ */ jsx(Button, {
900
+ style: styles$2.touch,
901
+ disabled: install.blocked,
902
+ onPress: onInstall,
903
+ children: install.action
904
+ })]
905
+ })
906
+ ]
907
+ }),
908
+ notice && /* @__PURE__ */ jsx(Text, {
909
+ accessibilityLiveRegion: "polite",
910
+ style: styles$2.notice,
911
+ children: notice
912
+ }),
913
+ footer && /* @__PURE__ */ jsx(Text, {
914
+ style: styles$2.dim,
915
+ children: footer
916
+ })
917
+ ]
918
+ })
919
+ });
920
+ }
921
+ const styles$2 = StyleSheet.create((theme) => ({
922
+ content: {
923
+ padding: theme.spacing(4),
924
+ uni__dependencies: [0]
925
+ },
926
+ card: {
927
+ padding: theme.spacing(4),
928
+ gap: theme.spacing(4),
929
+ borderWidth: 1,
930
+ borderColor: theme.colors.border,
931
+ borderRadius: theme.borderRadius.md,
932
+ backgroundColor: theme.colors.rail,
933
+ uni__dependencies: [0]
934
+ },
935
+ group: {
936
+ gap: theme.spacing(2),
937
+ uni__dependencies: [0]
938
+ },
939
+ build: {
940
+ gap: theme.spacing(3),
941
+ paddingTop: theme.spacing(4),
942
+ borderTopWidth: 1,
943
+ borderColor: theme.colors.border,
944
+ uni__dependencies: [0]
945
+ },
946
+ touch: { minHeight: 44 },
947
+ heading: {
948
+ fontFamily: fontOf(theme.fontFamily.sans),
949
+ fontSize: theme.fontSize.lg,
950
+ lineHeight: theme.lineHeight.lg,
951
+ fontWeight: "600",
952
+ color: theme.colors.hi,
953
+ uni__dependencies: [0]
954
+ },
955
+ title: {
956
+ fontFamily: fontOf(theme.fontFamily.sans),
957
+ fontSize: theme.fontSize.base,
958
+ lineHeight: theme.lineHeight.base,
959
+ fontWeight: "600",
960
+ color: theme.colors.hi,
961
+ uni__dependencies: [0]
962
+ },
963
+ dim: {
964
+ fontFamily: fontOf(theme.fontFamily.sans),
965
+ fontSize: theme.fontSize.sm,
966
+ lineHeight: theme.lineHeight.sm,
967
+ color: theme.colors.dim,
968
+ uni__dependencies: [0]
969
+ },
970
+ literal: {
971
+ fontFamily: fontOf(theme.fontFamily.mono),
972
+ fontSize: theme.fontSize.base,
973
+ lineHeight: theme.lineHeight.base,
974
+ color: theme.colors.text,
975
+ uni__dependencies: [0]
976
+ },
977
+ notice: {
978
+ fontFamily: fontOf(theme.fontFamily.sans),
979
+ fontSize: theme.fontSize.sm,
980
+ lineHeight: theme.lineHeight.sm,
981
+ color: theme.colors.blue,
982
+ uni__dependencies: [0]
983
+ }
984
+ }));
985
+ //#endregion
986
+ //#region src/extensions/workspaces/sessions/(frontend)/_lib/iosFrames.ts
987
+ /** Serial visible-reader polling. Late replies after cleanup are never delivered. */
988
+ function pollIosFrames(fetchFrame, receive) {
989
+ let stopped = false;
990
+ let timer;
991
+ let hash;
992
+ const tick = async () => {
993
+ let reply;
994
+ try {
995
+ reply = await fetchFrame(hash);
996
+ } catch {
997
+ reply = {
998
+ state: "error",
999
+ message: "Could not reach the simulator."
1000
+ };
1001
+ }
1002
+ if (stopped) return;
1003
+ if (reply.state === "ok") hash = reply.hash;
1004
+ else if (reply.state === "error") hash = void 0;
1005
+ receive(reply);
1006
+ if (reply.state !== "released" && reply.state !== "capture-unavailable") timer = setTimeout(() => void tick(), 750);
1007
+ };
1008
+ tick();
1009
+ return () => {
1010
+ stopped = true;
1011
+ clearTimeout(timer);
1012
+ };
1013
+ }
1014
+ //#endregion
1015
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/IosDeviceView.native.tsx
1016
+ function IosDeviceView({ name, status, note, frame, controls, composer }) {
1017
+ return /* @__PURE__ */ jsxs(View, {
1018
+ style: styles$1.screen,
1019
+ children: [
1020
+ /* @__PURE__ */ jsxs(View, {
1021
+ style: styles$1.header,
1022
+ children: [/* @__PURE__ */ jsx(Text, {
1023
+ accessibilityRole: "header",
1024
+ style: styles$1.title,
1025
+ children: name
1026
+ }), /* @__PURE__ */ jsxs(Text, {
1027
+ style: styles$1.dim,
1028
+ children: ["View only · ", status]
1029
+ })]
1030
+ }),
1031
+ /* @__PURE__ */ jsxs(ScrollView, {
1032
+ style: styles$1.viewport,
1033
+ contentContainerStyle: styles$1.content,
1034
+ children: [
1035
+ /* @__PURE__ */ jsx(Text, {
1036
+ accessibilityLiveRegion: "polite",
1037
+ style: styles$1.dim,
1038
+ children: note
1039
+ }),
1040
+ frame,
1041
+ controls
1042
+ ]
1043
+ }),
1044
+ composer
1045
+ ]
1046
+ });
1047
+ }
1048
+ const styles$1 = StyleSheet.create((theme) => ({
1049
+ dim: {
1050
+ fontFamily: fontOf(theme.fontFamily.sans),
1051
+ fontSize: theme.fontSize.sm,
1052
+ lineHeight: theme.lineHeight.sm,
1053
+ color: theme.colors.dim,
1054
+ uni__dependencies: [0]
1055
+ },
1056
+ screen: {
1057
+ flex: 1,
1058
+ backgroundColor: theme.colors.bg,
1059
+ uni__dependencies: [0]
1060
+ },
1061
+ header: {
1062
+ padding: theme.spacing(4),
1063
+ gap: theme.spacing(1),
1064
+ backgroundColor: theme.colors.panel,
1065
+ borderBottomWidth: 1,
1066
+ borderColor: theme.colors.border,
1067
+ uni__dependencies: [0]
1068
+ },
1069
+ viewport: {
1070
+ flex: 1,
1071
+ backgroundColor: theme.colors.deep,
1072
+ uni__dependencies: [0]
1073
+ },
1074
+ content: {
1075
+ padding: theme.spacing(4),
1076
+ alignItems: "center",
1077
+ gap: theme.spacing(3),
1078
+ uni__dependencies: [0]
1079
+ },
1080
+ title: {
1081
+ fontFamily: fontOf(theme.fontFamily.sans),
1082
+ fontSize: theme.fontSize.base,
1083
+ lineHeight: theme.lineHeight.base,
1084
+ fontWeight: "600",
1085
+ color: theme.colors.hi,
1086
+ uni__dependencies: [0]
1087
+ }
1088
+ }));
1089
+ //#endregion
1090
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/IosDevicePanel.native.tsx
1091
+ function iosDeviceTab(device) {
1092
+ return {
1093
+ id: `ios-device-${device.id}-${device.leaseId}`,
1094
+ label: device.name,
1095
+ retainComposer: true,
1096
+ panel: (props) => /* @__PURE__ */ jsx(IosDevicePanel, {
1097
+ ...props,
1098
+ opened: device
1099
+ }, props.sessionId)
1100
+ };
1101
+ }
1102
+ function useVisible() {
1103
+ const [visible, setVisible] = useState(AppState.currentState === "active");
1104
+ useEffect(() => {
1105
+ const subscription = AppState.addEventListener("change", (state) => setVisible(state === "active"));
1106
+ return () => subscription.remove();
1107
+ }, []);
1108
+ return visible;
1109
+ }
1110
+ function IosDevicePanel({ sessionId, opened, setTabHeader }) {
1111
+ const device = useIosActivity(sessionId).devices.find((item) => item.id === opened.id);
1112
+ const owned = !!device && canViewDevice(device) && device.leaseId === opened.leaseId;
1113
+ const visible = useVisible();
1114
+ const [frame, setFrame] = useState();
1115
+ const [reply, setReply] = useState();
1116
+ const released = reply?.state === "released";
1117
+ const unavailable = reply?.state === "capture-unavailable";
1118
+ useEffect(() => {
1119
+ setFrame(void 0);
1120
+ if (!sessionId || !owned || !visible || released || unavailable || !opened.leaseId) return;
1121
+ return pollIosFrames((since) => fetchIosFrame(sessionId, opened.leaseId, since), (next) => {
1122
+ setReply(next);
1123
+ if (next.state === "ok") setFrame(next.src);
1124
+ else if (next.state === "released" || next.state === "capture-unavailable" || next.state === "error") setFrame(void 0);
1125
+ });
1126
+ }, [
1127
+ sessionId,
1128
+ owned,
1129
+ visible,
1130
+ released,
1131
+ unavailable,
1132
+ opened.leaseId
1133
+ ]);
1134
+ const status = !owned || released ? "Device released or ownership changed" : unavailable ? "Screen capture unavailable" : !visible ? "Capture paused while hidden" : reply?.state === "error" ? "Connection unavailable" : frame ? "Updated just now" : "Waiting for first frame";
1135
+ const pixels = owned && visible && !released && !unavailable ? frame : void 0;
1136
+ useEffect(() => {
1137
+ setTabHeader?.({ subtitle: `View only · ${status}` });
1138
+ }, [setTabHeader, status]);
1139
+ return /* @__PURE__ */ jsx(IosDeviceView, {
1140
+ name: `${opened.name}${owned && !released ? " · This session" : ""}`,
1141
+ status,
1142
+ note: owned && !released ? "View only. Po controls this session’s simulator." : "View only.",
1143
+ frame: pixels ? /* @__PURE__ */ jsx(Image, {
1144
+ accessibilityLabel: "Current simulator screen",
1145
+ source: { uri: pixels },
1146
+ resizeMode: "contain",
1147
+ style: styles.frame
1148
+ }) : /* @__PURE__ */ jsx(View, {
1149
+ style: styles.empty,
1150
+ children: /* @__PURE__ */ jsx(Text, {
1151
+ style: styles.dim,
1152
+ children: status
1153
+ })
1154
+ })
1155
+ });
1156
+ }
1157
+ const styles = StyleSheet.create((theme) => ({
1158
+ frame: {
1159
+ width: "100%",
1160
+ maxWidth: 240,
1161
+ aspectRatio: 9 / 19
1162
+ },
1163
+ empty: {
1164
+ padding: theme.spacing(6),
1165
+ uni__dependencies: [0]
1166
+ },
1167
+ dim: {
1168
+ color: theme.colors.dim,
1169
+ uni__dependencies: [0]
1170
+ }
1171
+ }));
1172
+ //#endregion
1173
+ //#region src/extensions/workspaces/sessions/(frontend)/_components/IosActivityPanel.native.tsx
1174
+ function iosActivityTab() {
1175
+ return {
1176
+ id: "ios-activity",
1177
+ label: "iOS",
1178
+ panel: IosActivityPanel
1179
+ };
1180
+ }
1181
+ function IosActivityPanel(props) {
1182
+ const activity = useIosActivity(props.sessionId);
1183
+ const [busy, setBusy] = useState(false);
1184
+ const [notice, setNotice] = useState("");
1185
+ const mounted = useRef(true);
1186
+ const currentBuild = useRef(`${props.sessionId}:${activity.build?.id}`);
1187
+ currentBuild.current = `${props.sessionId}:${activity.build?.id}`;
1188
+ useEffect(() => {
1189
+ mounted.current = true;
1190
+ return () => {
1191
+ mounted.current = false;
1192
+ };
1193
+ }, []);
1194
+ const build = activity.build;
1195
+ const artifactTab = build ? props.fileTabFor(`artifact:${build.artifactPath}`) : void 0;
1196
+ const share = async (copy) => {
1197
+ if (!props.sessionId || !build || busy) return;
1198
+ setBusy(true);
1199
+ setNotice("");
1200
+ try {
1201
+ const reply = await shareIosBuild(props.sessionId, build.id);
1202
+ if (!mounted.current || currentBuild.current !== `${props.sessionId}:${build.id}`) return;
1203
+ if (!reply.ok) {
1204
+ setNotice(reply.message);
1205
+ return;
1206
+ }
1207
+ await Share.share({
1208
+ url: reply.url,
1209
+ message: reply.url
1210
+ });
1211
+ } catch {
1212
+ if (mounted.current) setNotice("The download handoff was unavailable. Try again or open the build in Po.");
1213
+ } finally {
1214
+ if (mounted.current) setBusy(false);
1215
+ }
1216
+ };
1217
+ return /* @__PURE__ */ jsx(IosActivityView, {
1218
+ devices: activity.devices.map((device) => ({
1219
+ id: device.id,
1220
+ name: device.name,
1221
+ detail: deviceDetail(device),
1222
+ canView: canViewDevice(device)
1223
+ })),
1224
+ build: build ? {
1225
+ name: build.name,
1226
+ detail: `${(build.size / 1024 / 1024).toFixed(1)} MB`
1227
+ } : void 0,
1228
+ details: {
1229
+ note: activity.error ?? (!activity.supported ? "iOS is unavailable on this host." : !build ? "No build is registered for this session." : "Download this build without connecting a device."),
1230
+ action: busy ? "Preparing link" : "Download build",
1231
+ blocked: !build || busy
1232
+ },
1233
+ install: {
1234
+ note: "Direct install is unavailable. Compatible signing, registered phone eligibility and HTTPS installation have not been verified.",
1235
+ action: "Install unavailable",
1236
+ blocked: true
1237
+ },
1238
+ notice,
1239
+ busy,
1240
+ canOpen: !!artifactTab,
1241
+ footer: `Native download and copy use the system share sheet. Saving large build files directly is not available.${build && !artifactTab ? " This host cannot preview the build in Po." : ""}`,
1242
+ onView: (id) => {
1243
+ const device = activity.devices.find((item) => item.id === id);
1244
+ if (device && canViewDevice(device)) props.openTransientTab(iosDeviceTab(device));
1245
+ },
1246
+ onDownload: () => void share(false),
1247
+ onCopy: () => void share(true),
1248
+ onOpen: () => {
1249
+ if (artifactTab) props.openTransientTab(artifactTab);
1250
+ },
1251
+ onInstall: () => {}
1252
+ });
1253
+ }
1254
+ //#endregion
1255
+ //#region src/extensions/workspaces/sessions/(frontend)/activity-group/ios.native.ts
1256
+ var ios_native_default = defineActivityGroup({
1257
+ keys: "g i",
1258
+ icon: () => createElement(ActivityIcon),
1259
+ activeSource: iosActivitySource,
1260
+ marksBackgroundWork: false,
1261
+ order: 46,
1262
+ transientTab: iosActivityTab
1263
+ });
1264
+ //#endregion
1265
+ //#region src/extensions/workspaces/sessions/(frontend)/channel/ios-activity.native.ts
1266
+ var ios_activity_native_default = defineChannelFile(iosActivityChannel);
1267
+ //#endregion
1268
+ //#region src/extensions/workspaces/sessions/(frontend)/fill/Ios.activity.ios.native.tsx
1269
+ var Ios_activity_ios_native_default = defineFill({ component: IosActivityPanel });
1270
+ //#endregion
1271
+ //#region src/extensions/workspaces/sessions/(frontend)/lifecycle/start.native.ts
1272
+ var start_native_default = defineWebLifecycle(startIosRuntime);
1273
+ //#endregion
1274
+ //#region generated/native.ts
1275
+ const via = (identity, value) => value === void 0 ? void 0 : {
1276
+ ...identity,
1277
+ ...value
1278
+ };
1279
+ const nativePlugin = defineNativePlugin({
1280
+ id: "ios",
1281
+ global: {
1282
+ get settingsPanels() {
1283
+ return [via({ id: "ios" }, ios_panel_native_default)];
1284
+ },
1285
+ get start() {
1286
+ return start_native_default$1;
1287
+ }
1288
+ },
1289
+ session: {
1290
+ get activityGroups() {
1291
+ return [via({ name: "ios" }, ios_native_default)];
1292
+ },
1293
+ get channels() {
1294
+ return [via({ channel: "ios_activity" }, ios_activity_native_default)];
1295
+ },
1296
+ get fills() {
1297
+ return [via({
1298
+ slot: "activity.ios",
1299
+ id: "ios"
1300
+ }, Ios_activity_ios_native_default)];
1301
+ },
1302
+ get start() {
1303
+ return start_native_default;
1304
+ }
1305
+ }
1306
+ });
1307
+ //#endregion
1308
+ export { nativePlugin };
1309
+
1310
+ //# sourceMappingURL=native.mjs.map