@agimon-ai/po-ios 0.0.1-alpha.35 → 0.0.1-alpha.37
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.
|
@@ -58,6 +58,8 @@ var IosError = class extends Error {
|
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/services/devicectl/index.ts
|
|
60
60
|
const CONNECTION_TIMEOUT_MS = 2e4;
|
|
61
|
+
const LIST_CACHE_MS = 2e3;
|
|
62
|
+
const LIST_BACKOFF_MS = 1e4;
|
|
61
63
|
const LAUNCHED = /^Launched application with /u;
|
|
62
64
|
const WAITING = /^Waiting for the application to terminate/u;
|
|
63
65
|
function record(value) {
|
|
@@ -128,19 +130,46 @@ function createDeviceCtl(options) {
|
|
|
128
130
|
await stopConsole(identifier);
|
|
129
131
|
consoles.delete(identifier);
|
|
130
132
|
};
|
|
133
|
+
let listing;
|
|
134
|
+
let expiresAt = 0;
|
|
135
|
+
let listingActive = false;
|
|
136
|
+
const readDevices = async () => {
|
|
137
|
+
const file = `${options.scratchDirectory}/devicectl-${crypto.randomUUID()}.json`;
|
|
138
|
+
try {
|
|
139
|
+
await step([
|
|
140
|
+
"list",
|
|
141
|
+
"devices",
|
|
142
|
+
"--json-output",
|
|
143
|
+
file
|
|
144
|
+
]);
|
|
145
|
+
const devices = parsePhysicalDevices(await options.readText(file));
|
|
146
|
+
expiresAt = Date.now() + (devices.length === 0 ? LIST_BACKOFF_MS : LIST_CACHE_MS);
|
|
147
|
+
return devices;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
expiresAt = Date.now() + LIST_BACKOFF_MS;
|
|
150
|
+
throw error;
|
|
151
|
+
} finally {
|
|
152
|
+
await options.remove(file);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
131
155
|
return {
|
|
132
156
|
async listDevices(signal) {
|
|
133
|
-
|
|
157
|
+
signal?.throwIfAborted();
|
|
158
|
+
if (listing === void 0 || !listingActive && Date.now() >= expiresAt) {
|
|
159
|
+
listingActive = true;
|
|
160
|
+
listing = readDevices().finally(() => {
|
|
161
|
+
listingActive = false;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
let onAbort;
|
|
134
165
|
try {
|
|
135
|
-
await
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
], signal);
|
|
141
|
-
return parsePhysicalDevices(await options.readText(file));
|
|
166
|
+
return (await Promise.race([listing, new Promise((_resolve, reject) => {
|
|
167
|
+
onAbort = () => reject(signal?.reason);
|
|
168
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
169
|
+
if (signal?.aborted) onAbort();
|
|
170
|
+
})])).map((device) => ({ ...device }));
|
|
142
171
|
} finally {
|
|
143
|
-
|
|
172
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
144
173
|
}
|
|
145
174
|
},
|
|
146
175
|
async ensureReachable(identifier, signal) {
|