Skip to content

Commit 453cc39

Browse files
committed
fixups
1 parent 8caa037 commit 453cc39

4 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/daemon/device-ready.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { promises as fs } from 'node:fs';
55
import { runCmd } from '../utils/exec.ts';
66
import { AppError } from '../utils/errors.ts';
77
import { resolveTimeoutMs } from '../utils/timeouts.ts';
8-
import { resolveIosDevicectlHint } from '../platforms/ios/devicectl.ts';
8+
import { resolveIosDevicectlHint, IOS_DEVICECTL_DEFAULT_HINT } from '../platforms/ios/devicectl.ts';
99

1010
const IOS_DEVICE_READY_TIMEOUT_MS = resolveTimeoutMs(
1111
process.env.AGENT_DEVICE_IOS_DEVICE_READY_TIMEOUT_MS,
@@ -146,12 +146,10 @@ async function readIosReadyPayload(jsonPath: string): Promise<{ parsed: boolean;
146146

147147
export function resolveIosReadyHint(stdout: string, stderr: string): string {
148148
const devicectlHint = resolveIosDevicectlHint(stdout, stderr);
149-
if (devicectlHint !== 'Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.') {
150-
return devicectlHint;
151-
}
149+
if (devicectlHint) return devicectlHint;
152150
const text = `${stdout}\n${stderr}`.toLowerCase();
153151
if (text.includes('timed out waiting for all destinations')) {
154152
return 'Xcode destination did not become available in time. Keep device unlocked and retry.';
155153
}
156-
return devicectlHint;
154+
return IOS_DEVICECTL_DEFAULT_HINT;
157155
}

src/platforms/android/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function inferAndroidAppName(packageName: string): string {
115115
.flatMap((segment) => segment.split(/[_-]+/))
116116
.map((token) => token.trim().toLowerCase())
117117
.filter((token) => token.length > 0);
118+
// Fallback to last token if every token is ignored (e.g. "com.android.app.services" → "Services").
118119
let chosen = tokens[tokens.length - 1] ?? packageName;
119120
for (let index = tokens.length - 1; index >= 0; index -= 1) {
120121
const token = tokens[index];

src/platforms/ios/devicectl.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function runIosDevicectl(
4141
stdout,
4242
stderr,
4343
deviceId: context.deviceId,
44-
hint: resolveIosDevicectlHint(stdout, stderr),
44+
hint: resolveIosDevicectlHint(stdout, stderr) ?? IOS_DEVICECTL_DEFAULT_HINT,
4545
});
4646
}
4747

@@ -80,7 +80,7 @@ export async function listIosDeviceApps(
8080
stdout,
8181
stderr,
8282
deviceId: device.id,
83-
hint: resolveIosDevicectlHint(stdout, stderr),
83+
hint: resolveIosDevicectlHint(stdout, stderr) ?? IOS_DEVICECTL_DEFAULT_HINT,
8484
});
8585
}
8686
const jsonText = await fs.readFile(jsonPath, 'utf8');
@@ -119,13 +119,16 @@ function filterIosDeviceApps(apps: IosAppInfo[], filter: 'user-installed' | 'all
119119
return apps;
120120
}
121121

122-
export function resolveIosDevicectlHint(stdout: string, stderr: string): string {
122+
export const IOS_DEVICECTL_DEFAULT_HINT =
123+
'Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.';
124+
125+
export function resolveIosDevicectlHint(stdout: string, stderr: string): string | null {
123126
const text = `${stdout}\n${stderr}`.toLowerCase();
124127
if (text.includes('device is busy') && text.includes('connecting')) {
125128
return 'iOS device is still connecting. Keep it unlocked and connected by cable until it is fully available in Xcode Devices, then retry.';
126129
}
127130
if (text.includes('coredeviceservice') && text.includes('timed out')) {
128131
return 'CoreDevice service timed out. Reconnect the device and retry; if it persists restart Xcode and the iOS device.';
129132
}
130-
return 'Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.';
133+
return null;
131134
}

src/utils/timeouts.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,5 @@ export function resolveTimeoutMs(raw: string | undefined, fallback: number, min:
55
return Math.max(min, Math.floor(parsed));
66
}
77

8-
export function resolveTimeoutSeconds(raw: string | undefined, fallback: number, min: number): number {
9-
if (!raw) return fallback;
10-
const parsed = Number(raw);
11-
if (!Number.isFinite(parsed)) return fallback;
12-
return Math.max(min, Math.floor(parsed));
13-
}
8+
/** Alias for `resolveTimeoutMs` — semantically marks the caller expects seconds. */
9+
export const resolveTimeoutSeconds = resolveTimeoutMs;

0 commit comments

Comments
 (0)