@aixnn/aixautots 0.6.4 → 0.6.6
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/dist/{automation-queue-BxrSIkG3.d.ts → automation-queue-aYRO9JLj.d.ts} +2 -2
- package/dist/{chunk-JTFZSFFA.js → chunk-7H4CYM42.js} +414 -5
- package/dist/{chunk-UJO7BJUV.js → chunk-A2CKXQ7U.js} +876 -106
- package/dist/{chunk-SAB5CH2K.js → chunk-AVRM42RS.js} +578 -141
- package/dist/{chunk-M4DO7SSZ.js → chunk-D7J4EQTA.js} +1 -1
- package/dist/{chunk-B2BOVLI6.js → chunk-F76N3GOA.js} +1077 -313
- package/dist/{chunk-Q63FQ7B5.js → chunk-LWTL4AIC.js} +254 -13
- package/dist/chunk-QZ3XJS2W.js +102 -0
- package/dist/{chunk-NGW34POA.js → chunk-SF5R25DU.js} +318 -15
- package/dist/{chunk-YFF7VLNT.js → chunk-SKTL6ACT.js} +40 -2
- package/dist/{chunk-T3QVYTOT.js → chunk-WUT5OUBG.js} +418 -0
- package/dist/{chunk-BYL2S2H6.js → chunk-X5KVYWUK.js} +4 -5
- package/dist/{config-CLi5IhmO.d.ts → config-B7t1Ln3w.d.ts} +177 -8
- package/dist/core/index.d.ts +21 -16
- package/dist/core/index.js +2 -4
- package/dist/{device-normalize-BaThgnH7.d.ts → device-normalize-CuGflfZA.d.ts} +1 -1
- package/dist/device-session-OFGN4KUD.js +1 -0
- package/dist/i18n/index.js +1 -1
- package/dist/{mirror-session-BP7Rd3Jk.d.ts → mirror-session-DK0OQvA3.d.ts} +11 -3
- package/dist/react/index.d.ts +10 -8
- package/dist/react/index.js +3 -6
- package/dist/{script-debugger-DtUGxK9i.d.ts → script-debugger-6hoLEwEz.d.ts} +1 -1
- package/dist/{task-agent-runner-DzV_OUZ7.d.ts → task-agent-runner-BwRW88rl.d.ts} +5 -3
- package/dist/{types-C2WXVcam.d.ts → types-BbtVr3QM.d.ts} +34 -3
- package/dist/ui/billing.d.ts +1 -1
- package/dist/ui/billing.js +5 -9
- package/dist/ui/device-create.d.ts +4 -3
- package/dist/ui/device-create.js +7 -9
- package/dist/ui/device-mirror.d.ts +16 -2
- package/dist/ui/device-mirror.js +6 -8
- package/dist/ui/devices.d.ts +5 -5
- package/dist/ui/devices.js +10 -13
- package/dist/ui/editor.d.ts +2 -2
- package/dist/ui/editor.js +7 -11
- package/dist/ui/index.d.ts +4 -4
- package/dist/ui/index.js +9 -15
- package/dist/ui/inspector.js +5 -9
- package/dist/ui/market.js +4 -7
- package/dist/ui/mirror.d.ts +3 -3
- package/dist/ui/primitives/index.d.ts +1 -1
- package/dist/ui/primitives/index.js +1 -2
- package/dist/ui/script-studio.js +6 -10
- package/dist/ui/scripts.d.ts +1 -1
- package/dist/ui/scripts.js +5 -9
- package/dist/ui/tasks.js +10 -13
- package/package.json +1 -1
- package/dist/chunk-A5VNENHD.js +0 -229
- package/dist/chunk-BUW45GM2.js +0 -341
- package/dist/chunk-H37NHOYU.js +0 -44
- package/dist/chunk-LAZ3RQ7X.js +0 -668
- package/dist/device-session-CVT7OY4H.js +0 -2
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { MirrorSurface, DeviceMirror } from './chunk-NGW34POA.js';
|
|
1
|
+
import { LogConsole } from './chunk-D7J4EQTA.js';
|
|
2
|
+
import { requestPreviewFrame, MirrorSurface, DeviceMirror } from './chunk-SF5R25DU.js';
|
|
4
3
|
import { ControlBar, MirrorView } from './chunk-E7WMHM63.js';
|
|
5
|
-
import { createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
import { deviceProxyCapabilities, createProxyProbeGuard, proxySummaryFromDevice, isProxyApplyStatus, proxyCapabilityReason, proxyProbeExitIp, proxyProbeMessage, DeviceCreate, isProxyProbeUnsupported, isRedactedProxyUrl, isSupportedProxyUrl, redactProxyUrl } from './chunk-AVRM42RS.js';
|
|
5
|
+
import { isPhysicalIos, IosDeviceDiagnostics, canConnectPhysicalDevice } from './chunk-QZ3XJS2W.js';
|
|
6
|
+
import { useAixT, useAixLang } from './chunk-WUT5OUBG.js';
|
|
7
|
+
import { cn, Badge, Button, Dialog, Input, Popover, Select, useToast, ToastViewport, Drawer } from './chunk-SKTL6ACT.js';
|
|
8
|
+
import { useClient, useDevicesView, useShortcutsView, GROUP_MIRROR_MAX, useGroupMirror, useScripts, useFleetRun, useTaskAgentRun, preflightTaskAgentDevice, createAgentTaskRunner, useNodesView } from './chunk-LWTL4AIC.js';
|
|
9
|
+
import { DeviceSession, pushFile, pullFile } from './chunk-F76N3GOA.js';
|
|
11
10
|
import { useState, useRef, useCallback, useEffect, useMemo, useLayoutEffect } from 'react';
|
|
12
11
|
import * as Icons from 'lucide-react';
|
|
13
12
|
import { Monitor, Eye, Play, Power, RefreshCw, Server, Pencil, Trash2, FolderPlus, Upload, ArrowUp, Folder, File, Download, Dices, ShieldCheck, AlertTriangle, X, Crown, RotateCcw, Square, Plus, Search, LayoutGrid, List, ChevronLeft, Link, Link2Off, Terminal as Terminal$1, PackagePlus, MonitorPlay, ChevronRight, ChevronDown, PlusSquare, Maximize2, Info, ChevronsLeft, ChevronsRight, Check, Copy, Tablet, Smartphone } from 'lucide-react';
|
|
@@ -61,12 +60,13 @@ function DeviceCard({
|
|
|
61
60
|
const provisioned = device.meta.provisioned === true;
|
|
62
61
|
const offlineVirtual = !device.online && device.status !== "connecting" && provisioned;
|
|
63
62
|
const sleeping = device.meta.sleeping === true;
|
|
63
|
+
const physicalIos = isPhysicalIos(device);
|
|
64
64
|
const sleepPreview = typeof device.meta.sleep_preview === "string" ? device.meta.sleep_preview : null;
|
|
65
65
|
const [waking, setWaking] = useState(false);
|
|
66
66
|
const [wakeErr, setWakeErr] = useState(null);
|
|
67
67
|
const handleWake = async (e) => {
|
|
68
68
|
e.stopPropagation();
|
|
69
|
-
if (waking) return;
|
|
69
|
+
if (waking || physicalIos) return;
|
|
70
70
|
setWaking(true);
|
|
71
71
|
setWakeErr(null);
|
|
72
72
|
try {
|
|
@@ -88,10 +88,7 @@ function DeviceCard({
|
|
|
88
88
|
inFlightRef.current = true;
|
|
89
89
|
setShotLoading(true);
|
|
90
90
|
Promise.resolve(
|
|
91
|
-
client
|
|
92
|
-
op: "screenshot",
|
|
93
|
-
thumb: true
|
|
94
|
-
})
|
|
91
|
+
requestPreviewFrame(client, device.id)
|
|
95
92
|
).then((r) => {
|
|
96
93
|
const url = r.jpeg_base64 ? `data:image/jpeg;base64,${r.jpeg_base64}` : r.png_base64 ? `data:image/png;base64,${r.png_base64}` : null;
|
|
97
94
|
if (!url) return;
|
|
@@ -198,7 +195,7 @@ function DeviceCard({
|
|
|
198
195
|
"button",
|
|
199
196
|
{
|
|
200
197
|
type: "button",
|
|
201
|
-
disabled: waking,
|
|
198
|
+
disabled: waking || physicalIos,
|
|
202
199
|
onClick: handleWake,
|
|
203
200
|
className: "relative z-10 flex items-center gap-1.5 rounded-md bg-white/20 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-sm transition-colors hover:bg-white/30 disabled:opacity-60",
|
|
204
201
|
children: [
|
|
@@ -207,6 +204,7 @@ function DeviceCard({
|
|
|
207
204
|
]
|
|
208
205
|
}
|
|
209
206
|
),
|
|
207
|
+
physicalIos && /* @__PURE__ */ jsx("span", { className: "relative z-10 max-w-[90%] text-center text-xs text-white", children: t("drawer.iosSleepUnsupported") }),
|
|
210
208
|
wakeErr && /* @__PURE__ */ jsx("span", { className: "relative z-10 max-w-[90%] text-center text-[10px] font-medium text-red-300", children: wakeErr })
|
|
211
209
|
] }),
|
|
212
210
|
!sleeping && offlineVirtual && onPowerOn && /* @__PURE__ */ jsxs("div", { className: "absolute inset-0 flex flex-col items-center justify-center gap-2 bg-gradient-to-b from-zinc-900 to-black", children: [
|
|
@@ -288,6 +286,571 @@ function DeviceCard({
|
|
|
288
286
|
);
|
|
289
287
|
}
|
|
290
288
|
|
|
289
|
+
// src/ui/devices/managed-proxy-state.ts
|
|
290
|
+
function proxyRequestStorageKey(baseUrl, owner, project, deviceId) {
|
|
291
|
+
return owner ? `aix-managed-proxy:v1:${JSON.stringify([baseUrl, owner, project ?? "", deviceId])}` : null;
|
|
292
|
+
}
|
|
293
|
+
function readProxyRequest(key) {
|
|
294
|
+
if (!key) return null;
|
|
295
|
+
try {
|
|
296
|
+
const value = JSON.parse(localStorage.getItem(key) ?? "null");
|
|
297
|
+
if (!value || typeof value.requestId !== "string") return null;
|
|
298
|
+
if (value.action === "purchase" && typeof value.quoteId === "string") return value;
|
|
299
|
+
if (["rotate", "apply", "release"].includes(value.action) && "orderId" in value && typeof value.orderId === "string") return value;
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
function writeProxyRequest(key, request) {
|
|
305
|
+
if (!key) return;
|
|
306
|
+
if (request) localStorage.setItem(key, JSON.stringify(request));
|
|
307
|
+
else localStorage.removeItem(key);
|
|
308
|
+
}
|
|
309
|
+
function proxyOrderBusy(order) {
|
|
310
|
+
return !!order.pending_action || order.status === "pending" || order.status === "reconciling" || order.status === "fulfilled" && order.apply_status === "pending";
|
|
311
|
+
}
|
|
312
|
+
function isDefiniteProxyRejection(error) {
|
|
313
|
+
const state = error?.requestState;
|
|
314
|
+
if (state === "rejected") return true;
|
|
315
|
+
if (state === "unknown") return false;
|
|
316
|
+
const status = error?.status ?? error?.meta?.status;
|
|
317
|
+
return status !== void 0 && [400, 402, 403, 404, 410, 422].includes(status);
|
|
318
|
+
}
|
|
319
|
+
function mergeProxyOrders(history, active) {
|
|
320
|
+
const merged = new Map(history.map((order) => [order.id, order]));
|
|
321
|
+
for (const order of active) merged.set(order.id, order);
|
|
322
|
+
return [...merged.values()].sort((a, b) => {
|
|
323
|
+
const activeA = ["pending", "reconciling", "fulfilled"].includes(a.status) || !!a.pending_action;
|
|
324
|
+
const activeB = ["pending", "reconciling", "fulfilled"].includes(b.status) || !!b.pending_action;
|
|
325
|
+
return Number(activeB) - Number(activeA) || Date.parse(b.created_at) - Date.parse(a.created_at);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function proxySelectionFromMeta(meta) {
|
|
329
|
+
const source = meta.proxy_source;
|
|
330
|
+
const summary = meta.proxy_summary;
|
|
331
|
+
return {
|
|
332
|
+
kind: summary?.configured === false ? "direct" : source?.kind === "aixips" ? "aixips" : source?.kind === "custom" ? "custom" : "unknown",
|
|
333
|
+
orderId: source?.kind === "aixips" && typeof source.order_id === "string" ? source.order_id : void 0,
|
|
334
|
+
desiredRevision: typeof summary?.desired_revision === "number" ? summary.desired_revision : void 0,
|
|
335
|
+
observedRevision: typeof summary?.observed_revision === "number" ? summary.observed_revision : void 0,
|
|
336
|
+
observedStatus: typeof summary?.observed_status === "string" ? summary.observed_status : void 0
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function proxyOrderCurrentlyApplied(order, selection) {
|
|
340
|
+
return selection?.kind === "aixips" && selection.orderId === order.id && selection.desiredRevision !== void 0 && selection.desiredRevision === order.applied_revision && selection.observedRevision === selection.desiredRevision && selection.observedStatus === "applied";
|
|
341
|
+
}
|
|
342
|
+
function ConfirmDialog({
|
|
343
|
+
open,
|
|
344
|
+
title,
|
|
345
|
+
description,
|
|
346
|
+
confirmLabel,
|
|
347
|
+
cancelLabel,
|
|
348
|
+
destructive,
|
|
349
|
+
busy,
|
|
350
|
+
onConfirm,
|
|
351
|
+
onClose
|
|
352
|
+
}) {
|
|
353
|
+
const t = useAixT();
|
|
354
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onClose, title, description, children: /* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-end gap-2", children: [
|
|
355
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClose, disabled: busy, children: cancelLabel ?? t("common.cancel") }),
|
|
356
|
+
/* @__PURE__ */ jsx(
|
|
357
|
+
Button,
|
|
358
|
+
{
|
|
359
|
+
size: "sm",
|
|
360
|
+
variant: "primary",
|
|
361
|
+
disabled: busy,
|
|
362
|
+
className: destructive ? "bg-destructive text-white hover:bg-destructive/90" : "",
|
|
363
|
+
onClick: onConfirm,
|
|
364
|
+
children: confirmLabel ?? t("common.confirm")
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
] }) });
|
|
368
|
+
}
|
|
369
|
+
function ManagedProxyPanel(props) {
|
|
370
|
+
const client = useClient();
|
|
371
|
+
return /* @__PURE__ */ jsx(ManagedProxySession, { ...props }, JSON.stringify([client.cfg.baseUrl, props.ownerUserId, props.projectId, props.deviceId]));
|
|
372
|
+
}
|
|
373
|
+
function ManagedProxySession({ deviceId, ownerUserId, projectId, supported, selection, onChanged }) {
|
|
374
|
+
const client = useClient();
|
|
375
|
+
const t = useAixT();
|
|
376
|
+
const lang = useAixLang();
|
|
377
|
+
const storageKey = proxyRequestStorageKey(client.cfg.baseUrl, ownerUserId, projectId, deviceId);
|
|
378
|
+
const [catalog, setCatalog] = useState(null);
|
|
379
|
+
const [orders, setOrders] = useState([]);
|
|
380
|
+
const [kind, setKind] = useState("static");
|
|
381
|
+
const [productId, setProductId] = useState("");
|
|
382
|
+
const [quote, setQuote] = useState(null);
|
|
383
|
+
const [pending, setPending] = useState(() => readProxyRequest(storageKey));
|
|
384
|
+
const [busy, setBusy] = useState(false);
|
|
385
|
+
const [loading, setLoading] = useState(true);
|
|
386
|
+
const [ordersLoaded, setOrdersLoaded] = useState(false);
|
|
387
|
+
const [error, setError] = useState(null);
|
|
388
|
+
const [refreshError, setRefreshError] = useState(null);
|
|
389
|
+
const [activeFresh, setActiveFresh] = useState(false);
|
|
390
|
+
const [historyCount, setHistoryCount] = useState(0);
|
|
391
|
+
const [notice, setNotice] = useState(null);
|
|
392
|
+
const [releaseOrder, setReleaseOrder] = useState(null);
|
|
393
|
+
const [now, setNow] = useState(Date.now());
|
|
394
|
+
const active = useRef(true);
|
|
395
|
+
const lock = useRef(false);
|
|
396
|
+
const pendingRef = useRef(pending);
|
|
397
|
+
const refreshInFlight = useRef(null);
|
|
398
|
+
const fastPoll = useRef(false);
|
|
399
|
+
const changedCallback = useRef(onChanged);
|
|
400
|
+
const appliedSnapshot = useRef(null);
|
|
401
|
+
changedCallback.current = onChanged;
|
|
402
|
+
pendingRef.current = pending;
|
|
403
|
+
const money = (minor) => `\xA5${(minor / 100).toFixed(2)}`;
|
|
404
|
+
const duration = (seconds) => seconds % 86400 === 0 ? t("managed.days", { n: seconds / 86400 }) : seconds % 3600 === 0 ? t("managed.hours", { n: seconds / 3600 }) : seconds % 60 === 0 ? t("managed.minutes", { n: seconds / 60 }) : t("managed.seconds", { n: seconds });
|
|
405
|
+
const date = (value) => value ? new Date(value).toLocaleString(lang === "zh" ? "zh-CN" : "en-US") : "\u2014";
|
|
406
|
+
const clearPending = useCallback((requestId, accepted = false) => {
|
|
407
|
+
try {
|
|
408
|
+
const stored = readProxyRequest(storageKey);
|
|
409
|
+
if (!accepted && stored?.requestId === requestId && stored.uncertain) return;
|
|
410
|
+
if (!stored || stored.requestId === requestId) writeProxyRequest(storageKey, null);
|
|
411
|
+
} catch {
|
|
412
|
+
}
|
|
413
|
+
if (!requestId || pendingRef.current?.requestId === requestId) {
|
|
414
|
+
setPending(null);
|
|
415
|
+
pendingRef.current = null;
|
|
416
|
+
}
|
|
417
|
+
}, [storageKey]);
|
|
418
|
+
const refresh = useCallback(() => {
|
|
419
|
+
if (refreshInFlight.current) return refreshInFlight.current;
|
|
420
|
+
const run = async () => {
|
|
421
|
+
const [history, current] = await Promise.allSettled([
|
|
422
|
+
client.proxies.list(deviceId),
|
|
423
|
+
client.proxies.list(deviceId, { active: true })
|
|
424
|
+
]);
|
|
425
|
+
if (!active.current) return;
|
|
426
|
+
const currentOk = current.status === "fulfilled";
|
|
427
|
+
setActiveFresh(currentOk);
|
|
428
|
+
if (currentOk) setOrdersLoaded(true);
|
|
429
|
+
if (history.status === "fulfilled") setHistoryCount(history.value.length);
|
|
430
|
+
const failures = [current, history].filter((result) => result.status === "rejected");
|
|
431
|
+
setRefreshError(failures.length ? failures[0].reason?.message ?? "Unable to refresh orders" : null);
|
|
432
|
+
if (history.status === "fulfilled" || currentOk) {
|
|
433
|
+
setOrders((previous) => mergeProxyOrders(
|
|
434
|
+
history.status === "fulfilled" ? history.value : previous,
|
|
435
|
+
currentOk ? current.value : previous.filter((order) => ["pending", "reconciling", "fulfilled"].includes(order.status))
|
|
436
|
+
));
|
|
437
|
+
}
|
|
438
|
+
const changed = currentOk ? JSON.stringify(current.value.map((order) => [order.id, order.apply_status, order.applied_revision])) : null;
|
|
439
|
+
if (changed !== null) {
|
|
440
|
+
if (appliedSnapshot.current !== null && appliedSnapshot.current !== changed) changedCallback.current?.();
|
|
441
|
+
appliedSnapshot.current = changed;
|
|
442
|
+
}
|
|
443
|
+
const request = pendingRef.current;
|
|
444
|
+
if (request) {
|
|
445
|
+
const visible = [...currentOk ? current.value : [], ...history.status === "fulfilled" ? history.value : []];
|
|
446
|
+
const match = visible.find((order) => request.action === "purchase" ? order.request_id === request.requestId : order.pending_request_id === request.requestId);
|
|
447
|
+
try {
|
|
448
|
+
const recovered = match ?? await client.proxies.byRequest(deviceId, request.requestId);
|
|
449
|
+
if (!active.current || pendingRef.current?.requestId !== request.requestId) return;
|
|
450
|
+
setOrders((previous) => mergeProxyOrders(previous, [recovered]));
|
|
451
|
+
clearPending(request.requestId, true);
|
|
452
|
+
} catch {
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const promise = run().finally(() => {
|
|
457
|
+
refreshInFlight.current = null;
|
|
458
|
+
});
|
|
459
|
+
refreshInFlight.current = promise;
|
|
460
|
+
return promise;
|
|
461
|
+
}, [client, deviceId, clearPending]);
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
active.current = true;
|
|
464
|
+
let timer;
|
|
465
|
+
const poll = async () => {
|
|
466
|
+
if (document.visibilityState !== "hidden") await refresh();
|
|
467
|
+
if (active.current) timer = setTimeout(() => void poll(), fastPoll.current ? 3e3 : 3e4);
|
|
468
|
+
};
|
|
469
|
+
void Promise.all([client.proxies.catalog().then((value) => {
|
|
470
|
+
if (active.current) setCatalog(value);
|
|
471
|
+
}), refresh()]).catch((e) => {
|
|
472
|
+
if (active.current) setError(e.message);
|
|
473
|
+
}).finally(() => {
|
|
474
|
+
if (active.current) {
|
|
475
|
+
setLoading(false);
|
|
476
|
+
timer = setTimeout(() => void poll(), fastPoll.current ? 3e3 : 3e4);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
const clock = setInterval(() => setNow(Date.now()), 1e3);
|
|
480
|
+
const visible = () => {
|
|
481
|
+
if (document.visibilityState === "visible") void refresh();
|
|
482
|
+
};
|
|
483
|
+
const storage = (event) => {
|
|
484
|
+
if (event.key !== storageKey) return;
|
|
485
|
+
const request = readProxyRequest(storageKey);
|
|
486
|
+
pendingRef.current = request;
|
|
487
|
+
setPending(request);
|
|
488
|
+
void refresh();
|
|
489
|
+
};
|
|
490
|
+
document.addEventListener("visibilitychange", visible);
|
|
491
|
+
window.addEventListener("storage", storage);
|
|
492
|
+
return () => {
|
|
493
|
+
active.current = false;
|
|
494
|
+
clearTimeout(timer);
|
|
495
|
+
clearInterval(clock);
|
|
496
|
+
document.removeEventListener("visibilitychange", visible);
|
|
497
|
+
window.removeEventListener("storage", storage);
|
|
498
|
+
};
|
|
499
|
+
}, [client, refresh, storageKey]);
|
|
500
|
+
const products = catalog?.products.filter((product) => product.kind === kind) ?? [];
|
|
501
|
+
const selected = products.find((product) => product.id === productId) ?? products[0];
|
|
502
|
+
const expired = quote ? !Number.isFinite(Date.parse(quote.expires_at)) || Date.parse(quote.expires_at) <= now : false;
|
|
503
|
+
const processing = orders.some(proxyOrderBusy);
|
|
504
|
+
fastPoll.current = !!pending || processing;
|
|
505
|
+
const disabled = !supported || !storageKey || busy || loading || !ordersLoaded || !activeFresh || !!pending || processing;
|
|
506
|
+
const requestQuote = async (id, replacesOrderId) => {
|
|
507
|
+
if (!supported || lock.current || pendingRef.current) return;
|
|
508
|
+
lock.current = true;
|
|
509
|
+
setBusy(true);
|
|
510
|
+
setError(null);
|
|
511
|
+
setNotice(null);
|
|
512
|
+
setQuote(null);
|
|
513
|
+
try {
|
|
514
|
+
const value = await client.proxies.quote({ device_id: deviceId, product_id: id, ...replacesOrderId ? { replaces_order_id: replacesOrderId } : {} });
|
|
515
|
+
if (active.current) {
|
|
516
|
+
setQuote(value);
|
|
517
|
+
setNow(Date.now());
|
|
518
|
+
}
|
|
519
|
+
} catch (e) {
|
|
520
|
+
if (active.current) setError(e.message);
|
|
521
|
+
} finally {
|
|
522
|
+
lock.current = false;
|
|
523
|
+
if (active.current) setBusy(false);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const execute = async (request) => {
|
|
527
|
+
if (lock.current || !supported && request.action !== "release") return;
|
|
528
|
+
lock.current = true;
|
|
529
|
+
setBusy(true);
|
|
530
|
+
setError(null);
|
|
531
|
+
setNotice(null);
|
|
532
|
+
const run = async () => {
|
|
533
|
+
let uncertain = !!request.uncertain;
|
|
534
|
+
let sent = false;
|
|
535
|
+
try {
|
|
536
|
+
if (!storageKey) throw new Error(t("managed.identityUnavailable"));
|
|
537
|
+
const existing = readProxyRequest(storageKey);
|
|
538
|
+
if (existing && existing.requestId !== request.requestId) {
|
|
539
|
+
pendingRef.current = existing;
|
|
540
|
+
setPending(existing);
|
|
541
|
+
throw new Error(t("managed.otherRequest"));
|
|
542
|
+
}
|
|
543
|
+
uncertain ||= pendingRef.current?.requestId === request.requestId || existing?.requestId === request.requestId;
|
|
544
|
+
const durable = uncertain ? { ...request, uncertain: true } : request;
|
|
545
|
+
writeProxyRequest(storageKey, durable);
|
|
546
|
+
setPending(durable);
|
|
547
|
+
pendingRef.current = durable;
|
|
548
|
+
sent = true;
|
|
549
|
+
const order = request.action === "purchase" ? await client.proxies.purchase({ quote_id: request.quoteId, request_id: request.requestId }) : await client.proxies[request.action](request.orderId, request.requestId);
|
|
550
|
+
if (!active.current) return;
|
|
551
|
+
clearPending(request.requestId, true);
|
|
552
|
+
setQuote(null);
|
|
553
|
+
setReleaseOrder(null);
|
|
554
|
+
setOrders((previous) => [order, ...previous.filter((item) => item.id !== order.id)]);
|
|
555
|
+
setNotice(t("managed.accepted"));
|
|
556
|
+
onChanged?.();
|
|
557
|
+
await refresh();
|
|
558
|
+
} catch (e) {
|
|
559
|
+
if (!active.current) return;
|
|
560
|
+
const stored = readProxyRequest(storageKey);
|
|
561
|
+
uncertain ||= stored?.requestId === request.requestId && !!stored.uncertain;
|
|
562
|
+
if (sent && isDefiniteProxyRejection(e) && !uncertain) {
|
|
563
|
+
clearPending(request.requestId);
|
|
564
|
+
setQuote(null);
|
|
565
|
+
} else if (sent) {
|
|
566
|
+
if (stored?.requestId === request.requestId) {
|
|
567
|
+
const durable = { ...stored, uncertain: true };
|
|
568
|
+
try {
|
|
569
|
+
writeProxyRequest(storageKey, durable);
|
|
570
|
+
} catch {
|
|
571
|
+
}
|
|
572
|
+
pendingRef.current = durable;
|
|
573
|
+
setPending(durable);
|
|
574
|
+
}
|
|
575
|
+
await refresh();
|
|
576
|
+
}
|
|
577
|
+
if (active.current) setError(e.message);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
try {
|
|
581
|
+
if (storageKey && navigator.locks?.request) {
|
|
582
|
+
await navigator.locks.request(storageKey, { mode: "exclusive", ifAvailable: true }, async (held) => {
|
|
583
|
+
if (held) return run();
|
|
584
|
+
const existing = readProxyRequest(storageKey);
|
|
585
|
+
if (active.current) {
|
|
586
|
+
pendingRef.current = existing;
|
|
587
|
+
setPending(existing);
|
|
588
|
+
setNotice(t("managed.otherRequest"));
|
|
589
|
+
await refresh();
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
} else await run();
|
|
593
|
+
} catch (e) {
|
|
594
|
+
if (active.current) setError(e.message);
|
|
595
|
+
} finally {
|
|
596
|
+
lock.current = false;
|
|
597
|
+
if (active.current) setBusy(false);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const act = (action, orderId) => void execute({ action, orderId, requestId: crypto.randomUUID() });
|
|
601
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3 rounded-lg border border-border p-3 text-xs", "aria-busy": busy || loading, children: [
|
|
602
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
603
|
+
/* @__PURE__ */ jsx("h4", { className: "font-semibold", children: t("managed.title") }),
|
|
604
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || loading, onClick: () => {
|
|
605
|
+
setError(null);
|
|
606
|
+
setLoading(true);
|
|
607
|
+
void Promise.all([refresh(), client.proxies.catalog().then((value) => {
|
|
608
|
+
if (active.current) setCatalog(value);
|
|
609
|
+
})]).catch((e) => {
|
|
610
|
+
if (active.current) setError(e.message);
|
|
611
|
+
}).finally(() => {
|
|
612
|
+
if (active.current) setLoading(false);
|
|
613
|
+
});
|
|
614
|
+
}, children: t("common.refresh") })
|
|
615
|
+
] }),
|
|
616
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.description") }),
|
|
617
|
+
selection && /* @__PURE__ */ jsx("p", { children: t(`managed.selection.${selection.kind}`) }),
|
|
618
|
+
!storageKey && /* @__PURE__ */ jsx("p", { className: "text-warning", children: t("managed.identityUnavailable") }),
|
|
619
|
+
!supported && /* @__PURE__ */ jsx("p", { className: "text-warning", children: t("managed.unsupported") }),
|
|
620
|
+
loading && /* @__PURE__ */ jsx("p", { role: "status", children: t("common.loading") }),
|
|
621
|
+
refreshError && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-warning", children: t("managed.refreshFailed", { error: refreshError }) }),
|
|
622
|
+
error && /* @__PURE__ */ jsx("p", { role: "alert", className: "break-words text-destructive", children: error }),
|
|
623
|
+
notice && /* @__PURE__ */ jsx("p", { role: "status", className: "text-muted-foreground", children: notice }),
|
|
624
|
+
pending && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded border border-warning/50 p-2", children: [
|
|
625
|
+
/* @__PURE__ */ jsx("p", { children: t("managed.unknown") }),
|
|
626
|
+
/* @__PURE__ */ jsxs("p", { className: "break-all text-muted-foreground", children: [
|
|
627
|
+
t("managed.request"),
|
|
628
|
+
": ",
|
|
629
|
+
pending.requestId
|
|
630
|
+
] }),
|
|
631
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", disabled: busy || !storageKey || !supported && pending.action !== "release", onClick: () => void execute(pending), children: t("managed.retry") })
|
|
632
|
+
] }),
|
|
633
|
+
catalog && !catalog.enabled && /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
|
|
634
|
+
t("managed.unavailable"),
|
|
635
|
+
catalog.unavailable_reason ? `: ${catalog.unavailable_reason}` : ""
|
|
636
|
+
] }),
|
|
637
|
+
catalog?.enabled && supported && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
638
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", role: "group", "aria-label": t("managed.kind"), children: ["static", "dynamic"].map((value) => /* @__PURE__ */ jsx(Button, { size: "sm", variant: kind === value ? "primary" : "secondary", "aria-pressed": kind === value, disabled, onClick: () => {
|
|
639
|
+
setKind(value);
|
|
640
|
+
setQuote(null);
|
|
641
|
+
setProductId("");
|
|
642
|
+
}, children: t(`managed.${value}`) }, value)) }),
|
|
643
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t(`managed.${kind}Hint`) }),
|
|
644
|
+
selected ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
645
|
+
/* @__PURE__ */ jsxs("label", { className: "block space-y-1", children: [
|
|
646
|
+
/* @__PURE__ */ jsx("span", { children: t("managed.product") }),
|
|
647
|
+
/* @__PURE__ */ jsx("select", { className: "w-full min-h-10 rounded-md border border-border bg-secondary px-2 focus-visible:outline focus-visible:outline-2 focus-visible:outline-primary", value: selected.id, disabled, onChange: (event) => {
|
|
648
|
+
setProductId(event.target.value);
|
|
649
|
+
setQuote(null);
|
|
650
|
+
}, children: products.map((product) => /* @__PURE__ */ jsxs("option", { value: product.id, children: [
|
|
651
|
+
product.region,
|
|
652
|
+
" \xB7 ",
|
|
653
|
+
product.name,
|
|
654
|
+
" \xB7 ",
|
|
655
|
+
duration(product.duration_seconds),
|
|
656
|
+
" \xB7 ",
|
|
657
|
+
money(product.cost_minor)
|
|
658
|
+
] }, product.id)) })
|
|
659
|
+
] }),
|
|
660
|
+
/* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(selected.quota_value) }) }),
|
|
661
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => void requestQuote(selected.id), children: t("managed.quote") })
|
|
662
|
+
] }) : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.emptyCatalog") })
|
|
663
|
+
] }),
|
|
664
|
+
quote && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border border-primary/40 bg-secondary/40 p-3", children: [
|
|
665
|
+
/* @__PURE__ */ jsx("h5", { className: "font-semibold", children: quote.replaces_order_id ? t("managed.replaceQuote") : t("managed.quoteTitle") }),
|
|
666
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
667
|
+
t(`managed.${quote.product.kind}`),
|
|
668
|
+
" \xB7 ",
|
|
669
|
+
quote.product.region,
|
|
670
|
+
" \xB7 ",
|
|
671
|
+
duration(quote.product.duration_seconds)
|
|
672
|
+
] }),
|
|
673
|
+
/* @__PURE__ */ jsx("p", { children: t("managed.budget", { amount: money(quote.product.quota_value) }) }),
|
|
674
|
+
/* @__PURE__ */ jsx("p", { children: t("managed.total", { amount: money(quote.total_minor) }) }),
|
|
675
|
+
quote.product.fixed_cost_minor != null && /* @__PURE__ */ jsx("p", { children: t("managed.fixedCost", { amount: money(quote.product.fixed_cost_minor) }) }),
|
|
676
|
+
quote.product.rate_minor_per_gib != null && /* @__PURE__ */ jsx("p", { children: t("managed.rate", { amount: money(quote.product.rate_minor_per_gib) }) }),
|
|
677
|
+
quote.product.refund_policy === "no_refund_after_allocation" && /* @__PURE__ */ jsx("p", { children: t("managed.noRefund") }),
|
|
678
|
+
quote.product.budget_accounting === "reserved_upper_bound" && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.reservations", { kib: (quote.product.reservation_bytes ?? 16384) / 1024 }) }),
|
|
679
|
+
quote.product.handshake_reservation_bytes != null && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.handshakeReservation", { kib: quote.product.handshake_reservation_bytes / 1024 }) }),
|
|
680
|
+
/* @__PURE__ */ jsx("p", { children: quote.product.replacement_policy.mode === "free" ? t("managed.freeRotate") : t("managed.newPurchase") }),
|
|
681
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.noRenew") }),
|
|
682
|
+
/* @__PURE__ */ jsx("p", { className: expired ? "text-warning" : "text-muted-foreground", children: expired ? t("managed.quoteExpired") : t("managed.quoteExpiry", { at: date(quote.expires_at) }) }),
|
|
683
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", disabled: disabled || expired, onClick: () => {
|
|
684
|
+
if (Date.parse(quote.expires_at) <= Date.now()) {
|
|
685
|
+
setNow(Date.now());
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
void execute({ action: "purchase", quoteId: quote.id, requestId: crypto.randomUUID() });
|
|
689
|
+
}, children: t("managed.pay", { amount: money(quote.total_minor) }) })
|
|
690
|
+
] }),
|
|
691
|
+
historyCount >= 100 && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("managed.historyLimit") }),
|
|
692
|
+
!!orders.length && /* @__PURE__ */ jsx("ul", { "aria-label": t("managed.orders"), className: "space-y-2", children: orders.map((order) => /* @__PURE__ */ jsxs("li", { className: "space-y-2 rounded border border-border p-2", children: [
|
|
693
|
+
/* @__PURE__ */ jsxs("p", { className: "font-medium", children: [
|
|
694
|
+
t(`managed.${order.product.kind}`),
|
|
695
|
+
" \xB7 ",
|
|
696
|
+
order.product.region
|
|
697
|
+
] }),
|
|
698
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
699
|
+
t(`managed.status.${order.status}`),
|
|
700
|
+
" \xB7 ",
|
|
701
|
+
t(order.apply_status === "applied" ? proxyOrderCurrentlyApplied(order, selection) ? "managed.currentlyApplied" : "managed.previouslyApplied" : `managed.apply.${order.apply_status}`)
|
|
702
|
+
] }),
|
|
703
|
+
selection?.kind === "aixips" && selection.orderId === order.id && /* @__PURE__ */ jsx("p", { className: "font-medium", children: t("managed.selectedOrder") }),
|
|
704
|
+
order.pending_action && /* @__PURE__ */ jsxs("p", { role: "status", children: [
|
|
705
|
+
t("managed.processing"),
|
|
706
|
+
": ",
|
|
707
|
+
t(`managed.action.${order.pending_action}`)
|
|
708
|
+
] }),
|
|
709
|
+
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
|
|
710
|
+
t("managed.total", { amount: money(order.total_minor) }),
|
|
711
|
+
" \xB7 ",
|
|
712
|
+
t("managed.expires", { at: date(order.expires_at) })
|
|
713
|
+
] }),
|
|
714
|
+
/* @__PURE__ */ jsx("p", { children: t("managed.remaining", { amount: order.remaining_budget_minor == null ? "\u2014" : order.status === "fulfilled" && order.remaining_budget_minor === 0 ? t("managed.fractionalBalance") : money(order.remaining_budget_minor) }) }),
|
|
715
|
+
order.failure_reason && /* @__PURE__ */ jsx("p", { className: "break-words text-destructive", children: order.failure_reason }),
|
|
716
|
+
order.status === "fulfilled" && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
|
|
717
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => act("apply", order.id), children: t("managed.apply") }),
|
|
718
|
+
order.product.kind === "dynamic" && order.product.replacement_policy.mode === "free" ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled, onClick: () => act("rotate", order.id), children: t("managed.rotate") }) : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled: disabled || !catalog?.enabled, onClick: () => void requestQuote(order.product.id, order.id), children: t("managed.replace") }),
|
|
719
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: !storageKey || busy || loading || !ordersLoaded || !!pending || order.pending_action === "release", onClick: () => setReleaseOrder(order), children: t("managed.release") })
|
|
720
|
+
] }),
|
|
721
|
+
/* @__PURE__ */ jsxs("p", { className: "break-all text-muted-foreground", children: [
|
|
722
|
+
t("managed.order"),
|
|
723
|
+
": ",
|
|
724
|
+
order.id
|
|
725
|
+
] })
|
|
726
|
+
] }, order.id)) }),
|
|
727
|
+
/* @__PURE__ */ jsx(ConfirmDialog, { open: !!releaseOrder, title: t("managed.releaseTitle"), description: t("managed.releaseDescription"), confirmLabel: t("managed.release"), busy, destructive: true, onClose: () => {
|
|
728
|
+
if (!busy) setReleaseOrder(null);
|
|
729
|
+
}, onConfirm: () => {
|
|
730
|
+
if (releaseOrder) act("release", releaseOrder.id);
|
|
731
|
+
} })
|
|
732
|
+
] });
|
|
733
|
+
}
|
|
734
|
+
function supportsDataSnapshots(meta) {
|
|
735
|
+
const spec = meta.spec;
|
|
736
|
+
const platform = typeof meta.platform === "string" ? meta.platform : spec?.platform;
|
|
737
|
+
return meta.provisioned === true && spec?.kind !== "android-real" && spec?.platform !== "android-real" && (platform == null || platform === "android" || platform === "redroid");
|
|
738
|
+
}
|
|
739
|
+
function DeviceSnapshotsPanel(props) {
|
|
740
|
+
return /* @__PURE__ */ jsx(SnapshotWorkspace, { ...props }, props.deviceId);
|
|
741
|
+
}
|
|
742
|
+
function SnapshotWorkspace({ deviceId, online, supported, onChanged }) {
|
|
743
|
+
const client = useClient();
|
|
744
|
+
const t = useAixT();
|
|
745
|
+
const alive = useRef(true);
|
|
746
|
+
const request = useRef(0);
|
|
747
|
+
const mutation = useRef(false);
|
|
748
|
+
const [snapshots, setSnapshots] = useState([]);
|
|
749
|
+
const [current, setCurrent] = useState(null);
|
|
750
|
+
const [label, setLabel] = useState("");
|
|
751
|
+
const [loading, setLoading] = useState(false);
|
|
752
|
+
const [busy, setBusy] = useState(false);
|
|
753
|
+
const [error, setError] = useState(null);
|
|
754
|
+
const [notice, setNotice] = useState(null);
|
|
755
|
+
const [pending, setPending] = useState(null);
|
|
756
|
+
const refresh = useCallback(async () => {
|
|
757
|
+
const token = ++request.current;
|
|
758
|
+
setLoading(true);
|
|
759
|
+
try {
|
|
760
|
+
const result = await client.devices.listSnapshots(deviceId);
|
|
761
|
+
if (!alive.current || request.current !== token) return;
|
|
762
|
+
setSnapshots(result.snapshots);
|
|
763
|
+
setCurrent(result.current_snapshot);
|
|
764
|
+
} catch (e) {
|
|
765
|
+
if (alive.current && request.current === token) setError(String(e.message ?? e));
|
|
766
|
+
} finally {
|
|
767
|
+
if (alive.current && request.current === token) setLoading(false);
|
|
768
|
+
}
|
|
769
|
+
}, [client, deviceId]);
|
|
770
|
+
useEffect(() => {
|
|
771
|
+
alive.current = true;
|
|
772
|
+
if (supported) void refresh();
|
|
773
|
+
return () => {
|
|
774
|
+
alive.current = false;
|
|
775
|
+
request.current++;
|
|
776
|
+
};
|
|
777
|
+
}, [refresh, supported]);
|
|
778
|
+
const mutate = async (action, snapshot) => {
|
|
779
|
+
if (!online || !supported || mutation.current || action === "save" && !label.trim()) return;
|
|
780
|
+
mutation.current = true;
|
|
781
|
+
setBusy(true);
|
|
782
|
+
setError(null);
|
|
783
|
+
setNotice(null);
|
|
784
|
+
try {
|
|
785
|
+
if (action === "save") await client.devices.createSnapshot(deviceId, { label: label.trim() });
|
|
786
|
+
else if (action === "load") await client.devices.loadSnapshot(deviceId, snapshot.name);
|
|
787
|
+
else await client.devices.deleteSnapshot(deviceId, snapshot.name);
|
|
788
|
+
if (!alive.current) return;
|
|
789
|
+
if (action === "save") setLabel("");
|
|
790
|
+
setPending(null);
|
|
791
|
+
setNotice(t(`snapshots.done.${action}`));
|
|
792
|
+
onChanged?.();
|
|
793
|
+
await refresh();
|
|
794
|
+
} catch (e) {
|
|
795
|
+
if (alive.current) {
|
|
796
|
+
setPending(null);
|
|
797
|
+
setError(String(e.message ?? e));
|
|
798
|
+
}
|
|
799
|
+
} finally {
|
|
800
|
+
mutation.current = false;
|
|
801
|
+
if (alive.current) setBusy(false);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
if (!supported) return /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("snapshots.unsupported") });
|
|
805
|
+
return /* @__PURE__ */ jsxs("section", { className: "space-y-3 text-xs", "aria-label": t("snapshots.title"), "aria-busy": busy || loading, children: [
|
|
806
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
807
|
+
/* @__PURE__ */ jsx("h3", { className: "font-semibold", children: t("snapshots.title") }),
|
|
808
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || loading, onClick: () => {
|
|
809
|
+
setError(null);
|
|
810
|
+
void refresh();
|
|
811
|
+
}, children: t("common.refresh") })
|
|
812
|
+
] }),
|
|
813
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("snapshots.description") }),
|
|
814
|
+
!online && /* @__PURE__ */ jsx("p", { className: "text-warning", children: t("snapshots.offline") }),
|
|
815
|
+
/* @__PURE__ */ jsxs("form", { className: "flex gap-2", onSubmit: (e) => {
|
|
816
|
+
e.preventDefault();
|
|
817
|
+
void mutate("save");
|
|
818
|
+
}, children: [
|
|
819
|
+
/* @__PURE__ */ jsx(Input, { "aria-label": t("snapshots.label"), placeholder: t("snapshots.label"), value: label, maxLength: 120, disabled: busy || !online, onChange: (e) => setLabel(e.target.value) }),
|
|
820
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", size: "sm", disabled: busy || !online || !label.trim(), children: t("common.save") })
|
|
821
|
+
] }),
|
|
822
|
+
busy && /* @__PURE__ */ jsx("p", { role: "status", children: t("snapshots.busy") }),
|
|
823
|
+
error && /* @__PURE__ */ jsxs("div", { role: "alert", className: "text-destructive", children: [
|
|
824
|
+
/* @__PURE__ */ jsx("p", { children: error }),
|
|
825
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || loading, onClick: () => {
|
|
826
|
+
setError(null);
|
|
827
|
+
void refresh();
|
|
828
|
+
}, children: t("snapshots.retry") })
|
|
829
|
+
] }),
|
|
830
|
+
notice && /* @__PURE__ */ jsx("p", { role: "status", children: notice }),
|
|
831
|
+
loading && /* @__PURE__ */ jsx("p", { children: t("common.loading") }),
|
|
832
|
+
!loading && snapshots.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("snapshots.empty") }),
|
|
833
|
+
/* @__PURE__ */ jsx("ul", { className: "max-h-96 overflow-y-auto space-y-2", "aria-label": t("snapshots.list"), children: snapshots.map((snapshot) => /* @__PURE__ */ jsxs("li", { className: "rounded border border-border p-3 space-y-2", children: [
|
|
834
|
+
/* @__PURE__ */ jsx("div", { className: "break-words font-medium", children: snapshot.label || snapshot.name }),
|
|
835
|
+
current === snapshot.name && /* @__PURE__ */ jsx("p", { className: "text-primary", children: t("snapshots.current") }),
|
|
836
|
+
/* @__PURE__ */ jsxs("p", { className: "text-muted-foreground break-words", children: [
|
|
837
|
+
new Date(snapshot.created_at).toLocaleString(),
|
|
838
|
+
" \xB7 ",
|
|
839
|
+
snapshot.size_bytes == null ? "\u2014" : `${(snapshot.size_bytes / 1048576).toFixed(1)} MB`
|
|
840
|
+
] }),
|
|
841
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
842
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", disabled: busy || !online, onClick: () => setPending({ action: "load", snapshot }), children: t("snapshots.load") }),
|
|
843
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy || !online || current === snapshot.name, onClick: () => setPending({ action: "delete", snapshot }), children: t("common.delete") })
|
|
844
|
+
] })
|
|
845
|
+
] }, snapshot.name)) }),
|
|
846
|
+
/* @__PURE__ */ jsx(ConfirmDialog, { open: pending !== null, title: t(pending?.action === "delete" ? "snapshots.deleteTitle" : "snapshots.loadTitle"), description: t(pending?.action === "delete" ? "snapshots.deleteConfirm" : "snapshots.loadConfirm", { name: pending?.snapshot.label || pending?.snapshot.name || "" }), confirmLabel: t(pending?.action === "delete" ? "common.delete" : "snapshots.load"), destructive: true, busy: busy || !online, onClose: () => {
|
|
847
|
+
if (!busy) setPending(null);
|
|
848
|
+
}, onConfirm: () => {
|
|
849
|
+
if (pending) void mutate(pending.action, pending.snapshot);
|
|
850
|
+
} })
|
|
851
|
+
] });
|
|
852
|
+
}
|
|
853
|
+
|
|
291
854
|
// src/ui/devices/file-transfer.ts
|
|
292
855
|
function triggerDownload(bytes, filename) {
|
|
293
856
|
const blob = new Blob([bytes.slice().buffer]);
|
|
@@ -1388,33 +1951,6 @@ function ShortcutRunDialog({ shortcut, deviceIds, onClose, onRun }) {
|
|
|
1388
1951
|
] })
|
|
1389
1952
|
] }) });
|
|
1390
1953
|
}
|
|
1391
|
-
function ConfirmDialog({
|
|
1392
|
-
open,
|
|
1393
|
-
title,
|
|
1394
|
-
description,
|
|
1395
|
-
confirmLabel,
|
|
1396
|
-
cancelLabel,
|
|
1397
|
-
destructive,
|
|
1398
|
-
busy,
|
|
1399
|
-
onConfirm,
|
|
1400
|
-
onClose
|
|
1401
|
-
}) {
|
|
1402
|
-
const t = useAixT();
|
|
1403
|
-
return /* @__PURE__ */ jsx(Dialog, { open, onClose, title, description, children: /* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-end gap-2", children: [
|
|
1404
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClose, disabled: busy, children: cancelLabel ?? t("common.cancel") }),
|
|
1405
|
-
/* @__PURE__ */ jsx(
|
|
1406
|
-
Button,
|
|
1407
|
-
{
|
|
1408
|
-
size: "sm",
|
|
1409
|
-
variant: "primary",
|
|
1410
|
-
disabled: busy,
|
|
1411
|
-
className: destructive ? "bg-destructive text-white hover:bg-destructive/90" : "",
|
|
1412
|
-
onClick: onConfirm,
|
|
1413
|
-
children: confirmLabel ?? t("common.confirm")
|
|
1414
|
-
}
|
|
1415
|
-
)
|
|
1416
|
-
] }) });
|
|
1417
|
-
}
|
|
1418
1954
|
function ShortcutEditDialog({ initial, onClose, onSaved, onDeleted }) {
|
|
1419
1955
|
const t = useAixT();
|
|
1420
1956
|
const { create, update, remove, error } = useShortcutsView();
|
|
@@ -2555,6 +3091,23 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2555
3091
|
const client = useClient();
|
|
2556
3092
|
const { devices, fetchDevices } = useDevicesView();
|
|
2557
3093
|
const device = devices.find((d) => d.id === deviceId) ?? null;
|
|
3094
|
+
const physicalIos = device ? isPhysicalIos(device) : false;
|
|
3095
|
+
const [proxyNode, setProxyNode] = useState(null);
|
|
3096
|
+
const proxyNodeId = device?.meta.node_id;
|
|
3097
|
+
const proxyCapability = deviceProxyCapabilities(device, proxyNode);
|
|
3098
|
+
useEffect(() => {
|
|
3099
|
+
let cancelled = false;
|
|
3100
|
+
setProxyNode(null);
|
|
3101
|
+
if (deviceId && typeof proxyNodeId === "string") {
|
|
3102
|
+
void client.nodes.list().then((nodes) => {
|
|
3103
|
+
if (!cancelled) setProxyNode(nodes.find((node) => node.id === proxyNodeId) ?? null);
|
|
3104
|
+
}).catch(() => {
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
return () => {
|
|
3108
|
+
cancelled = true;
|
|
3109
|
+
};
|
|
3110
|
+
}, [client, deviceId, proxyNodeId]);
|
|
2558
3111
|
const proxyProbeGuard = useRef(createProxyProbeGuard());
|
|
2559
3112
|
proxyProbeGuard.current.sync(deviceId);
|
|
2560
3113
|
const { toasts, toast, dismiss } = useToast();
|
|
@@ -2636,6 +3189,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2636
3189
|
});
|
|
2637
3190
|
};
|
|
2638
3191
|
const probeProxy = async (id) => {
|
|
3192
|
+
if (!proxyCapability.custom) return;
|
|
2639
3193
|
const token = proxyProbeGuard.current.begin(id);
|
|
2640
3194
|
if (token === null) return;
|
|
2641
3195
|
setProxyProbeLoading(true);
|
|
@@ -2706,7 +3260,6 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2706
3260
|
setProxyProbe(null);
|
|
2707
3261
|
setProxyProbeError(null);
|
|
2708
3262
|
setProxyProbeUnsupported(false);
|
|
2709
|
-
if (summary?.configured) void probeProxy(deviceId);
|
|
2710
3263
|
const stored = typeof cur?.meta?.sleep_timeout_min === "number" ? cur.meta.sleep_timeout_min : 30;
|
|
2711
3264
|
setSleepTimeoutMin(stored);
|
|
2712
3265
|
setInfoLoading(true);
|
|
@@ -2714,6 +3267,9 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2714
3267
|
client.devices.op(deviceId, { op: "screen_size" })
|
|
2715
3268
|
).then((size) => setInfo({ resolution: `${size.width}\xD7${size.height}` })).catch(() => setInfo({})).finally(() => setInfoLoading(false));
|
|
2716
3269
|
}, [deviceId]);
|
|
3270
|
+
useEffect(() => {
|
|
3271
|
+
if (deviceId && proxyCapability.custom && proxySummaryFromDevice(device)?.configured) void probeProxy(deviceId);
|
|
3272
|
+
}, [deviceId, proxyCapability.custom]);
|
|
2717
3273
|
useEffect(() => {
|
|
2718
3274
|
if (installMode !== "template" || !deviceId) return;
|
|
2719
3275
|
const devicePlatform = device?.platform === "ios" ? "ios" : "android";
|
|
@@ -2724,7 +3280,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2724
3280
|
onClose();
|
|
2725
3281
|
};
|
|
2726
3282
|
const handleSaveProxy = async () => {
|
|
2727
|
-
if (!deviceId || proxySaving) return;
|
|
3283
|
+
if (!deviceId || proxySaving || !proxyCapability.custom) return;
|
|
2728
3284
|
const nextProxy = proxyInput.trim();
|
|
2729
3285
|
if (isRedactedProxyUrl(nextProxy)) {
|
|
2730
3286
|
toast.error(t("drawer.proxyPasswordRequired"));
|
|
@@ -2818,16 +3374,17 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2818
3374
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold truncate", children: device?.name ?? t("drawer.deviceDetails") }),
|
|
2819
3375
|
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", onClick: handleClose, children: /* @__PURE__ */ jsx(X, { className: "w-4 h-4" }) })
|
|
2820
3376
|
] }),
|
|
2821
|
-
device && deviceId && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1 px-3 pt-2 border-b border-border shrink-0", children: [
|
|
3377
|
+
device && deviceId && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1 overflow-x-auto px-3 pt-2 border-b border-border shrink-0", children: [
|
|
2822
3378
|
["overview", t("drawer.tab.overview")],
|
|
2823
3379
|
["files", t("drawer.tab.files")],
|
|
2824
3380
|
["terminal", t("drawer.tab.terminal")],
|
|
2825
|
-
["fingerprint", t("drawer.tab.fingerprint")]
|
|
3381
|
+
["fingerprint", t("drawer.tab.fingerprint")],
|
|
3382
|
+
["snapshots", t("snapshots.title")]
|
|
2826
3383
|
].map(([key, label]) => /* @__PURE__ */ jsx(
|
|
2827
3384
|
"button",
|
|
2828
3385
|
{
|
|
2829
3386
|
onClick: () => setTab(key),
|
|
2830
|
-
className: `px-3 py-1.5 text-xs font-medium -mb-px border-b-2 transition-colors ${tab === key ? "border-primary text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
|
|
3387
|
+
className: `shrink-0 whitespace-nowrap px-3 py-1.5 text-xs font-medium -mb-px border-b-2 transition-colors ${tab === key ? "border-primary text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
|
|
2831
3388
|
children: label
|
|
2832
3389
|
},
|
|
2833
3390
|
key
|
|
@@ -2836,6 +3393,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2836
3393
|
device && deviceId && tab === "files" && /* @__PURE__ */ jsx(FileManager, { deviceId }),
|
|
2837
3394
|
device && deviceId && tab === "terminal" && /* @__PURE__ */ jsx(DeviceTerminal, { deviceId }),
|
|
2838
3395
|
device && deviceId && tab === "fingerprint" && /* @__PURE__ */ jsx(FingerprintPanel, { deviceId }),
|
|
3396
|
+
device && deviceId && /* @__PURE__ */ jsx("div", { hidden: tab !== "snapshots", children: /* @__PURE__ */ jsx(DeviceSnapshotsPanel, { deviceId, online: device.online, supported: supportsDataSnapshots(device.meta), onChanged: () => void fetchDevices() }) }),
|
|
2839
3397
|
tab === "overview" && device && /* @__PURE__ */ jsxs("section", { children: [
|
|
2840
3398
|
/* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.capability") }),
|
|
2841
3399
|
/* @__PURE__ */ jsxs("div", { className: "space-y-1 text-xs", children: [
|
|
@@ -2877,33 +3435,17 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
2877
3435
|
)
|
|
2878
3436
|
] })
|
|
2879
3437
|
] }),
|
|
3438
|
+
tab === "overview" && physicalIos && device && proxyNode?.is_owner && proxyNode.status === "online" && proxyNode.reported_caps?.ios_control?.diagnostics === true && (typeof device.meta.udid === "string" || device.id.startsWith("ios-")) && /* @__PURE__ */ jsx(
|
|
3439
|
+
IosDeviceDiagnostics,
|
|
3440
|
+
{
|
|
3441
|
+
nodeId: proxyNode.id,
|
|
3442
|
+
udid: typeof device.meta.udid === "string" ? device.meta.udid : device.id.slice(4)
|
|
3443
|
+
},
|
|
3444
|
+
`${proxyNode.id}:${device.id}`
|
|
3445
|
+
),
|
|
2880
3446
|
tab === "overview" && device && deviceId && device.platform === "ios" && /* @__PURE__ */ jsxs("section", { children: [
|
|
2881
3447
|
/* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.videoSource") }),
|
|
2882
|
-
/* @__PURE__ */ jsx("p", { className: "text-
|
|
2883
|
-
/* @__PURE__ */ jsx("div", { className: "flex gap-2", children: [
|
|
2884
|
-
["replaykit", t("drawer.video.replaykit")],
|
|
2885
|
-
["iosusbadapter", t("drawer.video.usbadapter")]
|
|
2886
|
-
].map(([val, label]) => {
|
|
2887
|
-
const current = device.meta.ios?.transport ?? "replaykit";
|
|
2888
|
-
const active = current === val;
|
|
2889
|
-
return /* @__PURE__ */ jsxs(
|
|
2890
|
-
Button,
|
|
2891
|
-
{
|
|
2892
|
-
size: "sm",
|
|
2893
|
-
variant: "secondary",
|
|
2894
|
-
disabled: busy,
|
|
2895
|
-
className: active ? "ring-2 ring-primary" : "",
|
|
2896
|
-
onClick: () => run(`video:${val}`, async () => {
|
|
2897
|
-
await client.devices.update(deviceId, { ios_transport: val });
|
|
2898
|
-
}),
|
|
2899
|
-
children: [
|
|
2900
|
-
label,
|
|
2901
|
-
active ? " \u2713" : ""
|
|
2902
|
-
]
|
|
2903
|
-
},
|
|
2904
|
-
val
|
|
2905
|
-
);
|
|
2906
|
-
}) })
|
|
3448
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t(physicalIos && device.nodeId ? "drawer.videoHostReadOnly" : "drawer.videoReadOnly") })
|
|
2907
3449
|
] }),
|
|
2908
3450
|
tab === "overview" && device && deviceId && /* @__PURE__ */ jsxs("section", { children: [
|
|
2909
3451
|
/* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.location") }),
|
|
@@ -3098,33 +3640,53 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3098
3640
|
] }),
|
|
3099
3641
|
tab === "overview" && device && deviceId && /* @__PURE__ */ jsxs("section", { children: [
|
|
3100
3642
|
/* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.proxy") }),
|
|
3101
|
-
/* @__PURE__ */ jsx(
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
onChange: (e) => setProxyInput(e.target.value),
|
|
3113
|
-
placeholder: t("drawer.proxyPlaceholder")
|
|
3114
|
-
}
|
|
3115
|
-
),
|
|
3116
|
-
/* @__PURE__ */ jsx(
|
|
3117
|
-
Button,
|
|
3118
|
-
{
|
|
3119
|
-
size: "sm",
|
|
3120
|
-
variant: "secondary",
|
|
3121
|
-
disabled: proxySaving,
|
|
3122
|
-
onClick: handleSaveProxy,
|
|
3123
|
-
children: proxySaving ? t("common.saving") : t("common.save")
|
|
3643
|
+
/* @__PURE__ */ jsx(
|
|
3644
|
+
ManagedProxyPanel,
|
|
3645
|
+
{
|
|
3646
|
+
deviceId,
|
|
3647
|
+
selection: proxySelectionFromMeta(device.meta),
|
|
3648
|
+
ownerUserId: device.ownerUserId,
|
|
3649
|
+
projectId: device.projectId,
|
|
3650
|
+
supported: proxyCapability.managed,
|
|
3651
|
+
onChanged: () => {
|
|
3652
|
+
void fetchDevices();
|
|
3653
|
+
void probeProxy(deviceId);
|
|
3124
3654
|
}
|
|
3125
|
-
|
|
3655
|
+
}
|
|
3656
|
+
),
|
|
3657
|
+
/* @__PURE__ */ jsxs("details", { className: "mt-3 rounded border border-border p-3", children: [
|
|
3658
|
+
/* @__PURE__ */ jsx("summary", { className: "cursor-pointer text-xs font-medium", children: t("managed.custom") }),
|
|
3659
|
+
/* @__PURE__ */ jsx("p", { className: "my-2 text-xs text-muted-foreground", children: t("managed.customHint") }),
|
|
3660
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mb-2", children: t("drawer.proxyDesc") }),
|
|
3661
|
+
proxySummary && /* @__PURE__ */ jsxs("p", { className: "mb-2 rounded border border-border/70 bg-secondary/40 px-2 py-1 text-[11px] text-muted-foreground", children: [
|
|
3662
|
+
t("drawer.proxyConfigured"),
|
|
3663
|
+
": ",
|
|
3664
|
+
/* @__PURE__ */ jsx("code", { children: proxySummary })
|
|
3665
|
+
] }),
|
|
3666
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3667
|
+
/* @__PURE__ */ jsx(
|
|
3668
|
+
Input,
|
|
3669
|
+
{
|
|
3670
|
+
"aria-label": t("managed.custom"),
|
|
3671
|
+
disabled: !proxyCapability.custom,
|
|
3672
|
+
value: proxyInput,
|
|
3673
|
+
onChange: (e) => setProxyInput(e.target.value),
|
|
3674
|
+
placeholder: t("drawer.proxyPlaceholder")
|
|
3675
|
+
}
|
|
3676
|
+
),
|
|
3677
|
+
/* @__PURE__ */ jsx(
|
|
3678
|
+
Button,
|
|
3679
|
+
{
|
|
3680
|
+
size: "sm",
|
|
3681
|
+
variant: "secondary",
|
|
3682
|
+
disabled: proxySaving || !proxyCapability.custom,
|
|
3683
|
+
onClick: handleSaveProxy,
|
|
3684
|
+
children: proxySaving ? t("common.saving") : t("common.save")
|
|
3685
|
+
}
|
|
3686
|
+
)
|
|
3687
|
+
] })
|
|
3126
3688
|
] }),
|
|
3127
|
-
|
|
3689
|
+
!proxyCapability.custom && /* @__PURE__ */ jsx("p", { className: "mt-1 text-[11px] text-warning", children: t("drawer.proxyUnavailable") }),
|
|
3128
3690
|
proxyApply && /* @__PURE__ */ jsxs("div", { className: "mt-2 rounded border border-border/70 p-2 text-[11px]", children: [
|
|
3129
3691
|
/* @__PURE__ */ jsxs("span", { className: proxyApply.status === "applied" ? "text-success" : proxyApply.status === "failed" ? "text-destructive" : "text-warning", children: [
|
|
3130
3692
|
t("drawer.proxyStatusLabel"),
|
|
@@ -3141,7 +3703,7 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3141
3703
|
{
|
|
3142
3704
|
size: "sm",
|
|
3143
3705
|
variant: "ghost",
|
|
3144
|
-
disabled: proxyProbeLoading,
|
|
3706
|
+
disabled: proxyProbeLoading || !proxyCapability.custom,
|
|
3145
3707
|
onClick: () => void probeProxy(deviceId),
|
|
3146
3708
|
children: proxyProbeLoading ? t("common.loading") : proxyProbe ? t("drawer.proxyProbeRetry") : t("drawer.proxyProbeCheck")
|
|
3147
3709
|
}
|
|
@@ -3161,12 +3723,13 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3161
3723
|
] }),
|
|
3162
3724
|
tab === "overview" && device && deviceId && /* @__PURE__ */ jsxs("section", { children: [
|
|
3163
3725
|
/* @__PURE__ */ jsx("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: t("drawer.autoSleep") }),
|
|
3164
|
-
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mb-2", children: device.meta.provisioned === true ? t("drawer.autoSleepDescVirtual") : t("drawer.autoSleepDescReal") }),
|
|
3726
|
+
/* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mb-2", children: physicalIos ? t("drawer.iosSleepUnsupported") : device.meta.provisioned === true ? t("drawer.autoSleepDescVirtual") : t("drawer.autoSleepDescReal") }),
|
|
3165
3727
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
|
|
3166
3728
|
/* @__PURE__ */ jsxs(
|
|
3167
3729
|
"select",
|
|
3168
3730
|
{
|
|
3169
3731
|
"aria-label": t("drawer.sleepTimeoutLabel"),
|
|
3732
|
+
disabled: physicalIos,
|
|
3170
3733
|
value: sleepTimeoutMin,
|
|
3171
3734
|
onChange: (e) => setSleepTimeoutMin(Number(e.target.value)),
|
|
3172
3735
|
className: "rounded border border-border bg-secondary px-2 py-1 text-xs text-foreground outline-none hover:bg-card",
|
|
@@ -3185,8 +3748,9 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3185
3748
|
{
|
|
3186
3749
|
size: "sm",
|
|
3187
3750
|
variant: "secondary",
|
|
3188
|
-
disabled: sleepTimeoutSaving,
|
|
3751
|
+
disabled: sleepTimeoutSaving || physicalIos,
|
|
3189
3752
|
onClick: async () => {
|
|
3753
|
+
if (physicalIos) return;
|
|
3190
3754
|
setSleepTimeoutSaving(true);
|
|
3191
3755
|
try {
|
|
3192
3756
|
await client.devices.update(deviceId, { sleep_timeout_min: sleepTimeoutMin });
|
|
@@ -3208,8 +3772,8 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3208
3772
|
{
|
|
3209
3773
|
size: "sm",
|
|
3210
3774
|
variant: "ghost",
|
|
3211
|
-
disabled: busy,
|
|
3212
|
-
onClick: () => run("sleep", () => client.devices.sleep(deviceId)),
|
|
3775
|
+
disabled: busy || physicalIos,
|
|
3776
|
+
onClick: () => !physicalIos && run("sleep", () => client.devices.sleep(deviceId)),
|
|
3213
3777
|
children: t("drawer.sleepNow")
|
|
3214
3778
|
}
|
|
3215
3779
|
),
|
|
@@ -3218,8 +3782,8 @@ function DeviceDetailDrawer({ deviceId, onClose }) {
|
|
|
3218
3782
|
{
|
|
3219
3783
|
size: "sm",
|
|
3220
3784
|
variant: "secondary",
|
|
3221
|
-
disabled: busy,
|
|
3222
|
-
onClick: () => run("wake", () => client.devices.wakeup(deviceId)),
|
|
3785
|
+
disabled: busy || physicalIos,
|
|
3786
|
+
onClick: () => !physicalIos && run("wake", () => client.devices.wakeup(deviceId)),
|
|
3223
3787
|
children: t("drawer.wakeDevice")
|
|
3224
3788
|
}
|
|
3225
3789
|
)
|
|
@@ -4589,6 +5153,195 @@ function DeviceEditDialog({ device, onClose }) {
|
|
|
4589
5153
|
}
|
|
4590
5154
|
);
|
|
4591
5155
|
}
|
|
5156
|
+
|
|
5157
|
+
// src/ui/devices/device-connect.ts
|
|
5158
|
+
function adbAddress(serial) {
|
|
5159
|
+
const value = serial.trim();
|
|
5160
|
+
const match = /^(\[[^\]]+\]|[^:\[\]\/\?#@\s]+):([0-9]{1,5})$/.exec(value);
|
|
5161
|
+
if (!match || Number(match[2]) < 1 || Number(match[2]) > 65535) return null;
|
|
5162
|
+
try {
|
|
5163
|
+
const parsed = new URL(`http://${value}`);
|
|
5164
|
+
if (!parsed.hostname || parsed.username || parsed.password || parsed.search || parsed.hash) return null;
|
|
5165
|
+
return value;
|
|
5166
|
+
} catch {
|
|
5167
|
+
return null;
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
function connectionMode(device) {
|
|
5171
|
+
if (device.meta.provisioned === true || device.id.startsWith("rd-") || device.id.startsWith("vp-")) return { kind: "blocked", code: "virtual" };
|
|
5172
|
+
if (device.platform === "macos" || device.platform === "windows") return { kind: "blocked", code: "desktop" };
|
|
5173
|
+
if (device.platform !== "android") return { kind: "blocked", code: "unsupported" };
|
|
5174
|
+
if (device.platform === "android") {
|
|
5175
|
+
const address = adbAddress(device.udid);
|
|
5176
|
+
if (address) return { kind: "wireless", address };
|
|
5177
|
+
if (device.udid.includes(":")) return { kind: "blocked", code: "invalidAddress" };
|
|
5178
|
+
}
|
|
5179
|
+
return { kind: "inventory" };
|
|
5180
|
+
}
|
|
5181
|
+
function eligibleConnectionNodes(nodes, device) {
|
|
5182
|
+
return nodes.filter((node) => canConnectPhysicalDevice(node, device.platform === "android" ? "android" : "ios") && (device.platform !== "android" || node.effective_caps?.android !== false));
|
|
5183
|
+
}
|
|
5184
|
+
async function connectSelectedDevices(client, devices, choices = {}, isCurrent = () => true) {
|
|
5185
|
+
const result = (device, code, error) => ({
|
|
5186
|
+
id: device.id,
|
|
5187
|
+
name: device.name,
|
|
5188
|
+
ok: code === "requested" || code === "alreadyOnline",
|
|
5189
|
+
code,
|
|
5190
|
+
...error ? { error } : {}
|
|
5191
|
+
});
|
|
5192
|
+
if (!devices.length) return [];
|
|
5193
|
+
let nodes;
|
|
5194
|
+
try {
|
|
5195
|
+
nodes = await client.nodes.list();
|
|
5196
|
+
} catch (error) {
|
|
5197
|
+
return devices.map((device) => result(device, "requestFailed", String(error.message ?? error)));
|
|
5198
|
+
}
|
|
5199
|
+
const results = [];
|
|
5200
|
+
for (const device of devices) {
|
|
5201
|
+
if (!isCurrent()) {
|
|
5202
|
+
results.push(result(device, "cancelled"));
|
|
5203
|
+
continue;
|
|
5204
|
+
}
|
|
5205
|
+
if (device.online) {
|
|
5206
|
+
results.push(result(device, "alreadyOnline"));
|
|
5207
|
+
continue;
|
|
5208
|
+
}
|
|
5209
|
+
const mode = connectionMode(device);
|
|
5210
|
+
if (mode.kind === "blocked") {
|
|
5211
|
+
results.push(result(device, mode.code));
|
|
5212
|
+
continue;
|
|
5213
|
+
}
|
|
5214
|
+
const nodeId = device.nodeId ?? choices[device.id];
|
|
5215
|
+
if (!nodeId) {
|
|
5216
|
+
results.push(result(device, "chooseNode"));
|
|
5217
|
+
continue;
|
|
5218
|
+
}
|
|
5219
|
+
const node = nodes.find((candidate) => candidate.id === nodeId);
|
|
5220
|
+
if (!node) {
|
|
5221
|
+
results.push(result(device, "nodeMissing"));
|
|
5222
|
+
continue;
|
|
5223
|
+
}
|
|
5224
|
+
if (!node.is_owner) {
|
|
5225
|
+
results.push(result(device, "notOwner"));
|
|
5226
|
+
continue;
|
|
5227
|
+
}
|
|
5228
|
+
if (node.status !== "online") {
|
|
5229
|
+
results.push(result(device, "nodeOffline"));
|
|
5230
|
+
continue;
|
|
5231
|
+
}
|
|
5232
|
+
if (!eligibleConnectionNodes([node], device).length) {
|
|
5233
|
+
results.push(result(device, "permission"));
|
|
5234
|
+
continue;
|
|
5235
|
+
}
|
|
5236
|
+
let requested = false;
|
|
5237
|
+
try {
|
|
5238
|
+
if (mode.kind === "wireless") {
|
|
5239
|
+
await client.nodes.adbConnect(node.id, mode.address);
|
|
5240
|
+
requested = true;
|
|
5241
|
+
if (!isCurrent()) {
|
|
5242
|
+
results.push(result(device, "cancelled"));
|
|
5243
|
+
continue;
|
|
5244
|
+
}
|
|
5245
|
+
}
|
|
5246
|
+
await client.nodes.discoverDevices(node.id);
|
|
5247
|
+
if (!isCurrent()) {
|
|
5248
|
+
results.push(result(device, "cancelled"));
|
|
5249
|
+
continue;
|
|
5250
|
+
}
|
|
5251
|
+
results.push(result(device, requested ? "requested" : "inventoryOnly"));
|
|
5252
|
+
} catch (error) {
|
|
5253
|
+
results.push(result(device, requested ? "refreshFailed" : "requestFailed", String(error.message ?? error)));
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
return results;
|
|
5257
|
+
}
|
|
5258
|
+
function ConnectDevicesDialog({ devices, onClose, onComplete }) {
|
|
5259
|
+
const client = useClient();
|
|
5260
|
+
const t = useAixT();
|
|
5261
|
+
const [nodes, setNodes] = useState([]);
|
|
5262
|
+
const [choices, setChoices] = useState({});
|
|
5263
|
+
const [loading, setLoading] = useState(false);
|
|
5264
|
+
const [busy, setBusy] = useState(false);
|
|
5265
|
+
const [error, setError] = useState("");
|
|
5266
|
+
const [results, setResults] = useState(null);
|
|
5267
|
+
const active = useRef(true);
|
|
5268
|
+
const pending = useRef(false);
|
|
5269
|
+
const unassigned = devices.filter((device) => !device.online && !device.nodeId && connectionMode(device).kind !== "blocked");
|
|
5270
|
+
const needsChoice = unassigned.some((device) => !choices[device.id]);
|
|
5271
|
+
const run = async () => {
|
|
5272
|
+
if (!active.current || pending.current || needsChoice) return;
|
|
5273
|
+
pending.current = true;
|
|
5274
|
+
setBusy(true);
|
|
5275
|
+
setError("");
|
|
5276
|
+
try {
|
|
5277
|
+
const next = await connectSelectedDevices(client, devices, choices, () => active.current);
|
|
5278
|
+
if (!active.current) return;
|
|
5279
|
+
setResults(next);
|
|
5280
|
+
await onComplete(next);
|
|
5281
|
+
} catch (error2) {
|
|
5282
|
+
if (active.current) setError(error2.message);
|
|
5283
|
+
} finally {
|
|
5284
|
+
pending.current = false;
|
|
5285
|
+
if (active.current) setBusy(false);
|
|
5286
|
+
}
|
|
5287
|
+
};
|
|
5288
|
+
useEffect(() => {
|
|
5289
|
+
active.current = true;
|
|
5290
|
+
if (unassigned.length) {
|
|
5291
|
+
setLoading(true);
|
|
5292
|
+
void client.nodes.list().then((rows) => {
|
|
5293
|
+
if (active.current) setNodes(rows);
|
|
5294
|
+
}).catch((error2) => {
|
|
5295
|
+
if (active.current) setError(error2.message);
|
|
5296
|
+
}).finally(() => {
|
|
5297
|
+
if (active.current) setLoading(false);
|
|
5298
|
+
});
|
|
5299
|
+
} else {
|
|
5300
|
+
void run();
|
|
5301
|
+
}
|
|
5302
|
+
return () => {
|
|
5303
|
+
active.current = false;
|
|
5304
|
+
};
|
|
5305
|
+
}, []);
|
|
5306
|
+
return /* @__PURE__ */ jsx(Dialog, { open: true, onClose, title: t("deviceConnect.title"), description: t("deviceConnect.description"), children: /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
5307
|
+
unassigned.map((device) => {
|
|
5308
|
+
const available = eligibleConnectionNodes(nodes, device);
|
|
5309
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
5310
|
+
/* @__PURE__ */ jsxs("label", { className: "block text-xs font-medium", children: [
|
|
5311
|
+
/* @__PURE__ */ jsx("span", { className: "mb-1 block", children: t("deviceConnect.chooseFor", { name: device.name }) }),
|
|
5312
|
+
/* @__PURE__ */ jsx(
|
|
5313
|
+
Select,
|
|
5314
|
+
{
|
|
5315
|
+
value: choices[device.id] ?? "",
|
|
5316
|
+
disabled: busy || loading,
|
|
5317
|
+
onChange: (nodeId) => setChoices((previous) => ({ ...previous, [device.id]: nodeId })),
|
|
5318
|
+
placeholder: t("deviceConnect.chooseNode"),
|
|
5319
|
+
options: available.map((node) => ({ value: node.id, label: node.name }))
|
|
5320
|
+
}
|
|
5321
|
+
)
|
|
5322
|
+
] }),
|
|
5323
|
+
!loading && !available.length && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("deviceConnect.noNodes") })
|
|
5324
|
+
] }, device.id);
|
|
5325
|
+
}),
|
|
5326
|
+
loading && /* @__PURE__ */ jsx("p", { role: "status", className: "text-xs", children: t("deviceConnect.loading") }),
|
|
5327
|
+
busy && /* @__PURE__ */ jsx("p", { role: "status", className: "text-xs", children: t("deviceConnect.running") }),
|
|
5328
|
+
error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: error }),
|
|
5329
|
+
results && /* @__PURE__ */ jsx("ul", { className: "max-h-64 space-y-2 overflow-auto", "aria-live": "polite", children: results.map((result) => /* @__PURE__ */ jsxs("li", { className: "text-xs", children: [
|
|
5330
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
5331
|
+
result.name,
|
|
5332
|
+
": "
|
|
5333
|
+
] }),
|
|
5334
|
+
/* @__PURE__ */ jsxs("span", { className: result.ok ? "text-muted-foreground" : "text-destructive", children: [
|
|
5335
|
+
t(`deviceConnect.${result.code}`),
|
|
5336
|
+
result.error ? ` ${result.error}` : ""
|
|
5337
|
+
] })
|
|
5338
|
+
] }, result.id)) }),
|
|
5339
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
5340
|
+
/* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onClick: onClose, children: t("common.close") }),
|
|
5341
|
+
!results && unassigned.length > 0 && /* @__PURE__ */ jsx(Button, { size: "sm", disabled: busy || loading || needsChoice, onClick: () => void run(), children: busy ? t("deviceConnect.running") : t("devices.bulk.connect") })
|
|
5342
|
+
] })
|
|
5343
|
+
] }) });
|
|
5344
|
+
}
|
|
4592
5345
|
function DevicesPage({ taskAgentRunner: providedTaskAgentRunner } = {}) {
|
|
4593
5346
|
const t = useAixT();
|
|
4594
5347
|
const client = useClient();
|
|
@@ -4619,6 +5372,7 @@ function DevicesPage({ taskAgentRunner: providedTaskAgentRunner } = {}) {
|
|
|
4619
5372
|
const [taskAgentDevices, setTaskAgentDevices] = useState(null);
|
|
4620
5373
|
const [bulkInstallDevices, setBulkInstallDevices] = useState(null);
|
|
4621
5374
|
const [bulkPowering, setBulkPowering] = useState(false);
|
|
5375
|
+
const [connectTargets, setConnectTargets] = useState(null);
|
|
4622
5376
|
const [editDeviceId, setEditDeviceId] = useState(null);
|
|
4623
5377
|
const [deleteTarget, setDeleteTarget] = useState(null);
|
|
4624
5378
|
const [poweringId, setPoweringId] = useState(null);
|
|
@@ -4861,8 +5615,16 @@ function DevicesPage({ taskAgentRunner: providedTaskAgentRunner } = {}) {
|
|
|
4861
5615
|
/* @__PURE__ */ jsx("span", { children: t("devices.selectAll") })
|
|
4862
5616
|
] }),
|
|
4863
5617
|
/* @__PURE__ */ jsx("div", { className: "h-4 w-px bg-border" }),
|
|
4864
|
-
/* @__PURE__ */ jsx(
|
|
4865
|
-
|
|
5618
|
+
/* @__PURE__ */ jsx(
|
|
5619
|
+
BulkAction,
|
|
5620
|
+
{
|
|
5621
|
+
icon: /* @__PURE__ */ jsx(Link, { className: "w-3.5 h-3.5" }),
|
|
5622
|
+
label: t("devices.bulk.connect"),
|
|
5623
|
+
disabled: !devices.some((device) => checkedIds.has(device.id)) || connectTargets !== null,
|
|
5624
|
+
onClick: () => setConnectTargets(devices.filter((device) => checkedIds.has(device.id)))
|
|
5625
|
+
}
|
|
5626
|
+
),
|
|
5627
|
+
/* @__PURE__ */ jsx("span", { tabIndex: 0, title: t("deviceConnect.disconnectUnsupported"), "aria-label": t("deviceConnect.disconnectUnsupported"), children: /* @__PURE__ */ jsx(BulkAction, { icon: /* @__PURE__ */ jsx(Link2Off, { className: "w-3.5 h-3.5" }), label: t("devices.bulk.disconnect"), disabled: true }) }),
|
|
4866
5628
|
/* @__PURE__ */ jsx(
|
|
4867
5629
|
BulkAction,
|
|
4868
5630
|
{
|
|
@@ -5191,6 +5953,14 @@ function DevicesPage({ taskAgentRunner: providedTaskAgentRunner } = {}) {
|
|
|
5191
5953
|
}
|
|
5192
5954
|
),
|
|
5193
5955
|
/* @__PURE__ */ jsx(BulkInstallAppsDialog, { devices: bulkInstallDevices, onClose: () => setBulkInstallDevices(null) }),
|
|
5956
|
+
connectTargets && /* @__PURE__ */ jsx(ConnectDevicesDialog, { devices: connectTargets, onClose: () => setConnectTargets(null), onComplete: async (results) => {
|
|
5957
|
+
const failed = results.filter((result) => !result.ok).length;
|
|
5958
|
+
const message = t("deviceConnect.summary", { ok: results.length - failed, failed });
|
|
5959
|
+
if (failed) toast.error(message);
|
|
5960
|
+
else toast.success(message);
|
|
5961
|
+
await fetchDevices();
|
|
5962
|
+
await fetchNodes();
|
|
5963
|
+
} }),
|
|
5194
5964
|
/* @__PURE__ */ jsx(
|
|
5195
5965
|
DeviceEditDialog,
|
|
5196
5966
|
{
|