@rootnative/loupe 0.0.0-alpha.2 → 0.0.0-alpha.3
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/CHANGELOG.md +18 -1
- package/README.md +1 -1
- package/dist/bin.js +2 -2
- package/dist/{chunk-HWVQXYQ3.js → chunk-7ALG5744.js} +702 -403
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -1
- package/dist/ios-runner/Debug-iphonesimulator/LoupeHost.app/Info.plist +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeHost.app/LoupeHost +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeHost.app/LoupeHost.debug.dylib +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeHost.app/PkgInfo +1 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeHost.app/__preview.dylib +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeRunner-Runner.app/Info.plist +239 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeRunner-Runner.app/LoupeRunner-Runner +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeRunner-Runner.app/PkgInfo +1 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeRunner-Runner.app/PlugIns/LoupeRunner.xctest/Info.plist +0 -0
- package/dist/ios-runner/Debug-iphonesimulator/LoupeRunner-Runner.app/PlugIns/LoupeRunner.xctest/LoupeRunner +0 -0
- package/dist/ios-runner/LoupeRunner.xctestrun +119 -0
- package/dist/{server-567FSCAH.js → server-3J6ZMCJG.js} +1 -1
- package/package.json +1 -1
- package/skills/loupe/SKILL.md +4 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@rootnative/loupe",
|
|
4
|
-
version: "0.0.0-alpha.
|
|
4
|
+
version: "0.0.0-alpha.3",
|
|
5
5
|
description: "loupe by Root Native: layout checks for iOS and Android, built for AI agents. Drive simulators and emulators, and measure every screen to the point.",
|
|
6
6
|
license: "MIT",
|
|
7
7
|
author: "Root Native",
|
|
@@ -90,22 +90,22 @@ function outputJsonSchema(command) {
|
|
|
90
90
|
}
|
|
91
91
|
var COMMAND_NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
92
92
|
function createRegistry(commands) {
|
|
93
|
-
const
|
|
93
|
+
const byName2 = /* @__PURE__ */ new Map();
|
|
94
94
|
for (const command of commands) {
|
|
95
95
|
if (!COMMAND_NAME.test(command.name)) {
|
|
96
96
|
throw new Error(
|
|
97
97
|
`The command name "${command.name}" must be kebab case, for example "open-url".`
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
100
|
+
if (byName2.has(command.name)) {
|
|
101
101
|
throw new Error(`Two commands have the name "${command.name}".`);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
byName2.set(command.name, command);
|
|
104
104
|
}
|
|
105
|
-
const list = [...
|
|
105
|
+
const list = [...byName2.values()];
|
|
106
106
|
return {
|
|
107
107
|
list: () => list,
|
|
108
|
-
get: (name2) =>
|
|
108
|
+
get: (name2) => byName2.get(name2)
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -121,16 +121,23 @@ var DEVICE_STATES = [
|
|
|
121
121
|
"other"
|
|
122
122
|
];
|
|
123
123
|
var deviceSchema = z2.object({
|
|
124
|
-
platform: z2.enum(["android"]),
|
|
125
|
-
kind: z2.enum(["emulator", "device"]),
|
|
126
|
-
serial: z2.string().optional().describe(
|
|
124
|
+
platform: z2.enum(["android", "ios"]),
|
|
125
|
+
kind: z2.enum(["emulator", "device", "simulator"]),
|
|
126
|
+
serial: z2.string().optional().describe(
|
|
127
|
+
"The adb serial of an Android device. An AVD that does not run has none."
|
|
128
|
+
),
|
|
127
129
|
avd: z2.string().optional().describe("The AVD name of an emulator."),
|
|
130
|
+
udid: z2.string().optional().describe("The UDID of an iOS simulator."),
|
|
131
|
+
name: z2.string().optional().describe("The name of an iOS simulator, for example iPhone 16 Pro."),
|
|
128
132
|
model: z2.string().optional(),
|
|
129
133
|
state: z2.enum(DEVICE_STATES).describe(
|
|
130
|
-
'Only a ready device takes commands. "stopped" is an AVD that does not run.'
|
|
134
|
+
'Only a ready device takes commands. "stopped" is an AVD or a simulator that does not run.'
|
|
135
|
+
),
|
|
136
|
+
detail: z2.string().optional().describe(
|
|
137
|
+
'What adb or simctl reports, for the states "no-permissions" and "other".'
|
|
131
138
|
),
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
apiLevel: z2.number().int().optional().describe("The API level of an Android device."),
|
|
140
|
+
os: z2.string().optional().describe("The runtime of an iOS simulator, for example iOS 18.6.")
|
|
134
141
|
});
|
|
135
142
|
var appField = z2.string().regex(
|
|
136
143
|
/^[A-Za-z][A-Za-z0-9_.-]*$/,
|
|
@@ -139,7 +146,7 @@ var appField = z2.string().regex(
|
|
|
139
146
|
"The package of the app under test, for example host.exp.exponent for Expo Go. loupe then works only while that app is in front. A real device needs it."
|
|
140
147
|
);
|
|
141
148
|
var deviceField = z2.string().min(1).optional().describe(
|
|
142
|
-
"The serial or the AVD name of the
|
|
149
|
+
"The serial or the AVD name of an Android device, or the UDID or the name of an iOS simulator. Without it, loupe uses ANDROID_SERIAL, or the only ready device."
|
|
143
150
|
);
|
|
144
151
|
|
|
145
152
|
// src/core/errors.ts
|
|
@@ -274,6 +281,13 @@ function describeDisplay({
|
|
|
274
281
|
import { spawn } from "child_process";
|
|
275
282
|
import path from "path";
|
|
276
283
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
284
|
+
var FAILURE_LIMIT = 500;
|
|
285
|
+
function describeToolFailure(name2, result) {
|
|
286
|
+
const status = result.code === null ? `${name2} stopped on a signal` : `${name2} exited with code ${result.code}`;
|
|
287
|
+
const output = (result.stderr.length > 0 ? result.stderr : result.stdout).toString("utf8").trim();
|
|
288
|
+
if (!output) return `${status}.`;
|
|
289
|
+
return output.length > FAILURE_LIMIT ? `${status}: ${output.slice(0, FAILURE_LIMIT)}\u2026` : `${status}: ${output}`;
|
|
290
|
+
}
|
|
277
291
|
function toolName(file) {
|
|
278
292
|
return path.parse(file).name || file;
|
|
279
293
|
}
|
|
@@ -336,7 +350,7 @@ var nodeExec = (file, args, options = {}) => {
|
|
|
336
350
|
};
|
|
337
351
|
|
|
338
352
|
// src/commands/background.ts
|
|
339
|
-
import { z as
|
|
353
|
+
import { z as z11 } from "zod";
|
|
340
354
|
|
|
341
355
|
// src/core/wait.ts
|
|
342
356
|
import { setTimeout as sleep } from "timers/promises";
|
|
@@ -377,12 +391,15 @@ var uiNodeSchema = z4.object({
|
|
|
377
391
|
return z4.array(uiNodeSchema).optional();
|
|
378
392
|
}
|
|
379
393
|
});
|
|
380
|
-
var
|
|
381
|
-
function
|
|
382
|
-
return
|
|
394
|
+
var EXPO_GO_ANDROID = "host.exp.exponent";
|
|
395
|
+
function isAndroidView(node) {
|
|
396
|
+
return node.type.startsWith("android.");
|
|
383
397
|
}
|
|
384
|
-
function
|
|
385
|
-
return
|
|
398
|
+
function isExpoGoOverlay(node, app, platform) {
|
|
399
|
+
return platform === "android" && app === EXPO_GO_ANDROID && !isAndroidView(node);
|
|
400
|
+
}
|
|
401
|
+
function scrollAxisOf(node, platform) {
|
|
402
|
+
return platform === "android" && /HorizontalScrollView|ViewPager/.test(node.type) ? "x" : "y";
|
|
386
403
|
}
|
|
387
404
|
function describeNode(node) {
|
|
388
405
|
const { x, y, width, height } = node.frame;
|
|
@@ -1198,7 +1215,6 @@ async function appRuns(target, app) {
|
|
|
1198
1215
|
|
|
1199
1216
|
// src/drivers/android/sdk-tool.ts
|
|
1200
1217
|
import path2 from "path";
|
|
1201
|
-
var MESSAGE_LIMIT = 500;
|
|
1202
1218
|
var ADB = {
|
|
1203
1219
|
name: "adb",
|
|
1204
1220
|
dir: "platform-tools",
|
|
@@ -1224,12 +1240,6 @@ function missingTool(tool, candidates) {
|
|
|
1224
1240
|
`loupe can't find ${tool.name}. ${where} Install ${tool.install}, or set ANDROID_HOME to the folder of your Android SDK.`
|
|
1225
1241
|
);
|
|
1226
1242
|
}
|
|
1227
|
-
function describeFailure(tool, result) {
|
|
1228
|
-
const status = result.code === null ? `${tool.name} stopped on a signal` : `${tool.name} exited with code ${result.code}`;
|
|
1229
|
-
const output = (result.stderr.length > 0 ? result.stderr : result.stdout).toString("utf8").trim();
|
|
1230
|
-
if (!output) return `${status}.`;
|
|
1231
|
-
return output.length > MESSAGE_LIMIT ? `${status}: ${output.slice(0, MESSAGE_LIMIT)}\u2026` : `${status}: ${output}`;
|
|
1232
|
-
}
|
|
1233
1243
|
function createSdkTool({ exec, env }, tool) {
|
|
1234
1244
|
let found;
|
|
1235
1245
|
async function execTool(args, options) {
|
|
@@ -1252,7 +1262,10 @@ function createSdkTool({ exec, env }, tool) {
|
|
|
1252
1262
|
async function run(args, options) {
|
|
1253
1263
|
const result = await execTool(args, options);
|
|
1254
1264
|
if (result.code !== 0) {
|
|
1255
|
-
throw new LoupeError(
|
|
1265
|
+
throw new LoupeError(
|
|
1266
|
+
"tool_failed",
|
|
1267
|
+
describeToolFailure(tool.name, result)
|
|
1268
|
+
);
|
|
1256
1269
|
}
|
|
1257
1270
|
return result.stdout;
|
|
1258
1271
|
}
|
|
@@ -1427,6 +1440,12 @@ async function findEntry(context, adb, entries, wanted) {
|
|
|
1427
1440
|
`No device has the serial or the AVD name "${wanted}". Run "loupe devices" to see the list.`
|
|
1428
1441
|
);
|
|
1429
1442
|
}
|
|
1443
|
+
async function readyAndroidDevices(context) {
|
|
1444
|
+
const entries = parseAdbDevices(
|
|
1445
|
+
await createAdb(context).text(["devices", "-l"])
|
|
1446
|
+
);
|
|
1447
|
+
return entries.filter((entry) => entry.adbState === "device").map(label);
|
|
1448
|
+
}
|
|
1430
1449
|
function onlyReadyEntry(entries) {
|
|
1431
1450
|
const ready = entries.filter((entry) => entry.adbState === "device");
|
|
1432
1451
|
const [first] = ready.length > 0 ? ready : entries;
|
|
@@ -1484,6 +1503,233 @@ async function selectAndroidDevice(context, wanted) {
|
|
|
1484
1503
|
};
|
|
1485
1504
|
}
|
|
1486
1505
|
|
|
1506
|
+
// src/drivers/ios/parse.ts
|
|
1507
|
+
import { z as z7 } from "zod";
|
|
1508
|
+
var listSchema = z7.object({
|
|
1509
|
+
runtimes: z7.array(
|
|
1510
|
+
z7.object({
|
|
1511
|
+
identifier: z7.string(),
|
|
1512
|
+
name: z7.string(),
|
|
1513
|
+
platform: z7.string().optional(),
|
|
1514
|
+
isAvailable: z7.boolean().optional()
|
|
1515
|
+
})
|
|
1516
|
+
),
|
|
1517
|
+
devices: z7.record(
|
|
1518
|
+
z7.string(),
|
|
1519
|
+
z7.array(
|
|
1520
|
+
z7.object({
|
|
1521
|
+
udid: z7.string(),
|
|
1522
|
+
name: z7.string(),
|
|
1523
|
+
state: z7.string(),
|
|
1524
|
+
isAvailable: z7.boolean().optional()
|
|
1525
|
+
})
|
|
1526
|
+
)
|
|
1527
|
+
)
|
|
1528
|
+
});
|
|
1529
|
+
function parseSimctlList(text) {
|
|
1530
|
+
let list;
|
|
1531
|
+
try {
|
|
1532
|
+
list = listSchema.parse(JSON.parse(text));
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
throw new LoupeError(
|
|
1535
|
+
"tool_failed",
|
|
1536
|
+
"loupe can't read the output of simctl list.",
|
|
1537
|
+
{ cause: error }
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
return list.runtimes.filter(
|
|
1541
|
+
(runtime) => runtime.isAvailable !== false && // A runtime of an old Xcode has no platform.
|
|
1542
|
+
(runtime.platform ?? runtime.name.split(" ")[0]) === "iOS"
|
|
1543
|
+
).flatMap(
|
|
1544
|
+
(runtime) => (list.devices[runtime.identifier] ?? []).filter((device) => device.isAvailable !== false).map(({ udid, name: name2, state: state2 }) => ({
|
|
1545
|
+
udid,
|
|
1546
|
+
name: name2,
|
|
1547
|
+
state: state2,
|
|
1548
|
+
os: runtime.name
|
|
1549
|
+
}))
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
// src/drivers/ios/simctl.ts
|
|
1554
|
+
function createSimctl({ exec }) {
|
|
1555
|
+
return {
|
|
1556
|
+
text: async (args, options) => {
|
|
1557
|
+
let result;
|
|
1558
|
+
try {
|
|
1559
|
+
result = await exec("xcrun", ["simctl", ...args], options);
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
if (error instanceof LoupeError && error.code === "tool_missing") {
|
|
1562
|
+
throw new LoupeError(
|
|
1563
|
+
"tool_missing",
|
|
1564
|
+
"loupe can't find xcrun. Install Xcode, then try again.",
|
|
1565
|
+
{ cause: error }
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
throw error;
|
|
1569
|
+
}
|
|
1570
|
+
if (result.code !== 0) {
|
|
1571
|
+
throw new LoupeError(
|
|
1572
|
+
"tool_failed",
|
|
1573
|
+
describeToolFailure("simctl", result)
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
return result.stdout.toString("utf8");
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// src/drivers/ios/devices.ts
|
|
1582
|
+
function stateOf2(state2) {
|
|
1583
|
+
switch (state2) {
|
|
1584
|
+
case "Booted":
|
|
1585
|
+
return { state: "ready" };
|
|
1586
|
+
case "Booting":
|
|
1587
|
+
return { state: "booting" };
|
|
1588
|
+
case "Shutdown":
|
|
1589
|
+
return { state: "stopped" };
|
|
1590
|
+
}
|
|
1591
|
+
return { state: "other", detail: state2 };
|
|
1592
|
+
}
|
|
1593
|
+
function deviceOf({ udid, name: name2, state: state2, os }) {
|
|
1594
|
+
return {
|
|
1595
|
+
platform: "ios",
|
|
1596
|
+
kind: "simulator",
|
|
1597
|
+
udid,
|
|
1598
|
+
name: name2,
|
|
1599
|
+
os,
|
|
1600
|
+
...stateOf2(state2)
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
function hasSimulators(context) {
|
|
1604
|
+
return context.hostPlatform === "darwin";
|
|
1605
|
+
}
|
|
1606
|
+
async function readSimulators(context) {
|
|
1607
|
+
return parseSimctlList(await createSimctl(context).text(["list", "--json"]));
|
|
1608
|
+
}
|
|
1609
|
+
async function listIosSimulators(context) {
|
|
1610
|
+
if (!hasSimulators(context)) return { devices: [], warnings: [] };
|
|
1611
|
+
const devices = (await readSimulators(context)).map(deviceOf);
|
|
1612
|
+
return {
|
|
1613
|
+
devices: [
|
|
1614
|
+
...devices.filter((device) => device.state !== "stopped"),
|
|
1615
|
+
...devices.filter((device) => device.state === "stopped")
|
|
1616
|
+
],
|
|
1617
|
+
warnings: []
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
// src/drivers/select.ts
|
|
1622
|
+
var BOOTED = "Booted";
|
|
1623
|
+
var describe = ({ name: name2, udid, os }) => `${name2} (${udid}, ${os})`;
|
|
1624
|
+
async function orWhenFails(promise, fallback) {
|
|
1625
|
+
try {
|
|
1626
|
+
return await promise;
|
|
1627
|
+
} catch (error) {
|
|
1628
|
+
if (error instanceof LoupeError) return fallback;
|
|
1629
|
+
throw error;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
function ios(context, { udid, name: name2, os }) {
|
|
1633
|
+
return {
|
|
1634
|
+
platform: "ios",
|
|
1635
|
+
target: { udid, name: name2, os, signal: context.signal }
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
async function android(context, wanted) {
|
|
1639
|
+
return {
|
|
1640
|
+
platform: "android",
|
|
1641
|
+
target: await selectAndroidDevice(context, wanted)
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
function notRunning(simulator) {
|
|
1645
|
+
return new LoupeError(
|
|
1646
|
+
"device_unavailable",
|
|
1647
|
+
simulator.state === "Booting" ? `The simulator ${describe(simulator)} is still booting. Wait until it's ready, then try again.` : `The simulator ${describe(simulator)} doesn't run. Start it, then try again.`
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
function byName(named, wanted) {
|
|
1651
|
+
const booted = named.filter((simulator) => simulator.state === BOOTED);
|
|
1652
|
+
if (booted.length > 1) {
|
|
1653
|
+
throw new LoupeError(
|
|
1654
|
+
"device_ambiguous",
|
|
1655
|
+
`${booted.length} simulators with the name "${wanted}" run: ${booted.map(describe).join(", ")}. Give the UDID of one in the "device" option.`
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
const [only] = booted;
|
|
1659
|
+
if (only) return only;
|
|
1660
|
+
const [first] = named;
|
|
1661
|
+
if (named.length === 1 && first) throw notRunning(first);
|
|
1662
|
+
throw new LoupeError(
|
|
1663
|
+
"device_unavailable",
|
|
1664
|
+
`No simulator with the name "${wanted}" runs. Start one, then try again.`
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
async function selectNamed(context, wanted) {
|
|
1668
|
+
const simulators = await orWhenFails(readSimulators(context), []);
|
|
1669
|
+
const byUdid = simulators.find(
|
|
1670
|
+
(simulator) => simulator.udid.toLowerCase() === wanted.toLowerCase()
|
|
1671
|
+
);
|
|
1672
|
+
if (byUdid) {
|
|
1673
|
+
if (byUdid.state !== BOOTED) throw notRunning(byUdid);
|
|
1674
|
+
return ios(context, byUdid);
|
|
1675
|
+
}
|
|
1676
|
+
try {
|
|
1677
|
+
return await android(context, wanted);
|
|
1678
|
+
} catch (error) {
|
|
1679
|
+
const open = error instanceof LoupeError && (error.code === "no_device" || error.code === "tool_missing");
|
|
1680
|
+
if (!open) throw error;
|
|
1681
|
+
const named = simulators.filter((simulator) => simulator.name === wanted);
|
|
1682
|
+
if (named.length > 0) return ios(context, byName(named, wanted));
|
|
1683
|
+
if (error.code === "tool_missing") throw error;
|
|
1684
|
+
throw new LoupeError(
|
|
1685
|
+
"no_device",
|
|
1686
|
+
`No device has the serial, the AVD name, the UDID or the simulator name "${wanted}". Run "loupe devices" to see the list.`
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
async function selectOnly(context) {
|
|
1691
|
+
const booted = (await orWhenFails(readSimulators(context), [])).filter(
|
|
1692
|
+
(simulator) => simulator.state === BOOTED
|
|
1693
|
+
);
|
|
1694
|
+
if (booted.length === 0) {
|
|
1695
|
+
try {
|
|
1696
|
+
return await android(context);
|
|
1697
|
+
} catch (error) {
|
|
1698
|
+
if (error instanceof LoupeError && error.code === "no_device") {
|
|
1699
|
+
throw new LoupeError(
|
|
1700
|
+
"no_device",
|
|
1701
|
+
"loupe finds no Android device, no running emulator and no running iOS simulator. Start one or connect a device, then try again."
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
throw error;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
const ready = await orWhenFails(readyAndroidDevices(context), []);
|
|
1708
|
+
const [only] = booted;
|
|
1709
|
+
if (ready.length === 0 && booted.length === 1 && only) {
|
|
1710
|
+
return ios(context, only);
|
|
1711
|
+
}
|
|
1712
|
+
throw new LoupeError(
|
|
1713
|
+
"device_ambiguous",
|
|
1714
|
+
`${ready.length + booted.length} devices are ready: ${[...ready, ...booted.map(describe)].join(", ")}. Choose one with the "device" option.`
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
async function selectDevice(context, wanted) {
|
|
1718
|
+
if (!hasSimulators(context)) return android(context, wanted);
|
|
1719
|
+
if (wanted) return selectNamed(context, wanted);
|
|
1720
|
+
if (context.env.ANDROID_SERIAL) return android(context);
|
|
1721
|
+
return selectOnly(context);
|
|
1722
|
+
}
|
|
1723
|
+
async function selectAndroidOnly(context, wanted) {
|
|
1724
|
+
const selected = await selectDevice(context, wanted);
|
|
1725
|
+
if (selected.platform === "android") return selected.target;
|
|
1726
|
+
const { name: name2, udid, os } = selected.target;
|
|
1727
|
+
throw new LoupeError(
|
|
1728
|
+
"unsupported",
|
|
1729
|
+
`loupe doesn't drive an iOS simulator yet: "loupe devices" only lists it. The device is ${name2} (${udid}, ${os}). For an Android device, give its serial or its AVD name in the "device" option.`
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1487
1733
|
// src/core/png.ts
|
|
1488
1734
|
import { crc32, deflateSync, inflateSync } from "zlib";
|
|
1489
1735
|
var SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
@@ -1785,15 +2031,15 @@ function changeShot(png, displayScale, { crop, scale }) {
|
|
|
1785
2031
|
}
|
|
1786
2032
|
|
|
1787
2033
|
// src/core/insets.ts
|
|
1788
|
-
import { z as
|
|
1789
|
-
var insetsSchema =
|
|
1790
|
-
top:
|
|
1791
|
-
right:
|
|
1792
|
-
bottom:
|
|
1793
|
-
left:
|
|
2034
|
+
import { z as z8 } from "zod";
|
|
2035
|
+
var insetsSchema = z8.object({
|
|
2036
|
+
top: z8.number(),
|
|
2037
|
+
right: z8.number(),
|
|
2038
|
+
bottom: z8.number(),
|
|
2039
|
+
left: z8.number()
|
|
1794
2040
|
});
|
|
1795
2041
|
var insetsReadingSchema = displaySchema.extend({
|
|
1796
|
-
source:
|
|
2042
|
+
source: z8.enum(["probe", "dumpsys"]).describe(
|
|
1797
2043
|
`Where the safe area comes from: "probe" is the app's own numbers, from the <LoupeProbe /> on the screen; "dumpsys" is the system's. The system bars and the cutout always come from the system.`
|
|
1798
2044
|
),
|
|
1799
2045
|
safeArea: insetsSchema.describe(
|
|
@@ -1803,8 +2049,8 @@ var insetsReadingSchema = displaySchema.extend({
|
|
|
1803
2049
|
"The status bar and the navigation bar, per edge, in dp."
|
|
1804
2050
|
),
|
|
1805
2051
|
cutout: insetsSchema.describe("The cutout, per edge, in dp."),
|
|
1806
|
-
cutoutRects:
|
|
1807
|
-
warnings:
|
|
2052
|
+
cutoutRects: z8.array(rectSchema).describe("The cutout shapes as rectangles, in dp. Empty with no cutout."),
|
|
2053
|
+
warnings: z8.array(z8.string())
|
|
1808
2054
|
});
|
|
1809
2055
|
var NO_INSETS = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
1810
2056
|
var EDGES = ["top", "right", "bottom", "left"];
|
|
@@ -1827,18 +2073,18 @@ function describeInsets({ top, right, bottom, left }) {
|
|
|
1827
2073
|
}
|
|
1828
2074
|
|
|
1829
2075
|
// src/core/probe.ts
|
|
1830
|
-
import { z as
|
|
2076
|
+
import { z as z9 } from "zod";
|
|
1831
2077
|
var PROBE_PREFIX = "loupe:";
|
|
1832
2078
|
var PROBE_FORMAT = 1;
|
|
1833
|
-
var probeReportSchema =
|
|
2079
|
+
var probeReportSchema = z9.object({
|
|
1834
2080
|
insets: insetsSchema.optional().describe(
|
|
1835
2081
|
"The app's safe-area insets, in dp (pt on iOS). Left out when the probe has no SafeAreaProvider above it."
|
|
1836
2082
|
),
|
|
1837
|
-
window:
|
|
1838
|
-
scale:
|
|
1839
|
-
direction:
|
|
1840
|
-
colorScheme:
|
|
1841
|
-
route:
|
|
2083
|
+
window: z9.object({ width: z9.number(), height: z9.number() }).describe("The window size that the app gets, in dp (pt on iOS)."),
|
|
2084
|
+
scale: z9.number().describe("Pixels per dp (pt on iOS), as the app sees it."),
|
|
2085
|
+
direction: z9.enum(["ltr", "rtl"]).describe("The layout direction."),
|
|
2086
|
+
colorScheme: z9.enum(["light", "dark"]).optional(),
|
|
2087
|
+
route: z9.string().optional().describe("The route that the app gives to the probe.")
|
|
1842
2088
|
});
|
|
1843
2089
|
function isProbeLabel(label2) {
|
|
1844
2090
|
return label2?.startsWith(PROBE_PREFIX) ?? false;
|
|
@@ -1887,7 +2133,7 @@ function describeProbe(report) {
|
|
|
1887
2133
|
|
|
1888
2134
|
// src/drivers/android/ui.ts
|
|
1889
2135
|
var BOUNDS = /^\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]$/;
|
|
1890
|
-
var
|
|
2136
|
+
var MESSAGE_LIMIT = 200;
|
|
1891
2137
|
function frameOf(element, scale) {
|
|
1892
2138
|
const match = BOUNDS.exec(element.attributes.bounds ?? "");
|
|
1893
2139
|
if (!match) {
|
|
@@ -1959,7 +2205,7 @@ function readDump(target, output, parse) {
|
|
|
1959
2205
|
const line = output.split(/\r?\n/).map((text) => text.trim()).find(Boolean);
|
|
1960
2206
|
throw new LoupeError(
|
|
1961
2207
|
"tool_failed",
|
|
1962
|
-
line ? `uiautomator on ${target.serial} gave no tree: ${line.slice(0,
|
|
2208
|
+
line ? `uiautomator on ${target.serial} gave no tree: ${line.slice(0, MESSAGE_LIMIT)}` : `uiautomator on ${target.serial} gave no tree.`
|
|
1963
2209
|
);
|
|
1964
2210
|
}
|
|
1965
2211
|
async function readAndroidUi(target, app) {
|
|
@@ -2254,14 +2500,14 @@ async function waitAfterAction(target, app, { waitStill, waitText, waitTimeout =
|
|
|
2254
2500
|
}
|
|
2255
2501
|
|
|
2256
2502
|
// src/commands/foreground.ts
|
|
2257
|
-
import { z as
|
|
2258
|
-
var backSchema =
|
|
2259
|
-
way:
|
|
2503
|
+
import { z as z10 } from "zod";
|
|
2504
|
+
var backSchema = z10.object({
|
|
2505
|
+
way: z10.enum(["in-front", ...WAYS_BACK]).describe(
|
|
2260
2506
|
'How the app came back. in-front: it was in front already. recents: the Recents key two times, as a person does. task-lock: am task lock on its task, then lock stop; Android shows an "App unpinned" toast for a few seconds.'
|
|
2261
2507
|
),
|
|
2262
|
-
tried:
|
|
2263
|
-
task:
|
|
2264
|
-
ms:
|
|
2508
|
+
tried: z10.array(z10.enum(WAYS_BACK)).describe("Each way that loupe tried, in order."),
|
|
2509
|
+
task: z10.number().optional().describe("The id of the task that came back."),
|
|
2510
|
+
ms: z10.number().describe(
|
|
2265
2511
|
"Milliseconds from the first key or command until the app had the focus."
|
|
2266
2512
|
)
|
|
2267
2513
|
});
|
|
@@ -2274,7 +2520,7 @@ function describeBack(app, back) {
|
|
|
2274
2520
|
var foregroundCommand = defineCommand({
|
|
2275
2521
|
name: "foreground",
|
|
2276
2522
|
summary: "Bring an app back to the front: its most recent task, as a person does from Recents",
|
|
2277
|
-
input:
|
|
2523
|
+
input: z10.object({
|
|
2278
2524
|
app: appField.unwrap().describe(
|
|
2279
2525
|
"The package of the app to bring back, for example host.exp.exponent for Expo Go."
|
|
2280
2526
|
),
|
|
@@ -2283,11 +2529,11 @@ var foregroundCommand = defineCommand({
|
|
|
2283
2529
|
}),
|
|
2284
2530
|
positionals: ["app"],
|
|
2285
2531
|
output: backSchema.extend({
|
|
2286
|
-
app:
|
|
2532
|
+
app: z10.string(),
|
|
2287
2533
|
waited: waitedSchema.optional()
|
|
2288
2534
|
}),
|
|
2289
2535
|
run: async ({ app, device, waitStill, waitText, waitTimeout }, context) => {
|
|
2290
|
-
const target = await
|
|
2536
|
+
const target = await selectAndroidOnly(context, device);
|
|
2291
2537
|
const back = await foregroundAndroid(target, app);
|
|
2292
2538
|
const waited = await waitAfterAction(
|
|
2293
2539
|
target,
|
|
@@ -2304,17 +2550,17 @@ var foregroundCommand = defineCommand({
|
|
|
2304
2550
|
var backgroundCommand = defineCommand({
|
|
2305
2551
|
name: "background",
|
|
2306
2552
|
summary: "Send the app in front to the background with HOME, and with --for bring it back after that time",
|
|
2307
|
-
input:
|
|
2308
|
-
for:
|
|
2553
|
+
input: z11.object({
|
|
2554
|
+
for: z11.number().int().min(0).max(6e5).optional().describe(
|
|
2309
2555
|
"Milliseconds in the background. Then loupe brings the app back, as the foreground command does. With no value, the app stays in the background."
|
|
2310
2556
|
),
|
|
2311
2557
|
...waitFields,
|
|
2312
2558
|
app: appField,
|
|
2313
2559
|
device: deviceField
|
|
2314
2560
|
}),
|
|
2315
|
-
output:
|
|
2316
|
-
app:
|
|
2317
|
-
away:
|
|
2561
|
+
output: z11.object({
|
|
2562
|
+
app: z11.string().describe("The package that went to the background."),
|
|
2563
|
+
away: z11.number().optional().describe(
|
|
2318
2564
|
"Milliseconds from HOME to the first step back. Left out with no --for."
|
|
2319
2565
|
),
|
|
2320
2566
|
back: backSchema.optional().describe("How the app came back."),
|
|
@@ -2328,7 +2574,7 @@ var backgroundCommand = defineCommand({
|
|
|
2328
2574
|
"The wait options need --for: with no --for, the app stays in the background, and there is nothing to wait for."
|
|
2329
2575
|
);
|
|
2330
2576
|
}
|
|
2331
|
-
const target = await
|
|
2577
|
+
const target = await selectAndroidOnly(context, input.device);
|
|
2332
2578
|
const result = await backgroundAndroid(target, input.app, input.for);
|
|
2333
2579
|
const waited = result.back ? await waitAfterAction(
|
|
2334
2580
|
target,
|
|
@@ -2354,10 +2600,10 @@ var backgroundCommand = defineCommand({
|
|
|
2354
2600
|
// src/commands/check.ts
|
|
2355
2601
|
import { readFile } from "fs/promises";
|
|
2356
2602
|
import path4 from "path";
|
|
2357
|
-
import { z as
|
|
2603
|
+
import { z as z14 } from "zod";
|
|
2358
2604
|
|
|
2359
2605
|
// src/core/check.ts
|
|
2360
|
-
import { z as
|
|
2606
|
+
import { z as z12 } from "zod";
|
|
2361
2607
|
|
|
2362
2608
|
// src/core/ink.ts
|
|
2363
2609
|
var INK_TOLERANCE = 32;
|
|
@@ -2434,34 +2680,34 @@ var MIN_TOUCH_TARGET = 48;
|
|
|
2434
2680
|
var HIT_SLOP_BAND = 8;
|
|
2435
2681
|
var CENTRE_TOLERANCE = 4;
|
|
2436
2682
|
var CLEAR_GAP = 24;
|
|
2437
|
-
var findingSchema =
|
|
2683
|
+
var findingSchema = z12.object({
|
|
2438
2684
|
element: elementSchema,
|
|
2439
|
-
message:
|
|
2440
|
-
details:
|
|
2685
|
+
message: z12.string().describe("What is wrong, with the numbers, for a person."),
|
|
2686
|
+
details: z12.record(z12.string(), z12.number()).describe("The numbers of the finding, in dp, by name.")
|
|
2441
2687
|
});
|
|
2442
|
-
var ruleResultSchema =
|
|
2443
|
-
rule:
|
|
2444
|
-
passed:
|
|
2445
|
-
checked:
|
|
2446
|
-
findings:
|
|
2447
|
-
warnings:
|
|
2688
|
+
var ruleResultSchema = z12.object({
|
|
2689
|
+
rule: z12.enum(RULES),
|
|
2690
|
+
passed: z12.boolean(),
|
|
2691
|
+
checked: z12.number().describe("The elements that the rule looked at."),
|
|
2692
|
+
findings: z12.array(findingSchema),
|
|
2693
|
+
warnings: z12.array(z12.string()).optional().describe(
|
|
2448
2694
|
"Notes that are no finding: an element that you named but the rule could not check, or a touch target that a hitSlop can make whole."
|
|
2449
2695
|
)
|
|
2450
2696
|
});
|
|
2451
2697
|
var screenCheckSchema = displaySchema.extend({
|
|
2452
|
-
app:
|
|
2453
|
-
safeAreaSource:
|
|
2454
|
-
passed:
|
|
2455
|
-
results:
|
|
2456
|
-
warnings:
|
|
2698
|
+
app: z12.string().optional().describe("The package of the window in the tree."),
|
|
2699
|
+
safeAreaSource: z12.enum(["probe", "dumpsys"]).describe("Where the safe area comes from, as in `insets`."),
|
|
2700
|
+
passed: z12.boolean().describe("True when every rule passed."),
|
|
2701
|
+
results: z12.array(ruleResultSchema),
|
|
2702
|
+
warnings: z12.array(z12.string())
|
|
2457
2703
|
});
|
|
2458
2704
|
function place(screen) {
|
|
2459
2705
|
const placed = [];
|
|
2460
2706
|
const walk = (nodes, scrollAxes) => {
|
|
2461
2707
|
for (const node of nodes) {
|
|
2462
|
-
if (isExpoGoOverlay(node, screen.app)) continue;
|
|
2708
|
+
if (isExpoGoOverlay(node, screen.app, screen.platform)) continue;
|
|
2463
2709
|
placed.push({ node, siblings: nodes, scrollAxes });
|
|
2464
|
-
const inner = node.scrollable ? /* @__PURE__ */ new Set([...scrollAxes, scrollAxisOf(node)]) : scrollAxes;
|
|
2710
|
+
const inner = node.scrollable ? /* @__PURE__ */ new Set([...scrollAxes, scrollAxisOf(node, screen.platform)]) : scrollAxes;
|
|
2465
2711
|
walk(node.children ?? [], inner);
|
|
2466
2712
|
}
|
|
2467
2713
|
};
|
|
@@ -2981,6 +3227,7 @@ async function checkAndroidUi(target, app, ui, names, options = {}, shot = false
|
|
|
2981
3227
|
}
|
|
2982
3228
|
}
|
|
2983
3229
|
const screen = {
|
|
3230
|
+
platform: "android",
|
|
2984
3231
|
display: ui.display,
|
|
2985
3232
|
app: ui.app,
|
|
2986
3233
|
nodes: ui.nodes,
|
|
@@ -3008,7 +3255,7 @@ async function checkAndroid(target, app, names, options = {}, shot = false) {
|
|
|
3008
3255
|
}
|
|
3009
3256
|
|
|
3010
3257
|
// src/commands/ui.ts
|
|
3011
|
-
import { z as
|
|
3258
|
+
import { z as z13 } from "zod";
|
|
3012
3259
|
|
|
3013
3260
|
// src/core/output-file.ts
|
|
3014
3261
|
import { mkdir, writeFile } from "fs/promises";
|
|
@@ -3025,26 +3272,26 @@ var uiCommand = defineCommand({
|
|
|
3025
3272
|
name: "ui",
|
|
3026
3273
|
summary: "Read the accessibility tree of the screen, with frames in dp",
|
|
3027
3274
|
readOnly: true,
|
|
3028
|
-
input:
|
|
3029
|
-
out:
|
|
3275
|
+
input: z13.object({
|
|
3276
|
+
out: z13.string().min(1).optional().describe(
|
|
3030
3277
|
"Also write the result as JSON to this file, to give to check as mirrorOf later. loupe makes its folder, and replaces a file that is there."
|
|
3031
3278
|
),
|
|
3032
3279
|
app: appField,
|
|
3033
3280
|
device: deviceField
|
|
3034
3281
|
}),
|
|
3035
3282
|
output: displaySchema.extend({
|
|
3036
|
-
app:
|
|
3037
|
-
nodes:
|
|
3283
|
+
app: z13.string().optional().describe("The package of the window in the tree."),
|
|
3284
|
+
nodes: z13.array(uiNodeSchema).describe(
|
|
3038
3285
|
"The tree of the window in front. A system sheet, for example the share sheet, takes the place of the app below it."
|
|
3039
3286
|
),
|
|
3040
3287
|
probe: probeReportSchema.optional().describe(
|
|
3041
3288
|
"The report of the app's <LoupeProbe />, when the screen shows one. The probe's own node isn't in nodes."
|
|
3042
3289
|
),
|
|
3043
|
-
file:
|
|
3290
|
+
file: z13.string().optional().describe("The JSON file, as an absolute path. Left out with no out.")
|
|
3044
3291
|
}),
|
|
3045
3292
|
run: async ({ out, app, device }, context) => {
|
|
3046
3293
|
const ui = await readAndroidUi(
|
|
3047
|
-
await
|
|
3294
|
+
await selectAndroidOnly(context, device),
|
|
3048
3295
|
app
|
|
3049
3296
|
);
|
|
3050
3297
|
const data = {
|
|
@@ -3066,7 +3313,7 @@ var uiCommand = defineCommand({
|
|
|
3066
3313
|
});
|
|
3067
3314
|
|
|
3068
3315
|
// src/commands/check.ts
|
|
3069
|
-
var centredField = (by) =>
|
|
3316
|
+
var centredField = (by) => z14.array(z14.string().min(1)).optional().describe(
|
|
3070
3317
|
`For the centred rule: the element with this ${by} must be at the centre of its container, whatever sits beside it. Give it once for each element.`
|
|
3071
3318
|
);
|
|
3072
3319
|
function notSaved(file, why) {
|
|
@@ -3126,6 +3373,7 @@ function otherDirection(file, saved, ui) {
|
|
|
3126
3373
|
);
|
|
3127
3374
|
}
|
|
3128
3375
|
return {
|
|
3376
|
+
platform: "android",
|
|
3129
3377
|
display: saved,
|
|
3130
3378
|
app: saved.app,
|
|
3131
3379
|
nodes: saved.nodes,
|
|
@@ -3136,14 +3384,14 @@ var checkCommand = defineCommand({
|
|
|
3136
3384
|
name: "check",
|
|
3137
3385
|
summary: "Check the screen for layout defects: elements under an inset, cut at an edge, off centre, too small to touch, or not mirrored in the other direction",
|
|
3138
3386
|
readOnly: true,
|
|
3139
|
-
input:
|
|
3140
|
-
rules:
|
|
3387
|
+
input: z14.object({
|
|
3388
|
+
rules: z14.string().regex(/^[a-z-]+(,[a-z-]+)*$/, "The rules are a comma list.").optional().describe(
|
|
3141
3389
|
`The rules to run, as a comma list. Each one by default: ${RULES.join(", ")} (mirrored only with --mirror-of).`
|
|
3142
3390
|
),
|
|
3143
3391
|
centred: centredField("text (the whole text)"),
|
|
3144
3392
|
centredLabel: centredField("accessibility label"),
|
|
3145
3393
|
centredId: centredField("id"),
|
|
3146
|
-
mirrorOf:
|
|
3394
|
+
mirrorOf: z14.string().min(1).optional().describe(
|
|
3147
3395
|
"For the mirrored rule: a file with this screen in the other layout direction, from loupe ui --json. Each element must sit where that screen puts it, mirrored."
|
|
3148
3396
|
),
|
|
3149
3397
|
app: appField,
|
|
@@ -3173,7 +3421,7 @@ var checkCommand = defineCommand({
|
|
|
3173
3421
|
);
|
|
3174
3422
|
}
|
|
3175
3423
|
const saved = input.mirrorOf ? await readSavedUi(input.mirrorOf) : void 0;
|
|
3176
|
-
const target = await
|
|
3424
|
+
const target = await selectAndroidOnly(context, input.device);
|
|
3177
3425
|
const ui = await readAndroidUi(target, input.app);
|
|
3178
3426
|
const mirrorOf = saved && input.mirrorOf ? otherDirection(input.mirrorOf, saved, ui) : void 0;
|
|
3179
3427
|
const { check } = await checkAndroidUi(target, input.app, ui, names, {
|
|
@@ -3191,15 +3439,48 @@ var checkCommand = defineCommand({
|
|
|
3191
3439
|
});
|
|
3192
3440
|
|
|
3193
3441
|
// src/commands/devices.ts
|
|
3194
|
-
import { z as
|
|
3195
|
-
|
|
3442
|
+
import { z as z15 } from "zod";
|
|
3443
|
+
|
|
3444
|
+
// src/drivers/devices.ts
|
|
3445
|
+
async function attempt2(promise) {
|
|
3446
|
+
try {
|
|
3447
|
+
return { list: await promise };
|
|
3448
|
+
} catch (error) {
|
|
3449
|
+
if (error instanceof LoupeError) return { error };
|
|
3450
|
+
throw error;
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
async function listDevices(context) {
|
|
3454
|
+
if (!hasSimulators(context)) return listAndroidDevices(context);
|
|
3455
|
+
const [android2, ios2] = await Promise.all([
|
|
3456
|
+
attempt2(listAndroidDevices(context)),
|
|
3457
|
+
attempt2(listIosSimulators(context))
|
|
3458
|
+
]);
|
|
3459
|
+
if ("error" in android2 && "error" in ios2) throw android2.error;
|
|
3460
|
+
const lists = [android2, ios2].map(
|
|
3461
|
+
(listed, index) => "list" in listed ? listed.list : {
|
|
3462
|
+
devices: [],
|
|
3463
|
+
warnings: [
|
|
3464
|
+
`The list has no ${index === 0 ? "Android devices" : "iOS simulators"}. ${listed.error.message}`
|
|
3465
|
+
]
|
|
3466
|
+
}
|
|
3467
|
+
);
|
|
3468
|
+
return {
|
|
3469
|
+
devices: lists.flatMap((list) => list.devices),
|
|
3470
|
+
warnings: lists.flatMap((list) => list.warnings)
|
|
3471
|
+
};
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
// src/commands/devices.ts
|
|
3475
|
+
var HEADER = ["Id", "State", "Kind", "Name", "OS"];
|
|
3476
|
+
var idOf = (device) => device.serial ?? device.udid;
|
|
3196
3477
|
function row(device) {
|
|
3197
3478
|
return [
|
|
3198
|
-
device
|
|
3479
|
+
idOf(device) ?? "-",
|
|
3199
3480
|
device.state,
|
|
3200
3481
|
device.kind,
|
|
3201
|
-
device.avd ?? device.model ?? "",
|
|
3202
|
-
device.apiLevel
|
|
3482
|
+
device.avd ?? device.name ?? device.model ?? "",
|
|
3483
|
+
device.apiLevel === void 0 ? device.os ?? "" : `API ${device.apiLevel}`
|
|
3203
3484
|
];
|
|
3204
3485
|
}
|
|
3205
3486
|
function table(rows) {
|
|
@@ -3212,17 +3493,17 @@ function table(rows) {
|
|
|
3212
3493
|
}
|
|
3213
3494
|
var devicesCommand = defineCommand({
|
|
3214
3495
|
name: "devices",
|
|
3215
|
-
summary: "List the Android emulators and devices, and the AVDs that don't run",
|
|
3496
|
+
summary: "List the Android emulators and devices, the iOS simulators, and the AVDs that don't run",
|
|
3216
3497
|
readOnly: true,
|
|
3217
|
-
input:
|
|
3218
|
-
output:
|
|
3219
|
-
devices:
|
|
3220
|
-
warnings:
|
|
3498
|
+
input: z15.object({}),
|
|
3499
|
+
output: z15.object({
|
|
3500
|
+
devices: z15.array(deviceSchema),
|
|
3501
|
+
warnings: z15.array(z15.string())
|
|
3221
3502
|
}),
|
|
3222
|
-
run: (_input, context) =>
|
|
3503
|
+
run: (_input, context) => listDevices(context),
|
|
3223
3504
|
format: ({ devices, warnings }) => {
|
|
3224
|
-
const lines2 = devices.length > 0 ? table([HEADER, ...devices.map(row)]) : ["No devices, and no
|
|
3225
|
-
const details = devices.filter((device) => device.detail).map((device) => `${device
|
|
3505
|
+
const lines2 = devices.length > 0 ? table([HEADER, ...devices.map(row)]) : ["No devices, no AVDs, and no simulators."];
|
|
3506
|
+
const details = devices.filter((device) => device.detail).map((device) => `${idOf(device)}: ${device.detail}`);
|
|
3226
3507
|
return [
|
|
3227
3508
|
...lines2,
|
|
3228
3509
|
...details,
|
|
@@ -3232,7 +3513,7 @@ var devicesCommand = defineCommand({
|
|
|
3232
3513
|
});
|
|
3233
3514
|
|
|
3234
3515
|
// src/commands/dismiss.ts
|
|
3235
|
-
import { z as
|
|
3516
|
+
import { z as z16 } from "zod";
|
|
3236
3517
|
|
|
3237
3518
|
// src/drivers/android/dismiss.ts
|
|
3238
3519
|
import { setTimeout as sleep5 } from "timers/promises";
|
|
@@ -3407,7 +3688,7 @@ function unknownWindow(owner, type) {
|
|
|
3407
3688
|
}
|
|
3408
3689
|
async function topOverlay(target, app) {
|
|
3409
3690
|
const ui = await readAndroidUi(target, app);
|
|
3410
|
-
return labelledOverlays({ ...ui, app }).at(-1)?.label;
|
|
3691
|
+
return labelledOverlays({ ...ui, platform: "android", app }).at(-1)?.label;
|
|
3411
3692
|
}
|
|
3412
3693
|
async function appFront(target, app) {
|
|
3413
3694
|
try {
|
|
@@ -3586,18 +3867,18 @@ async function dismissAndroid(target, app, { all = false, limit = 5e3, interval
|
|
|
3586
3867
|
}
|
|
3587
3868
|
|
|
3588
3869
|
// src/commands/dismiss.ts
|
|
3589
|
-
var layerSchema =
|
|
3870
|
+
var layerSchema = z16.enum(LAYERS).describe(
|
|
3590
3871
|
`keyboard. stylus-sheet: the "Try out your stylus" sheet of Gboard's stylus mode, which a stylus touch starts (on an emulator, loupe's double-tap, drag and pinch are one). app-dialog: a dialog or a modal of the app. app-overlay: a menu, a sheet or a dialog that the app draws in its own window, found by its scrim or outside-press region: a node over the whole screen with a label and a touch. share-sheet: the system share sheet. permission-dialog: Android doesn't count Back as a denial, and the app's request can stay with no answer. notification-shade: also with the quick settings open. not-responding: an "isn't responding" dialog, of any app.`
|
|
3591
3872
|
);
|
|
3592
|
-
var closedSchema =
|
|
3873
|
+
var closedSchema = z16.object({
|
|
3593
3874
|
layer: layerSchema,
|
|
3594
|
-
label:
|
|
3875
|
+
label: z16.string().optional().describe(
|
|
3595
3876
|
"The label of the scrim or the outside-press region of an app-overlay."
|
|
3596
3877
|
),
|
|
3597
|
-
way:
|
|
3878
|
+
way: z16.enum(DISMISS_WAYS).describe(
|
|
3598
3879
|
`back: the Back key. escape: the Escape key, for the keyboard in Gboard's stylus mode, where Back also reaches the app. tap-cancel: a tap on Cancel in the stylus sheet. collapse: the status bar collapse, which closes the shade and the quick settings in one step. tap-wait: a tap on Wait in an "isn't responding" dialog, so the app gets more time.`
|
|
3599
3880
|
),
|
|
3600
|
-
ms:
|
|
3881
|
+
ms: z16.number().describe(
|
|
3601
3882
|
"Milliseconds from the key, command or tap until the layer was gone."
|
|
3602
3883
|
)
|
|
3603
3884
|
});
|
|
@@ -3614,29 +3895,29 @@ function summaryOf(app, closed, next) {
|
|
|
3614
3895
|
var dismissCommand = defineCommand({
|
|
3615
3896
|
name: "dismiss",
|
|
3616
3897
|
summary: "Close the top layer over the app: the keyboard, a dialog, the app's own menu or sheet, a system sheet or the notification shade. With --all, each layer",
|
|
3617
|
-
input:
|
|
3618
|
-
all:
|
|
3898
|
+
input: z16.object({
|
|
3899
|
+
all: z16.boolean().optional().describe(
|
|
3619
3900
|
`Close each layer, from the top, until the app's own screen shows: at most ${MAX_LAYERS}.`
|
|
3620
3901
|
),
|
|
3621
3902
|
...waitFields,
|
|
3622
3903
|
app: appField,
|
|
3623
3904
|
device: deviceField
|
|
3624
3905
|
}),
|
|
3625
|
-
output:
|
|
3626
|
-
app:
|
|
3906
|
+
output: z16.object({
|
|
3907
|
+
app: z16.string().optional().describe(
|
|
3627
3908
|
"The package under the layers. Left out when a layer still shows and the input has no app."
|
|
3628
3909
|
),
|
|
3629
|
-
closed:
|
|
3910
|
+
closed: z16.array(closedSchema).describe(
|
|
3630
3911
|
"Each layer that loupe closed, from the top. Empty when nothing was open: then loupe sent no key."
|
|
3631
3912
|
),
|
|
3632
3913
|
next: layerSchema.optional().describe(
|
|
3633
3914
|
`The layer that shows now, when loupe stopped before the app: one call closes one layer, and --all stops after ${MAX_LAYERS}.`
|
|
3634
3915
|
),
|
|
3635
3916
|
waited: waitedSchema.optional(),
|
|
3636
|
-
warnings:
|
|
3917
|
+
warnings: z16.array(z16.string()).optional()
|
|
3637
3918
|
}),
|
|
3638
3919
|
run: async ({ all, app, device, ...wait }, context) => {
|
|
3639
|
-
const target = await
|
|
3920
|
+
const target = await selectAndroidOnly(context, device);
|
|
3640
3921
|
const result = await dismissAndroid(target, app, { all });
|
|
3641
3922
|
const waited = await waitAfterAction(target, app, wait, "dismiss");
|
|
3642
3923
|
return { ...result, waited };
|
|
@@ -3648,24 +3929,24 @@ var dismissCommand = defineCommand({
|
|
|
3648
3929
|
});
|
|
3649
3930
|
|
|
3650
3931
|
// src/commands/double-tap.ts
|
|
3651
|
-
import { z as
|
|
3932
|
+
import { z as z18 } from "zod";
|
|
3652
3933
|
|
|
3653
3934
|
// src/core/touch.ts
|
|
3654
|
-
import { z as
|
|
3655
|
-
var pointSchema =
|
|
3935
|
+
import { z as z17 } from "zod";
|
|
3936
|
+
var pointSchema = z17.object({ x: z17.number(), y: z17.number() });
|
|
3656
3937
|
function coordinateField(axis) {
|
|
3657
|
-
return
|
|
3938
|
+
return z17.number().min(0).describe(
|
|
3658
3939
|
`${axis === "x" ? "Across" : "Down"} from the top-left corner of the screen, in dp (pt on iOS), not px.`
|
|
3659
3940
|
);
|
|
3660
3941
|
}
|
|
3661
3942
|
function durationField(byDefault, what) {
|
|
3662
|
-
return
|
|
3943
|
+
return z17.number().int().min(0).default(byDefault).describe(`Milliseconds ${what}.`);
|
|
3663
3944
|
}
|
|
3664
|
-
var touchSchema =
|
|
3665
|
-
orientation:
|
|
3666
|
-
points:
|
|
3667
|
-
pixels:
|
|
3668
|
-
duration:
|
|
3945
|
+
var touchSchema = z17.object({
|
|
3946
|
+
orientation: z17.enum(ORIENTATIONS),
|
|
3947
|
+
points: z17.array(pointSchema).describe("The points of the touch, in dp."),
|
|
3948
|
+
pixels: z17.array(pointSchema).describe("The same points in px, as loupe sent them."),
|
|
3949
|
+
duration: z17.number().optional().describe("In milliseconds.")
|
|
3669
3950
|
});
|
|
3670
3951
|
var aimedTouchSchema = touchSchema.extend({
|
|
3671
3952
|
element: elementSchema.optional().describe("The element that loupe touched, when the input named one.")
|
|
@@ -4035,7 +4316,7 @@ async function dragAndroid(target, from, to, options, app) {
|
|
|
4035
4316
|
var doubleTapCommand = defineCommand({
|
|
4036
4317
|
name: "double-tap",
|
|
4037
4318
|
summary: "Tap one point or element twice, as a double-tap, by text, label or id",
|
|
4038
|
-
input:
|
|
4319
|
+
input: z18.object({
|
|
4039
4320
|
x: coordinateField("x").optional(),
|
|
4040
4321
|
y: coordinateField("y").optional(),
|
|
4041
4322
|
...selectorFields,
|
|
@@ -4045,13 +4326,13 @@ var doubleTapCommand = defineCommand({
|
|
|
4045
4326
|
}),
|
|
4046
4327
|
positionals: ["x", "y"],
|
|
4047
4328
|
output: aimedTouchSchema.extend({
|
|
4048
|
-
gap:
|
|
4329
|
+
gap: z18.number().describe(
|
|
4049
4330
|
"Milliseconds between the two taps: on an emulator, measured on the host through the emulator console; on a real device, measured on the device."
|
|
4050
4331
|
),
|
|
4051
4332
|
waited: waitedSchema.optional()
|
|
4052
4333
|
}),
|
|
4053
4334
|
run: async ({ app, device, waitStill, waitText, waitTimeout, ...input }, context) => {
|
|
4054
|
-
const target = await
|
|
4335
|
+
const target = await selectAndroidOnly(context, device);
|
|
4055
4336
|
const { point, element } = await aimAndroid(target, targetOf(input), app);
|
|
4056
4337
|
const touch2 = await doubleTapAndroid(target, point, app);
|
|
4057
4338
|
const waited = await waitAfterAction(
|
|
@@ -4069,11 +4350,11 @@ var doubleTapCommand = defineCommand({
|
|
|
4069
4350
|
});
|
|
4070
4351
|
|
|
4071
4352
|
// src/commands/drag.ts
|
|
4072
|
-
import { z as
|
|
4353
|
+
import { z as z19 } from "zod";
|
|
4073
4354
|
var dragCommand = defineCommand({
|
|
4074
4355
|
name: "drag",
|
|
4075
4356
|
summary: "Touch, hold, move, hold and lift, with a screenshot while the touch is down",
|
|
4076
|
-
input:
|
|
4357
|
+
input: z19.object({
|
|
4077
4358
|
fromX: coordinateField("x"),
|
|
4078
4359
|
fromY: coordinateField("y"),
|
|
4079
4360
|
toX: coordinateField("x"),
|
|
@@ -4084,10 +4365,10 @@ var dragCommand = defineCommand({
|
|
|
4084
4365
|
),
|
|
4085
4366
|
holdStart: durationField(0, "to hold the touch before it moves"),
|
|
4086
4367
|
holdEnd: durationField(0, "to hold the touch at the end, before it lifts"),
|
|
4087
|
-
shot:
|
|
4368
|
+
shot: z19.string().min(1).optional().describe(
|
|
4088
4369
|
"A PNG file. loupe takes a screenshot while the touch is down, and writes it there."
|
|
4089
4370
|
),
|
|
4090
|
-
shotAt:
|
|
4371
|
+
shotAt: z19.number().min(0).max(1).default(1).describe(
|
|
4091
4372
|
"Where along the move loupe takes the screenshot: 0 is after the start hold, 1 is after the end hold. In between, the touch pauses there while the screenshot runs."
|
|
4092
4373
|
),
|
|
4093
4374
|
...waitFields,
|
|
@@ -4096,12 +4377,12 @@ var dragCommand = defineCommand({
|
|
|
4096
4377
|
}),
|
|
4097
4378
|
positionals: ["fromX", "fromY", "toX", "toY"],
|
|
4098
4379
|
output: touchSchema.extend({
|
|
4099
|
-
holdStart:
|
|
4100
|
-
holdEnd:
|
|
4101
|
-
moveTime:
|
|
4380
|
+
holdStart: z19.number(),
|
|
4381
|
+
holdEnd: z19.number(),
|
|
4382
|
+
moveTime: z19.number().describe(
|
|
4102
4383
|
"Milliseconds that the move took, with a screenshot in the move: on an emulator, measured on the host through the emulator console; on a real device, measured on the device."
|
|
4103
4384
|
),
|
|
4104
|
-
shot:
|
|
4385
|
+
shot: z19.string().optional().describe("The PNG file, as an absolute path."),
|
|
4105
4386
|
waited: waitedSchema.optional()
|
|
4106
4387
|
}),
|
|
4107
4388
|
run: async ({
|
|
@@ -4118,7 +4399,7 @@ var dragCommand = defineCommand({
|
|
|
4118
4399
|
waitTimeout,
|
|
4119
4400
|
...timing
|
|
4120
4401
|
}, context) => {
|
|
4121
|
-
const target = await
|
|
4402
|
+
const target = await selectAndroidOnly(context, device);
|
|
4122
4403
|
const { png, ...drag } = await dragAndroid(
|
|
4123
4404
|
target,
|
|
4124
4405
|
{ x: fromX, y: fromY },
|
|
@@ -4145,13 +4426,13 @@ var dragCommand = defineCommand({
|
|
|
4145
4426
|
});
|
|
4146
4427
|
|
|
4147
4428
|
// src/commands/expo-open.ts
|
|
4148
|
-
import { z as
|
|
4429
|
+
import { z as z21 } from "zod";
|
|
4149
4430
|
|
|
4150
4431
|
// src/drivers/android/expo.ts
|
|
4151
4432
|
import { setTimeout as sleep7 } from "timers/promises";
|
|
4152
4433
|
|
|
4153
4434
|
// src/expo/expo-go.ts
|
|
4154
|
-
var
|
|
4435
|
+
var EXPO_GO = "host.exp.exponent";
|
|
4155
4436
|
var CLOSE_BUTTON = {
|
|
4156
4437
|
onboarding: { by: "text", value: "Continue" },
|
|
4157
4438
|
"dev-menu": { by: "label", value: "Close" }
|
|
@@ -4176,9 +4457,9 @@ function expoGoScreenOf(nodes) {
|
|
|
4176
4457
|
}
|
|
4177
4458
|
return void 0;
|
|
4178
4459
|
}
|
|
4179
|
-
function hasAppContent(nodes) {
|
|
4460
|
+
function hasAppContent(nodes, platform) {
|
|
4180
4461
|
return nodes.some(
|
|
4181
|
-
(node) => node
|
|
4462
|
+
(node) => !isExpoGoOverlay(node, EXPO_GO, platform) && ((node.text || node.label || node.clickable || node.longClickable) && node.frame.width > 0 && node.frame.height > 0 || hasAppContent(node.children ?? [], platform))
|
|
4182
4463
|
);
|
|
4183
4464
|
}
|
|
4184
4465
|
function normalRoute(route) {
|
|
@@ -4247,25 +4528,25 @@ ${result.stderr.toString("utf8")}`
|
|
|
4247
4528
|
var OPEN_AGAIN_MS = 2e4;
|
|
4248
4529
|
var READ_INTERVAL = 500;
|
|
4249
4530
|
async function readExpoGoVersion(target) {
|
|
4250
|
-
const installed = await target.adb.result(["shell", "pm", "path",
|
|
4531
|
+
const installed = await target.adb.result(["shell", "pm", "path", EXPO_GO]);
|
|
4251
4532
|
if (installed.code !== 0 || !installed.stdout.toString("utf8").includes("package:")) {
|
|
4252
4533
|
throw new LoupeError(
|
|
4253
4534
|
"no_handler",
|
|
4254
4535
|
`Expo Go isn't on ${target.serial}. Ask the user to install it: press "a" in "npx expo start", and the Expo CLI installs the Expo Go of the app's SDK.`
|
|
4255
4536
|
);
|
|
4256
4537
|
}
|
|
4257
|
-
const dump = await target.adb.text(["shell", "dumpsys", "package",
|
|
4538
|
+
const dump = await target.adb.text(["shell", "dumpsys", "package", EXPO_GO]);
|
|
4258
4539
|
return /versionName=(\S+)/.exec(dump)?.[1];
|
|
4259
4540
|
}
|
|
4260
4541
|
function forceStopExpoGo(target, limit) {
|
|
4261
|
-
return forceStopAndroid(target,
|
|
4542
|
+
return forceStopAndroid(target, EXPO_GO, limit);
|
|
4262
4543
|
}
|
|
4263
4544
|
async function reverseAndroid(target, port) {
|
|
4264
4545
|
await target.adb.run(["reverse", `tcp:${port}`, `tcp:${port}`]);
|
|
4265
4546
|
}
|
|
4266
4547
|
async function readExpoGo(target) {
|
|
4267
4548
|
try {
|
|
4268
|
-
return await readAndroidUi(target,
|
|
4549
|
+
return await readAndroidUi(target, EXPO_GO);
|
|
4269
4550
|
} catch (error) {
|
|
4270
4551
|
if (error instanceof LoupeError && error.code === "not_idle") {
|
|
4271
4552
|
return "not_idle";
|
|
@@ -4282,7 +4563,7 @@ async function probeRouteInExpoGo(target) {
|
|
|
4282
4563
|
}
|
|
4283
4564
|
async function showInExpoGo(target, { link, route, direction, timeout, openAgain = OPEN_AGAIN_MS }) {
|
|
4284
4565
|
const start = Date.now();
|
|
4285
|
-
const opened = await openUrlAndroid(target, link,
|
|
4566
|
+
const opened = await openUrlAndroid(target, link, EXPO_GO);
|
|
4286
4567
|
let opens = 1;
|
|
4287
4568
|
let openedAt = start;
|
|
4288
4569
|
const reopens = [];
|
|
@@ -4292,14 +4573,14 @@ async function showInExpoGo(target, { link, route, direction, timeout, openAgain
|
|
|
4292
4573
|
while (Date.now() - start < timeout) {
|
|
4293
4574
|
throwIfCancelled(target.signal);
|
|
4294
4575
|
const { focus } = await readWindowDisplay(target);
|
|
4295
|
-
const inExperience = isAppWindow(focus,
|
|
4576
|
+
const inExperience = isAppWindow(focus, EXPO_GO) && !focus?.includes("LauncherActivity");
|
|
4296
4577
|
let appShows = false;
|
|
4297
4578
|
if (!inExperience) {
|
|
4298
4579
|
notIdle = false;
|
|
4299
4580
|
if (notRespondingPackage(focus) !== void 0) {
|
|
4300
|
-
await readInFront(target,
|
|
4581
|
+
await readInFront(target, EXPO_GO);
|
|
4301
4582
|
}
|
|
4302
|
-
last = isAppWindow(focus,
|
|
4583
|
+
last = isAppWindow(focus, EXPO_GO) ? "Expo Go's home screen" : target.kind === "device" ? "another window in front" : `${focus ?? "no window"} in front`;
|
|
4303
4584
|
} else {
|
|
4304
4585
|
const read = await readExpoGo(target);
|
|
4305
4586
|
notIdle = read === "not_idle";
|
|
@@ -4313,12 +4594,12 @@ async function showInExpoGo(target, { link, route, direction, timeout, openAgain
|
|
|
4313
4594
|
CLOSE_BUTTON[screen],
|
|
4314
4595
|
ui.display.size
|
|
4315
4596
|
);
|
|
4316
|
-
await tapAndroid(target, point,
|
|
4597
|
+
await tapAndroid(target, point, EXPO_GO);
|
|
4317
4598
|
closed.push(screen);
|
|
4318
4599
|
last = `Expo Go's ${screen === "onboarding" ? "onboarding sheet" : "developer menu"}`;
|
|
4319
4600
|
} else if (screen === "loading") {
|
|
4320
4601
|
last = "Expo Go's loading screen";
|
|
4321
|
-
} else if (!ui.probe?.report && !hasAppContent(ui.nodes)) {
|
|
4602
|
+
} else if (!ui.probe?.report && !hasAppContent(ui.nodes, "android")) {
|
|
4322
4603
|
last = "a screen with no text, label or touch yet";
|
|
4323
4604
|
} else if (!ui.probe?.report) {
|
|
4324
4605
|
appShows = true;
|
|
@@ -4347,7 +4628,7 @@ async function showInExpoGo(target, { link, route, direction, timeout, openAgain
|
|
|
4347
4628
|
}
|
|
4348
4629
|
const stuck = !inExperience || appShows;
|
|
4349
4630
|
if (stuck && Date.now() - openedAt >= openAgain) {
|
|
4350
|
-
await openUrlAndroid(target, link,
|
|
4631
|
+
await openUrlAndroid(target, link, EXPO_GO);
|
|
4351
4632
|
opens += 1;
|
|
4352
4633
|
reopens.push(last);
|
|
4353
4634
|
openedAt = Date.now();
|
|
@@ -4368,10 +4649,10 @@ async function showInExpoGo(target, { link, route, direction, timeout, openAgain
|
|
|
4368
4649
|
async function stillAppInExpoGo(target, timeout) {
|
|
4369
4650
|
await waitStillInExpoGo(target, timeout);
|
|
4370
4651
|
const again = treeOf2(await readExpoGo(target));
|
|
4371
|
-
return again !== void 0 && expoGoScreenOf(again.nodes) === void 0 && !again.probe?.report && hasAppContent(again.nodes);
|
|
4652
|
+
return again !== void 0 && expoGoScreenOf(again.nodes) === void 0 && !again.probe?.report && hasAppContent(again.nodes, "android");
|
|
4372
4653
|
}
|
|
4373
4654
|
async function waitStillInExpoGo(target, timeout) {
|
|
4374
|
-
const still = await waitStillAndroid(target,
|
|
4655
|
+
const still = await waitStillAndroid(target, EXPO_GO, {
|
|
4375
4656
|
timeout,
|
|
4376
4657
|
interval: READ_INTERVAL
|
|
4377
4658
|
});
|
|
@@ -4386,11 +4667,11 @@ async function waitStillInExpoGo(target, timeout) {
|
|
|
4386
4667
|
// src/expo/metro.ts
|
|
4387
4668
|
import { createHash } from "crypto";
|
|
4388
4669
|
import { setTimeout as sleep8 } from "timers/promises";
|
|
4389
|
-
import { z as
|
|
4670
|
+
import { z as z20 } from "zod";
|
|
4390
4671
|
var DEFAULT_PORT = 8081;
|
|
4391
4672
|
var DEFAULT_BUNDLE_TIMEOUT = 3e5;
|
|
4392
4673
|
var REQUEST_TIMEOUT = 1e4;
|
|
4393
|
-
var portField =
|
|
4674
|
+
var portField = z20.number().int().min(1).max(65535).optional().describe(
|
|
4394
4675
|
`The port of Metro on this machine (npx expo start). ${DEFAULT_PORT} by default.`
|
|
4395
4676
|
);
|
|
4396
4677
|
var metroBase = (port) => `http://127.0.0.1:${port}`;
|
|
@@ -4398,22 +4679,22 @@ var MANIFEST_HEADERS = {
|
|
|
4398
4679
|
"expo-platform": "android",
|
|
4399
4680
|
accept: "application/expo+json,application/json"
|
|
4400
4681
|
};
|
|
4401
|
-
var manifestSchema =
|
|
4402
|
-
launchAsset:
|
|
4403
|
-
extra:
|
|
4404
|
-
expoClient:
|
|
4405
|
-
name:
|
|
4406
|
-
slug:
|
|
4407
|
-
sdkVersion:
|
|
4682
|
+
var manifestSchema = z20.object({
|
|
4683
|
+
launchAsset: z20.object({ url: z20.string() }),
|
|
4684
|
+
extra: z20.object({
|
|
4685
|
+
expoClient: z20.object({
|
|
4686
|
+
name: z20.string().optional(),
|
|
4687
|
+
slug: z20.string().optional(),
|
|
4688
|
+
sdkVersion: z20.string().optional(),
|
|
4408
4689
|
// Read with type checks in `readExpoApp`: Expo CLI sends
|
|
4409
4690
|
// `_internal.dynamicConfigPath` as `{}` when the app has no
|
|
4410
4691
|
// dynamic config, and a field of another type must not drop the
|
|
4411
4692
|
// whole manifest.
|
|
4412
|
-
extra:
|
|
4413
|
-
_internal:
|
|
4693
|
+
extra: z20.unknown().optional(),
|
|
4694
|
+
_internal: z20.unknown().optional()
|
|
4414
4695
|
}).optional(),
|
|
4415
|
-
expoGo:
|
|
4416
|
-
developer:
|
|
4696
|
+
expoGo: z20.object({
|
|
4697
|
+
developer: z20.object({ projectRoot: z20.string().optional() }).optional()
|
|
4417
4698
|
}).optional()
|
|
4418
4699
|
}).optional()
|
|
4419
4700
|
});
|
|
@@ -4582,34 +4863,34 @@ async function warmExpo(context, { port = DEFAULT_PORT, timeout = DEFAULT_BUNDLE
|
|
|
4582
4863
|
// src/commands/expo-open.ts
|
|
4583
4864
|
var DEFAULT_SHOW_TIMEOUT = 12e4;
|
|
4584
4865
|
var STEPS = 5;
|
|
4585
|
-
var showTimeoutField =
|
|
4866
|
+
var showTimeoutField = z21.number().int().min(1e3).max(6e5).optional().describe(
|
|
4586
4867
|
`How long to wait for the app after the open, in ms. ${DEFAULT_SHOW_TIMEOUT} by default.`
|
|
4587
4868
|
);
|
|
4588
|
-
var shownSchema =
|
|
4589
|
-
link:
|
|
4590
|
-
app:
|
|
4591
|
-
name:
|
|
4592
|
-
slug:
|
|
4593
|
-
sdkVersion:
|
|
4869
|
+
var shownSchema = z21.object({
|
|
4870
|
+
link: z21.string().describe("The link that loupe opened in Expo Go."),
|
|
4871
|
+
app: z21.object({
|
|
4872
|
+
name: z21.string().optional(),
|
|
4873
|
+
slug: z21.string().optional(),
|
|
4874
|
+
sdkVersion: z21.string().optional()
|
|
4594
4875
|
}),
|
|
4595
|
-
expoGo:
|
|
4596
|
-
launchState:
|
|
4597
|
-
opens:
|
|
4876
|
+
expoGo: z21.string().optional().describe("The version of Expo Go on the device."),
|
|
4877
|
+
launchState: z21.string().optional().describe("cold, warm or hot, as Android measured the first open."),
|
|
4878
|
+
opens: z21.number().describe(
|
|
4598
4879
|
"How many times loupe opened the link. Expo Go can lose a link while it starts."
|
|
4599
4880
|
),
|
|
4600
|
-
reopens:
|
|
4881
|
+
reopens: z21.array(z21.string()).describe(
|
|
4601
4882
|
"What the last read saw before each time that loupe opened the link again."
|
|
4602
4883
|
),
|
|
4603
|
-
closed:
|
|
4884
|
+
closed: z21.array(z21.enum(["onboarding", "dev-menu"])).describe(
|
|
4604
4885
|
"The Expo Go sheets that loupe closed: the onboarding sheet of the first open, and the developer menu."
|
|
4605
4886
|
),
|
|
4606
|
-
ms:
|
|
4607
|
-
route:
|
|
4608
|
-
direction:
|
|
4609
|
-
probe:
|
|
4887
|
+
ms: z21.number().describe("From the open until the app showed, in ms."),
|
|
4888
|
+
route: z21.string().optional().describe("The route that the app's probe shows."),
|
|
4889
|
+
direction: z21.enum(["ltr", "rtl"]).optional().describe("The layout direction that the app's probe shows."),
|
|
4890
|
+
probe: z21.boolean().describe(
|
|
4610
4891
|
"True when the app has the probe. With no probe, loupe waited until the screen had text, a label or a touch, kept still, and then still showed no Expo Go screen."
|
|
4611
4892
|
),
|
|
4612
|
-
warnings:
|
|
4893
|
+
warnings: z21.array(z21.string())
|
|
4613
4894
|
});
|
|
4614
4895
|
async function showApp(context, {
|
|
4615
4896
|
route,
|
|
@@ -4617,7 +4898,7 @@ async function showApp(context, {
|
|
|
4617
4898
|
timeout = DEFAULT_SHOW_TIMEOUT,
|
|
4618
4899
|
device
|
|
4619
4900
|
}, { reload = false, prepare } = {}) {
|
|
4620
|
-
const target = await
|
|
4901
|
+
const target = await selectAndroidOnly(context, device);
|
|
4621
4902
|
const expoGo = await readExpoGoVersion(target);
|
|
4622
4903
|
const warmed = await warmExpo(context, { port }, STEPS);
|
|
4623
4904
|
const direction = await prepare?.();
|
|
@@ -4680,8 +4961,8 @@ function describeShown(lead, { app, opens, reopens, closed, ms, route, direction
|
|
|
4680
4961
|
var expoOpenCommand = defineCommand({
|
|
4681
4962
|
name: "expo-open",
|
|
4682
4963
|
summary: "Open the app in Expo Go on the device, at a route, and wait until it shows",
|
|
4683
|
-
input:
|
|
4684
|
-
route:
|
|
4964
|
+
input: z21.object({
|
|
4965
|
+
route: z21.string().optional().describe(
|
|
4685
4966
|
"The route to open, for example /settings. The root by default. When the app has the probe, loupe waits until the probe shows this route."
|
|
4686
4967
|
),
|
|
4687
4968
|
port: portField,
|
|
@@ -4698,12 +4979,12 @@ var expoOpenCommand = defineCommand({
|
|
|
4698
4979
|
});
|
|
4699
4980
|
|
|
4700
4981
|
// src/commands/expo-reload.ts
|
|
4701
|
-
import { z as
|
|
4982
|
+
import { z as z22 } from "zod";
|
|
4702
4983
|
var expoReloadCommand = defineCommand({
|
|
4703
4984
|
name: "expo-reload",
|
|
4704
4985
|
summary: "Stop Expo Go and open the app again, so its JavaScript starts again, and wait until it shows",
|
|
4705
|
-
input:
|
|
4706
|
-
route:
|
|
4986
|
+
input: z22.object({
|
|
4987
|
+
route: z22.string().optional().describe(
|
|
4707
4988
|
"The route to open after the stop, for example /settings. By default the route that the probe shows before the stop, else the root."
|
|
4708
4989
|
),
|
|
4709
4990
|
port: portField,
|
|
@@ -4720,15 +5001,15 @@ var expoReloadCommand = defineCommand({
|
|
|
4720
5001
|
});
|
|
4721
5002
|
|
|
4722
5003
|
// src/commands/expo-rtl.ts
|
|
4723
|
-
import { z as
|
|
5004
|
+
import { z as z24 } from "zod";
|
|
4724
5005
|
|
|
4725
5006
|
// src/expo/app-config.ts
|
|
4726
5007
|
import { mkdir as mkdir2, readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
4727
5008
|
import path5 from "path";
|
|
4728
|
-
import { z as
|
|
5009
|
+
import { z as z23 } from "zod";
|
|
4729
5010
|
var KEYS2 = ["supportsRTL", "forcesRTL"];
|
|
4730
5011
|
var RECORD_PATH = path5.join(".expo", "loupe-rtl.json");
|
|
4731
|
-
var recordSchema =
|
|
5012
|
+
var recordSchema = z23.object({ original: z23.string(), written: z23.string() });
|
|
4732
5013
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4733
5014
|
function parseAppJson(text, file) {
|
|
4734
5015
|
let json;
|
|
@@ -4897,11 +5178,11 @@ function directionOf({
|
|
|
4897
5178
|
var expoRtlCommand = defineCommand({
|
|
4898
5179
|
name: "expo-rtl",
|
|
4899
5180
|
summary: "Turn RTL on or off in the app.json of the app in Expo Go, then open the app again in that direction",
|
|
4900
|
-
input:
|
|
4901
|
-
rtl:
|
|
5181
|
+
input: z24.object({
|
|
5182
|
+
rtl: z24.enum(["on", "off"]).describe(
|
|
4902
5183
|
`on: supportsRTL and forcesRTL in the extra of app.json; loupe keeps app.json as it was in ${RECORD_PATH}. off: app.json as it was before on.`
|
|
4903
5184
|
),
|
|
4904
|
-
route:
|
|
5185
|
+
route: z24.string().optional().describe(
|
|
4905
5186
|
"The route to open after the change, for example /settings. By default the route that the probe shows before it, else the root."
|
|
4906
5187
|
),
|
|
4907
5188
|
port: portField,
|
|
@@ -4910,9 +5191,9 @@ var expoRtlCommand = defineCommand({
|
|
|
4910
5191
|
}),
|
|
4911
5192
|
positionals: ["rtl", "route"],
|
|
4912
5193
|
output: shownSchema.extend({
|
|
4913
|
-
rtl:
|
|
4914
|
-
file:
|
|
4915
|
-
changed:
|
|
5194
|
+
rtl: z24.enum(["on", "off"]),
|
|
5195
|
+
file: z24.string().describe("The app.json of the app, as an absolute path."),
|
|
5196
|
+
changed: z24.boolean().describe("True when loupe wrote app.json.")
|
|
4916
5197
|
}),
|
|
4917
5198
|
run: async ({ rtl, ...input }, context) => {
|
|
4918
5199
|
const port = input.port ?? DEFAULT_PORT;
|
|
@@ -4955,37 +5236,37 @@ var expoRtlCommand = defineCommand({
|
|
|
4955
5236
|
});
|
|
4956
5237
|
|
|
4957
5238
|
// src/commands/expo-warm.ts
|
|
4958
|
-
import { z as
|
|
5239
|
+
import { z as z25 } from "zod";
|
|
4959
5240
|
var expoWarmCommand = defineCommand({
|
|
4960
5241
|
name: "expo-warm",
|
|
4961
5242
|
summary: "Ask Metro for the app and its bundle, so that the first open in Expo Go is fast, and give the hash of the bundle",
|
|
4962
5243
|
readOnly: true,
|
|
4963
|
-
input:
|
|
5244
|
+
input: z25.object({
|
|
4964
5245
|
port: portField,
|
|
4965
|
-
timeout:
|
|
5246
|
+
timeout: z25.number().int().min(1e3).max(6e5).optional().describe(
|
|
4966
5247
|
`How long to wait for the bundle at most, in ms. ${DEFAULT_BUNDLE_TIMEOUT} by default: a cold bundle of a large app can take minutes.`
|
|
4967
5248
|
)
|
|
4968
5249
|
}),
|
|
4969
|
-
output:
|
|
4970
|
-
server:
|
|
4971
|
-
link:
|
|
5250
|
+
output: z25.object({
|
|
5251
|
+
server: z25.string().describe("The Metro server that loupe asked."),
|
|
5252
|
+
link: z25.string().describe(
|
|
4972
5253
|
"The link that opens the app in Expo Go on Android, after adb reverse of the port."
|
|
4973
5254
|
),
|
|
4974
|
-
app:
|
|
4975
|
-
name:
|
|
4976
|
-
slug:
|
|
4977
|
-
sdkVersion:
|
|
5255
|
+
app: z25.object({
|
|
5256
|
+
name: z25.string().optional(),
|
|
5257
|
+
slug: z25.string().optional(),
|
|
5258
|
+
sdkVersion: z25.string().optional().describe(
|
|
4978
5259
|
"The Expo SDK of the app, for example 58.0.0. Expo Go must have the same major version."
|
|
4979
5260
|
)
|
|
4980
5261
|
}),
|
|
4981
|
-
projectRoot:
|
|
4982
|
-
bundle:
|
|
4983
|
-
path:
|
|
4984
|
-
ms:
|
|
5262
|
+
projectRoot: z25.string().optional().describe("The folder of the app on this machine, as Metro gives it."),
|
|
5263
|
+
bundle: z25.object({
|
|
5264
|
+
path: z25.string().describe("The path and query of the launch bundle on Metro."),
|
|
5265
|
+
ms: z25.number().describe(
|
|
4985
5266
|
"How long the bundle took, in ms: seconds when cold, under a second when warm."
|
|
4986
5267
|
),
|
|
4987
|
-
bytes:
|
|
4988
|
-
sha256:
|
|
5268
|
+
bytes: z25.number(),
|
|
5269
|
+
sha256: z25.string().describe(
|
|
4989
5270
|
"The SHA-256 of the bundle. After an edit of the app's code, the same hash means that Metro didn't see the edit."
|
|
4990
5271
|
)
|
|
4991
5272
|
})
|
|
@@ -4999,11 +5280,11 @@ var expoWarmCommand = defineCommand({
|
|
|
4999
5280
|
});
|
|
5000
5281
|
|
|
5001
5282
|
// src/commands/hold.ts
|
|
5002
|
-
import { z as
|
|
5283
|
+
import { z as z26 } from "zod";
|
|
5003
5284
|
var holdCommand = defineCommand({
|
|
5004
5285
|
name: "hold",
|
|
5005
5286
|
summary: "Touch one point or element and hold it (a long press), by text, label or id",
|
|
5006
|
-
input:
|
|
5287
|
+
input: z26.object({
|
|
5007
5288
|
x: coordinateField("x").optional(),
|
|
5008
5289
|
y: coordinateField("y").optional(),
|
|
5009
5290
|
...selectorFields,
|
|
@@ -5015,7 +5296,7 @@ var holdCommand = defineCommand({
|
|
|
5015
5296
|
positionals: ["x", "y"],
|
|
5016
5297
|
output: aimedTouchSchema.extend({ waited: waitedSchema.optional() }),
|
|
5017
5298
|
run: async ({ duration, app, device, waitStill, waitText, waitTimeout, ...input }, context) => {
|
|
5018
|
-
const target = await
|
|
5299
|
+
const target = await selectAndroidOnly(context, device);
|
|
5019
5300
|
const { point, element } = await aimAndroid(target, targetOf(input), app);
|
|
5020
5301
|
const touch2 = await holdAndroid(target, point, duration, app);
|
|
5021
5302
|
const waited = await waitAfterAction(
|
|
@@ -5033,19 +5314,19 @@ var holdCommand = defineCommand({
|
|
|
5033
5314
|
});
|
|
5034
5315
|
|
|
5035
5316
|
// src/commands/insets.ts
|
|
5036
|
-
import { z as
|
|
5317
|
+
import { z as z27 } from "zod";
|
|
5037
5318
|
var insetsCommand = defineCommand({
|
|
5038
5319
|
name: "insets",
|
|
5039
5320
|
summary: "Read the safe-area insets and the cutout of the current orientation",
|
|
5040
5321
|
readOnly: true,
|
|
5041
|
-
input:
|
|
5322
|
+
input: z27.object({
|
|
5042
5323
|
app: appField.describe(
|
|
5043
5324
|
"The package of the app under test, for example host.exp.exponent for Expo Go. loupe then reads the app's probe only while that app is in front. On a real device, loupe reads the probe only with this option."
|
|
5044
5325
|
),
|
|
5045
5326
|
device: deviceField
|
|
5046
5327
|
}),
|
|
5047
5328
|
output: insetsReadingSchema,
|
|
5048
|
-
run: async ({ app, device }, context) => readAndroidInsets(await
|
|
5329
|
+
run: async ({ app, device }, context) => readAndroidInsets(await selectAndroidOnly(context, device), app),
|
|
5049
5330
|
format: (reading) => [
|
|
5050
5331
|
describeDisplay(reading),
|
|
5051
5332
|
`Safe area, from ${reading.source === "probe" ? "the app's probe" : "dumpsys"}: ${describeInsets(reading.safeArea)}`,
|
|
@@ -5056,7 +5337,7 @@ var insetsCommand = defineCommand({
|
|
|
5056
5337
|
});
|
|
5057
5338
|
|
|
5058
5339
|
// src/commands/key.ts
|
|
5059
|
-
import { z as
|
|
5340
|
+
import { z as z28 } from "zod";
|
|
5060
5341
|
|
|
5061
5342
|
// src/core/keys.ts
|
|
5062
5343
|
var KEY_NAMES = [
|
|
@@ -5131,19 +5412,19 @@ async function pressAndroid(target, key2, app) {
|
|
|
5131
5412
|
var keyCommand = defineCommand({
|
|
5132
5413
|
name: "key",
|
|
5133
5414
|
summary: "Press one key, for example back, home or enter",
|
|
5134
|
-
input:
|
|
5135
|
-
key:
|
|
5415
|
+
input: z28.object({
|
|
5416
|
+
key: z28.enum(KEY_NAMES),
|
|
5136
5417
|
...waitFields,
|
|
5137
5418
|
app: appField,
|
|
5138
5419
|
device: deviceField
|
|
5139
5420
|
}),
|
|
5140
5421
|
positionals: ["key"],
|
|
5141
|
-
output:
|
|
5142
|
-
key:
|
|
5422
|
+
output: z28.object({
|
|
5423
|
+
key: z28.enum(KEY_NAMES),
|
|
5143
5424
|
waited: waitedSchema.optional()
|
|
5144
5425
|
}),
|
|
5145
5426
|
run: async ({ key: key2, app, device, ...wait }, context) => {
|
|
5146
|
-
const target = await
|
|
5427
|
+
const target = await selectAndroidOnly(context, device);
|
|
5147
5428
|
const pressed = await pressAndroid(target, key2, app);
|
|
5148
5429
|
const waited = await waitAfterAction(target, app, wait, "key");
|
|
5149
5430
|
return { ...pressed, waited };
|
|
@@ -5152,10 +5433,10 @@ var keyCommand = defineCommand({
|
|
|
5152
5433
|
});
|
|
5153
5434
|
|
|
5154
5435
|
// src/commands/measure.ts
|
|
5155
|
-
import { z as
|
|
5436
|
+
import { z as z30 } from "zod";
|
|
5156
5437
|
|
|
5157
5438
|
// src/core/measure.ts
|
|
5158
|
-
import { z as
|
|
5439
|
+
import { z as z29 } from "zod";
|
|
5159
5440
|
function measureTargetOf(input) {
|
|
5160
5441
|
const targets = [
|
|
5161
5442
|
...input.row === void 0 ? [] : [{ line: { axis: "row", at: input.row } }],
|
|
@@ -5235,12 +5516,12 @@ function joinShortRuns(runs, minLength) {
|
|
|
5235
5516
|
flush();
|
|
5236
5517
|
return out;
|
|
5237
5518
|
}
|
|
5238
|
-
var runSchema =
|
|
5239
|
-
from:
|
|
5240
|
-
to:
|
|
5241
|
-
length:
|
|
5242
|
-
pixels:
|
|
5243
|
-
colour:
|
|
5519
|
+
var runSchema = z29.object({
|
|
5520
|
+
from: z29.number().describe("The start along the line, in dp."),
|
|
5521
|
+
to: z29.number().describe("The end along the line, in dp."),
|
|
5522
|
+
length: z29.number().describe("In dp."),
|
|
5523
|
+
pixels: z29.object({ from: z29.number(), to: z29.number() }).describe("The same run in px: from the first pixel to past the last."),
|
|
5524
|
+
colour: z29.string().optional().describe(
|
|
5244
5525
|
"The mean colour: #rrggbb, or #rrggbbaa when not opaque. Left out for a mix of short runs, for example text."
|
|
5245
5526
|
)
|
|
5246
5527
|
});
|
|
@@ -5253,20 +5534,20 @@ function runInDp(run, scale) {
|
|
|
5253
5534
|
colour: run.colour
|
|
5254
5535
|
};
|
|
5255
5536
|
}
|
|
5256
|
-
var lineSchema =
|
|
5257
|
-
axis:
|
|
5258
|
-
at:
|
|
5259
|
-
pixel:
|
|
5260
|
-
runs:
|
|
5537
|
+
var lineSchema = z29.object({
|
|
5538
|
+
axis: z29.enum(["row", "column"]),
|
|
5539
|
+
at: z29.number().describe("The row (y) or the column (x) in dp, at the whole pixel used."),
|
|
5540
|
+
pixel: z29.number().describe("The row or the column in px."),
|
|
5541
|
+
runs: z29.array(runSchema)
|
|
5261
5542
|
});
|
|
5262
|
-
var elementMeasureSchema =
|
|
5543
|
+
var elementMeasureSchema = z29.object({
|
|
5263
5544
|
toScreen: insetsSchema.describe(
|
|
5264
5545
|
"From each edge of the screen to the element, in dp."
|
|
5265
5546
|
),
|
|
5266
5547
|
toSafeArea: insetsSchema.describe(
|
|
5267
5548
|
"From each edge of the safe area to the element, in dp. Negative: the element reaches into the inset by that much."
|
|
5268
5549
|
),
|
|
5269
|
-
offCentre:
|
|
5550
|
+
offCentre: z29.object({
|
|
5270
5551
|
screen: pointSchema,
|
|
5271
5552
|
safeArea: pointSchema
|
|
5272
5553
|
}).describe(
|
|
@@ -5308,14 +5589,14 @@ function describeRun({ from, to, length, colour }) {
|
|
|
5308
5589
|
// src/commands/measure.ts
|
|
5309
5590
|
var DEFAULT_TOLERANCE = 8;
|
|
5310
5591
|
var DEFAULT_MIN_LENGTH = 1;
|
|
5311
|
-
var lineField = (axis, coordinate) =>
|
|
5592
|
+
var lineField = (axis, coordinate) => z30.number().min(0).optional().describe(
|
|
5312
5593
|
`Measure the colour runs along this ${axis} of a new screenshot: ${coordinate} in dp, from the top-left corner.`
|
|
5313
5594
|
);
|
|
5314
5595
|
var measureCommand = defineCommand({
|
|
5315
5596
|
name: "measure",
|
|
5316
5597
|
summary: "Measure the colour runs along a row or a column, or where an element sits on the screen and in the safe area",
|
|
5317
5598
|
readOnly: true,
|
|
5318
|
-
input:
|
|
5599
|
+
input: z30.object({
|
|
5319
5600
|
row: lineField("row", "y"),
|
|
5320
5601
|
column: lineField("column", "x"),
|
|
5321
5602
|
text: selectorFields.text.describe(
|
|
@@ -5327,10 +5608,10 @@ var measureCommand = defineCommand({
|
|
|
5327
5608
|
id: selectorFields.id.describe(
|
|
5328
5609
|
'Measure the element with this id: the resource-id on Android, or the part after ":id/".'
|
|
5329
5610
|
),
|
|
5330
|
-
tolerance:
|
|
5611
|
+
tolerance: z30.number().int().min(0).max(255).optional().describe(
|
|
5331
5612
|
`For a row or a column: a pixel stays in the run while no colour channel differs from the run's first pixel by more than this (0\u2013255). ${DEFAULT_TOLERANCE} by default.`
|
|
5332
5613
|
),
|
|
5333
|
-
minLength:
|
|
5614
|
+
minLength: z30.number().min(0).optional().describe(
|
|
5334
5615
|
`For a row or a column, in dp: two or more runs in a row that are each shorter than this become one run with no colour, for example text. ${DEFAULT_MIN_LENGTH} by default; 0 keeps each run.`
|
|
5335
5616
|
),
|
|
5336
5617
|
app: appField,
|
|
@@ -5341,14 +5622,14 @@ var measureCommand = defineCommand({
|
|
|
5341
5622
|
"The colour runs, from the left or the top. They cover the whole line."
|
|
5342
5623
|
),
|
|
5343
5624
|
element: elementSchema.extend(elementMeasureSchema.shape).extend({
|
|
5344
|
-
safeAreaSource:
|
|
5625
|
+
safeAreaSource: z30.enum(["probe", "dumpsys"]).describe("Where the safe area comes from, as in `insets`.")
|
|
5345
5626
|
}).optional(),
|
|
5346
|
-
warnings:
|
|
5627
|
+
warnings: z30.array(z30.string())
|
|
5347
5628
|
}),
|
|
5348
5629
|
run: async (input, context) => {
|
|
5349
5630
|
const { tolerance: tolerance2 = DEFAULT_TOLERANCE, minLength = DEFAULT_MIN_LENGTH } = input;
|
|
5350
5631
|
const measured = measureTargetOf(input);
|
|
5351
|
-
const target = await
|
|
5632
|
+
const target = await selectAndroidOnly(context, input.device);
|
|
5352
5633
|
if (measured.line) {
|
|
5353
5634
|
const { axis, at } = measured.line;
|
|
5354
5635
|
const { png, display } = await captureAndroid(target, input.app);
|
|
@@ -5419,12 +5700,12 @@ var measureCommand = defineCommand({
|
|
|
5419
5700
|
});
|
|
5420
5701
|
|
|
5421
5702
|
// src/commands/open-url.ts
|
|
5422
|
-
import { z as
|
|
5703
|
+
import { z as z31 } from "zod";
|
|
5423
5704
|
var openUrlCommand = defineCommand({
|
|
5424
5705
|
name: "open-url",
|
|
5425
5706
|
summary: "Open a link (a deep link or a web page), and wait until it opens",
|
|
5426
|
-
input:
|
|
5427
|
-
url:
|
|
5707
|
+
input: z31.object({
|
|
5708
|
+
url: z31.string().regex(
|
|
5428
5709
|
/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/,
|
|
5429
5710
|
"A URL starts with a scheme, for example https: or exp:, and has no spaces."
|
|
5430
5711
|
),
|
|
@@ -5435,15 +5716,15 @@ var openUrlCommand = defineCommand({
|
|
|
5435
5716
|
device: deviceField
|
|
5436
5717
|
}),
|
|
5437
5718
|
positionals: ["url"],
|
|
5438
|
-
output:
|
|
5439
|
-
url:
|
|
5440
|
-
activity:
|
|
5441
|
-
launchState:
|
|
5442
|
-
totalTime:
|
|
5719
|
+
output: z31.object({
|
|
5720
|
+
url: z31.string(),
|
|
5721
|
+
activity: z31.string().optional().describe("The activity that opened the link: package/activity."),
|
|
5722
|
+
launchState: z31.string().optional().describe("cold, warm or hot."),
|
|
5723
|
+
totalTime: z31.number().optional().describe("Milliseconds, as Android measured the start."),
|
|
5443
5724
|
waited: waitedSchema.optional()
|
|
5444
5725
|
}),
|
|
5445
5726
|
run: async ({ url, app, device, ...wait }, context) => {
|
|
5446
|
-
const target = await
|
|
5727
|
+
const target = await selectAndroidOnly(context, device);
|
|
5447
5728
|
const opened = await openUrlAndroid(target, url, app);
|
|
5448
5729
|
const waited = await waitAfterAction(target, app, wait, "open-url");
|
|
5449
5730
|
return { ...opened, waited };
|
|
@@ -5459,21 +5740,21 @@ var openUrlCommand = defineCommand({
|
|
|
5459
5740
|
});
|
|
5460
5741
|
|
|
5461
5742
|
// src/commands/pinch.ts
|
|
5462
|
-
import { z as
|
|
5743
|
+
import { z as z33 } from "zod";
|
|
5463
5744
|
|
|
5464
5745
|
// src/core/pinch.ts
|
|
5465
|
-
import { z as
|
|
5746
|
+
import { z as z32 } from "zod";
|
|
5466
5747
|
var pinchFields = {
|
|
5467
|
-
scale:
|
|
5748
|
+
scale: z32.number().positive().default(1).describe(
|
|
5468
5749
|
"The span between the fingers at the end \xF7 the span at the start. Above 1 spreads them (zoom in); below 1 brings them together (zoom out)."
|
|
5469
5750
|
),
|
|
5470
|
-
distance:
|
|
5751
|
+
distance: z32.number().positive().default(200).describe(
|
|
5471
5752
|
"The smaller span between the fingers, in dp: where a spread starts, or where a pinch ends. Android ignores a span under about 170 dp."
|
|
5472
5753
|
),
|
|
5473
|
-
angle:
|
|
5754
|
+
angle: z32.number().min(0).max(180).optional().describe(
|
|
5474
5755
|
"The line between the fingers at the start, in degrees clockwise from across the screen: 0 is across, 90 is down. Default: along the longer side of the screen."
|
|
5475
5756
|
),
|
|
5476
|
-
turn:
|
|
5757
|
+
turn: z32.number().default(0).describe(
|
|
5477
5758
|
"Degrees to turn the fingers around the centre during the gesture, clockwise. A negative value turns them the other way (on the CLI: --turn=-90)."
|
|
5478
5759
|
)
|
|
5479
5760
|
};
|
|
@@ -5516,21 +5797,21 @@ function planPinch(shape, screen, steps) {
|
|
|
5516
5797
|
});
|
|
5517
5798
|
return { angle, span: { from, to }, steps: plan };
|
|
5518
5799
|
}
|
|
5519
|
-
var pinchSchema =
|
|
5520
|
-
orientation:
|
|
5800
|
+
var pinchSchema = z32.object({
|
|
5801
|
+
orientation: z32.enum(ORIENTATIONS),
|
|
5521
5802
|
centre: pointSchema.describe("The centre of the pinch, in dp."),
|
|
5522
5803
|
element: elementSchema.optional().describe("The element that loupe pinched, when the input named one."),
|
|
5523
|
-
fingers:
|
|
5524
|
-
span:
|
|
5804
|
+
fingers: z32.array(z32.object({ from: pointSchema, to: pointSchema })).describe("Where each finger touched and where it lifted, in dp."),
|
|
5805
|
+
span: z32.object({ from: z32.number(), to: z32.number() }).describe(
|
|
5525
5806
|
"The span between the fingers at the start and at the end, in dp."
|
|
5526
5807
|
),
|
|
5527
|
-
scale:
|
|
5528
|
-
angle:
|
|
5808
|
+
scale: z32.number(),
|
|
5809
|
+
angle: z32.number().describe(
|
|
5529
5810
|
"The line between the fingers at the start, in degrees clockwise from across the screen."
|
|
5530
5811
|
),
|
|
5531
|
-
turn:
|
|
5532
|
-
duration:
|
|
5533
|
-
moveTime:
|
|
5812
|
+
turn: z32.number().describe("In degrees, clockwise."),
|
|
5813
|
+
duration: z32.number().describe("In milliseconds."),
|
|
5814
|
+
moveTime: z32.number().describe("Milliseconds that the move took, measured on the host.")
|
|
5534
5815
|
});
|
|
5535
5816
|
function describePinch(pinch) {
|
|
5536
5817
|
const { centre, element, span, turn, orientation, moveTime } = pinch;
|
|
@@ -5577,7 +5858,7 @@ async function pinchAndroid(target, centre, options, app) {
|
|
|
5577
5858
|
var pinchCommand = defineCommand({
|
|
5578
5859
|
name: "pinch",
|
|
5579
5860
|
summary: "Pinch or spread two fingers around a point or an element, and turn them (emulator only)",
|
|
5580
|
-
input:
|
|
5861
|
+
input: z33.object({
|
|
5581
5862
|
x: coordinateField("x").optional(),
|
|
5582
5863
|
y: coordinateField("y").optional(),
|
|
5583
5864
|
...selectorFields,
|
|
@@ -5605,7 +5886,7 @@ var pinchCommand = defineCommand({
|
|
|
5605
5886
|
waitTimeout,
|
|
5606
5887
|
...shape
|
|
5607
5888
|
}, context) => {
|
|
5608
|
-
const target = await
|
|
5889
|
+
const target = await selectAndroidOnly(context, device);
|
|
5609
5890
|
const { point, element } = await aimAndroid(
|
|
5610
5891
|
target,
|
|
5611
5892
|
targetOf({ x, y, text, label: label2, id }),
|
|
@@ -5624,38 +5905,38 @@ var pinchCommand = defineCommand({
|
|
|
5624
5905
|
});
|
|
5625
5906
|
|
|
5626
5907
|
// src/commands/rotate.ts
|
|
5627
|
-
import { z as
|
|
5908
|
+
import { z as z34 } from "zod";
|
|
5628
5909
|
var rotateCommand = defineCommand({
|
|
5629
5910
|
name: "rotate",
|
|
5630
5911
|
summary: "Turn the screen, and wait until it has turned",
|
|
5631
|
-
input:
|
|
5632
|
-
to:
|
|
5912
|
+
input: z34.object({
|
|
5913
|
+
to: z34.enum(["portrait", "landscape-left", "landscape-right"]).describe(orientationDescription),
|
|
5633
5914
|
device: deviceField,
|
|
5634
|
-
timeout:
|
|
5915
|
+
timeout: z34.number().int().min(0).default(5e3).describe("Milliseconds to wait for the screen to turn.")
|
|
5635
5916
|
}),
|
|
5636
5917
|
positionals: ["to"],
|
|
5637
5918
|
output: displaySchema,
|
|
5638
|
-
run: async ({ to, device, timeout }, context) => rotateAndroid(await
|
|
5919
|
+
run: async ({ to, device, timeout }, context) => rotateAndroid(await selectAndroidOnly(context, device), to, { timeout }),
|
|
5639
5920
|
format: describeDisplay
|
|
5640
5921
|
});
|
|
5641
5922
|
|
|
5642
5923
|
// src/commands/screenshot.ts
|
|
5643
|
-
import { z as
|
|
5924
|
+
import { z as z35 } from "zod";
|
|
5644
5925
|
var screenshotCommand = defineCommand({
|
|
5645
5926
|
name: "screenshot",
|
|
5646
5927
|
summary: "Save the screen as a PNG file, upright in each orientation",
|
|
5647
5928
|
readOnly: true,
|
|
5648
|
-
input:
|
|
5649
|
-
out:
|
|
5929
|
+
input: z35.object({
|
|
5930
|
+
out: z35.string().min(1).describe(
|
|
5650
5931
|
"The PNG file to write. loupe makes its folder, and replaces a file that is there."
|
|
5651
5932
|
),
|
|
5652
|
-
crop:
|
|
5933
|
+
crop: z35.string().regex(
|
|
5653
5934
|
CROP_PATTERN,
|
|
5654
5935
|
"A crop is x,y,width,height in dp, for example 0,0,411,64."
|
|
5655
5936
|
).optional().describe(
|
|
5656
5937
|
"Save only this part of the screen: x,y,width,height in dp, from the top-left corner of the current orientation. The part outside the screen is left out."
|
|
5657
5938
|
),
|
|
5658
|
-
scale:
|
|
5939
|
+
scale: z35.number().gt(0).max(1).optional().describe(
|
|
5659
5940
|
"Scale the image down by this factor, for example 0.5 for half the width and half the height. A smaller file costs fewer tokens."
|
|
5660
5941
|
),
|
|
5661
5942
|
app: appField,
|
|
@@ -5663,8 +5944,8 @@ var screenshotCommand = defineCommand({
|
|
|
5663
5944
|
}),
|
|
5664
5945
|
positionals: ["out"],
|
|
5665
5946
|
output: displaySchema.extend({
|
|
5666
|
-
file:
|
|
5667
|
-
image:
|
|
5947
|
+
file: z35.string().describe("The PNG file, as an absolute path."),
|
|
5948
|
+
image: z35.object({ width: z35.number(), height: z35.number() }).describe(
|
|
5668
5949
|
"The size of the PNG file, in px: the screen, or the crop, after the scale."
|
|
5669
5950
|
),
|
|
5670
5951
|
crop: rectSchema.optional().describe(
|
|
@@ -5673,7 +5954,7 @@ var screenshotCommand = defineCommand({
|
|
|
5673
5954
|
}),
|
|
5674
5955
|
run: async ({ out, crop, scale, app, device }, context) => {
|
|
5675
5956
|
const capture = await captureAndroid(
|
|
5676
|
-
await
|
|
5957
|
+
await selectAndroidOnly(context, device),
|
|
5677
5958
|
app
|
|
5678
5959
|
);
|
|
5679
5960
|
const { pixels, display } = capture;
|
|
@@ -5712,7 +5993,7 @@ var screenshotCommand = defineCommand({
|
|
|
5712
5993
|
});
|
|
5713
5994
|
|
|
5714
5995
|
// src/commands/scroll-to.ts
|
|
5715
|
-
import { z as
|
|
5996
|
+
import { z as z36 } from "zod";
|
|
5716
5997
|
|
|
5717
5998
|
// src/core/scroll.ts
|
|
5718
5999
|
var DIRECTIONS = ["down", "up", "left", "right"];
|
|
@@ -5727,7 +6008,7 @@ function everyNode3(nodes) {
|
|
|
5727
6008
|
function area({ width, height }) {
|
|
5728
6009
|
return width * height;
|
|
5729
6010
|
}
|
|
5730
|
-
function scrollViewFor(nodes, direction, screen, id) {
|
|
6011
|
+
function scrollViewFor(nodes, direction, screen, platform, id) {
|
|
5731
6012
|
if (id !== void 0) {
|
|
5732
6013
|
const named = findNode(
|
|
5733
6014
|
nodes,
|
|
@@ -5748,7 +6029,7 @@ function scrollViewFor(nodes, direction, screen, id) {
|
|
|
5748
6029
|
(node) => node.scrollable && node.frame.width > 0 && node.frame.height > 0 && intersection(node.frame, screenRect2) !== null
|
|
5749
6030
|
);
|
|
5750
6031
|
const along = scrollers.filter(
|
|
5751
|
-
(node) => scrollAxisOf(node) === axisOf(direction)
|
|
6032
|
+
(node) => scrollAxisOf(node, platform) === axisOf(direction)
|
|
5752
6033
|
);
|
|
5753
6034
|
const candidates = along.length > 0 ? along : scrollers;
|
|
5754
6035
|
const innermost = candidates.filter((node) => {
|
|
@@ -5766,11 +6047,11 @@ function scrollStroke(frame, direction, share = SCROLL_SHARE) {
|
|
|
5766
6047
|
const along = (at) => axisOf(direction) === "y" ? { x: frame.x + frame.width / 2, y: frame.y + frame.height * at } : { x: frame.x + frame.width * at, y: frame.y + frame.height / 2 };
|
|
5767
6048
|
return direction === "down" || direction === "right" ? { from: along(start), to: along(end) } : { from: along(end), to: along(start) };
|
|
5768
6049
|
}
|
|
5769
|
-
function viewContent(nodes, frame, app) {
|
|
6050
|
+
function viewContent(nodes, frame, platform, app) {
|
|
5770
6051
|
const rows = [];
|
|
5771
6052
|
const walk = (list) => {
|
|
5772
6053
|
for (const node of list) {
|
|
5773
|
-
if (isExpoGoOverlay(node, app)) continue;
|
|
6054
|
+
if (isExpoGoOverlay(node, app, platform)) continue;
|
|
5774
6055
|
if (intersection(node.frame, frame) !== null) {
|
|
5775
6056
|
const { type, text, label: label2, id } = node;
|
|
5776
6057
|
const { x, y, width, height } = node.frame;
|
|
@@ -5816,7 +6097,13 @@ async function scrollToAndroid(target, selector, options, app) {
|
|
|
5816
6097
|
let nudged = false;
|
|
5817
6098
|
let ended = false;
|
|
5818
6099
|
const scroll = async (share) => {
|
|
5819
|
-
const next = scrollViewFor(
|
|
6100
|
+
const next = scrollViewFor(
|
|
6101
|
+
ui.nodes,
|
|
6102
|
+
direction,
|
|
6103
|
+
ui.display.size,
|
|
6104
|
+
"android",
|
|
6105
|
+
options.in
|
|
6106
|
+
);
|
|
5820
6107
|
if (!next) {
|
|
5821
6108
|
throw new LoupeError(
|
|
5822
6109
|
"element_not_found",
|
|
@@ -5824,12 +6111,12 @@ async function scrollToAndroid(target, selector, options, app) {
|
|
|
5824
6111
|
);
|
|
5825
6112
|
}
|
|
5826
6113
|
view = next;
|
|
5827
|
-
const before = viewContent(ui.nodes, next.frame, app);
|
|
6114
|
+
const before = viewContent(ui.nodes, next.frame, "android", app);
|
|
5828
6115
|
const { from, to } = scrollStroke(next.frame, direction, share);
|
|
5829
6116
|
await dragAndroid(target, from, to, STROKE, app);
|
|
5830
6117
|
scrolls += 1;
|
|
5831
6118
|
ui = await readAndroidUi(target, app);
|
|
5832
|
-
ended = viewContent(ui.nodes, next.frame, app) === before;
|
|
6119
|
+
ended = viewContent(ui.nodes, next.frame, "android", app) === before;
|
|
5833
6120
|
};
|
|
5834
6121
|
for (; ; ) {
|
|
5835
6122
|
if (elementsOnScreen(ui.nodes, selector, ui.display.size).length > 0) {
|
|
@@ -5839,7 +6126,13 @@ async function scrollToAndroid(target, selector, options, app) {
|
|
|
5839
6126
|
ui.display.size,
|
|
5840
6127
|
"Scroll to one by another selector."
|
|
5841
6128
|
);
|
|
5842
|
-
const around = view ?? scrollViewFor(
|
|
6129
|
+
const around = view ?? scrollViewFor(
|
|
6130
|
+
ui.nodes,
|
|
6131
|
+
direction,
|
|
6132
|
+
ui.display.size,
|
|
6133
|
+
"android",
|
|
6134
|
+
options.in
|
|
6135
|
+
);
|
|
5843
6136
|
const cut = around !== null && intersection(element.frame, around.frame) !== null && cutAtIncomingEdge(
|
|
5844
6137
|
element.frame,
|
|
5845
6138
|
around.frame,
|
|
@@ -5876,13 +6169,13 @@ async function scrollToAndroid(target, selector, options, app) {
|
|
|
5876
6169
|
}
|
|
5877
6170
|
async function scrollOnceAndroid(target, app) {
|
|
5878
6171
|
const ui = await readAndroidUi(target, app);
|
|
5879
|
-
const view = scrollViewFor(ui.nodes, "down", ui.display.size);
|
|
5880
|
-
if (!view || scrollAxisOf(view) !== "y") return void 0;
|
|
5881
|
-
const top = viewContent(ui.nodes, view.frame, app);
|
|
6172
|
+
const view = scrollViewFor(ui.nodes, "down", ui.display.size, "android");
|
|
6173
|
+
if (!view || scrollAxisOf(view, "android") !== "y") return void 0;
|
|
6174
|
+
const top = viewContent(ui.nodes, view.frame, "android", app);
|
|
5882
6175
|
const { from, to } = scrollStroke(view.frame, "down");
|
|
5883
6176
|
await dragAndroid(target, from, to, STROKE, app);
|
|
5884
6177
|
const after = await readAndroidUi(target, app);
|
|
5885
|
-
return viewContent(after.nodes, view.frame, app) === top ? void 0 : { frame: view.frame, top };
|
|
6178
|
+
return viewContent(after.nodes, view.frame, "android", app) === top ? void 0 : { frame: view.frame, top };
|
|
5886
6179
|
}
|
|
5887
6180
|
async function flingToTopAndroid(target, { frame, top }, app) {
|
|
5888
6181
|
const { from, to } = scrollStroke(frame, "up");
|
|
@@ -5894,6 +6187,7 @@ async function flingToTopAndroid(target, { frame, top }, app) {
|
|
|
5894
6187
|
const now = viewContent(
|
|
5895
6188
|
(await readAndroidUi(target, app)).nodes,
|
|
5896
6189
|
frame,
|
|
6190
|
+
"android",
|
|
5897
6191
|
app
|
|
5898
6192
|
);
|
|
5899
6193
|
if (now === top) return [];
|
|
@@ -5910,7 +6204,7 @@ var DEFAULT_MAX_SCROLLS = 20;
|
|
|
5910
6204
|
var scrollToCommand = defineCommand({
|
|
5911
6205
|
name: "scroll-to",
|
|
5912
6206
|
summary: "Scroll until the element with a text, label or id is in view, and give its frame",
|
|
5913
|
-
input:
|
|
6207
|
+
input: z36.object({
|
|
5914
6208
|
text: selectorFields.text.describe(
|
|
5915
6209
|
"Scroll to the element with this text: the whole text, not a part."
|
|
5916
6210
|
),
|
|
@@ -5920,13 +6214,13 @@ var scrollToCommand = defineCommand({
|
|
|
5920
6214
|
id: selectorFields.id.describe(
|
|
5921
6215
|
'Scroll to the element with this id: the resource-id on Android, or the part after ":id/".'
|
|
5922
6216
|
),
|
|
5923
|
-
direction:
|
|
6217
|
+
direction: z36.enum(DIRECTIONS).default("down").describe(
|
|
5924
6218
|
"Where the content to show is: down shows what is below, so the touch moves up."
|
|
5925
6219
|
),
|
|
5926
|
-
maxScrolls:
|
|
6220
|
+
maxScrolls: z36.number().int().min(0).max(200).default(DEFAULT_MAX_SCROLLS).describe(
|
|
5927
6221
|
"The most drags. Each one moves the scroll view by 60 % of its length."
|
|
5928
6222
|
),
|
|
5929
|
-
in:
|
|
6223
|
+
in: z36.string().min(1).optional().describe(
|
|
5930
6224
|
"The id of the scroll view to drag. By default, the innermost scroll view on the screen that scrolls along the direction; the largest one when there are more."
|
|
5931
6225
|
),
|
|
5932
6226
|
app: appField,
|
|
@@ -5934,13 +6228,13 @@ var scrollToCommand = defineCommand({
|
|
|
5934
6228
|
}),
|
|
5935
6229
|
output: displaySchema.extend({
|
|
5936
6230
|
element: elementSchema.describe("The element, as it shows at the end."),
|
|
5937
|
-
direction:
|
|
5938
|
-
scrolls:
|
|
6231
|
+
direction: z36.enum(DIRECTIONS),
|
|
6232
|
+
scrolls: z36.number().describe("The drags that loupe made: 0 when the element was in view."),
|
|
5939
6233
|
scrollView: elementSchema.optional().describe("The scroll view of the last drag. Left out with no drag.")
|
|
5940
6234
|
}),
|
|
5941
6235
|
run: async (input, context) => {
|
|
5942
6236
|
const selector = selectorOf(input);
|
|
5943
|
-
const target = await
|
|
6237
|
+
const target = await selectAndroidOnly(context, input.device);
|
|
5944
6238
|
const { display, ...scrolled } = await scrollToAndroid(
|
|
5945
6239
|
target,
|
|
5946
6240
|
selector,
|
|
@@ -5965,11 +6259,11 @@ var scrollToCommand = defineCommand({
|
|
|
5965
6259
|
|
|
5966
6260
|
// src/commands/sweep.ts
|
|
5967
6261
|
import path7 from "path";
|
|
5968
|
-
import { z as
|
|
6262
|
+
import { z as z38 } from "zod";
|
|
5969
6263
|
|
|
5970
6264
|
// src/core/sweep.ts
|
|
5971
6265
|
import path6 from "path";
|
|
5972
|
-
import { z as
|
|
6266
|
+
import { z as z37 } from "zod";
|
|
5973
6267
|
|
|
5974
6268
|
// src/core/contact-sheet.ts
|
|
5975
6269
|
var BACKGROUND = [32, 32, 32];
|
|
@@ -6082,53 +6376,53 @@ var SWEEP_THEMES = ["light", "dark"];
|
|
|
6082
6376
|
var SWEEP_DIRECTIONS = ["ltr", "rtl"];
|
|
6083
6377
|
var THUMBNAIL_WIDTH = 240;
|
|
6084
6378
|
var NO_SHOT = { width: THUMBNAIL_WIDTH, height: 427 };
|
|
6085
|
-
var sweepScreenSchema =
|
|
6086
|
-
number:
|
|
6379
|
+
var sweepScreenSchema = z37.object({
|
|
6380
|
+
number: z37.number().describe(
|
|
6087
6381
|
"The place of the link in the list, from 1: the number of its cell on each contact sheet, and of its screenshot file."
|
|
6088
6382
|
),
|
|
6089
|
-
url:
|
|
6090
|
-
variant:
|
|
6383
|
+
url: z37.string(),
|
|
6384
|
+
variant: z37.string().describe(
|
|
6091
6385
|
"The orientation and the theme, and the direction in a sweep with directions: portrait-dark, portrait-dark-rtl."
|
|
6092
6386
|
),
|
|
6093
|
-
scrolled:
|
|
6387
|
+
scrolled: z37.boolean().describe(
|
|
6094
6388
|
"True for the check after one scroll down. It comes right after the check of its link at the top."
|
|
6095
6389
|
),
|
|
6096
|
-
reloaded:
|
|
6390
|
+
reloaded: z37.boolean().describe(
|
|
6097
6391
|
"True when loupe stopped the app before this link, so the link started it again."
|
|
6098
6392
|
),
|
|
6099
|
-
passed:
|
|
6393
|
+
passed: z37.boolean().describe("True when loupe checked the screen and every rule passed."),
|
|
6100
6394
|
check: screenCheckSchema.optional().describe("The result of each rule, as `check` gives it."),
|
|
6101
|
-
error:
|
|
6395
|
+
error: z37.object({ code: z37.enum(ERROR_CODES), message: z37.string() }).optional().describe(
|
|
6102
6396
|
"Why loupe could not check this screen. The sweep went on with the next one."
|
|
6103
6397
|
),
|
|
6104
|
-
screenshot:
|
|
6105
|
-
warnings:
|
|
6106
|
-
ms:
|
|
6398
|
+
screenshot: z37.string().optional().describe("The file. Left out when loupe could take no screenshot."),
|
|
6399
|
+
warnings: z37.array(z37.string()),
|
|
6400
|
+
ms: z37.number().describe(
|
|
6107
6401
|
"Milliseconds for this screen, from the open, or from the scroll for a scrolled screen."
|
|
6108
6402
|
)
|
|
6109
6403
|
});
|
|
6110
|
-
var sweepVariantSchema =
|
|
6111
|
-
name:
|
|
6404
|
+
var sweepVariantSchema = z37.object({
|
|
6405
|
+
name: z37.string().describe(
|
|
6112
6406
|
"The orientation and the theme, and the direction in a sweep with directions: portrait-dark, portrait-dark-rtl."
|
|
6113
6407
|
),
|
|
6114
|
-
orientation:
|
|
6115
|
-
theme:
|
|
6116
|
-
direction:
|
|
6117
|
-
sheet:
|
|
6408
|
+
orientation: z37.enum(ORIENTATIONS),
|
|
6409
|
+
theme: z37.string().describe("light or dark, or the setting of the device."),
|
|
6410
|
+
direction: z37.enum(SWEEP_DIRECTIONS).optional().describe("ltr or rtl. Left out in a sweep with no directions."),
|
|
6411
|
+
sheet: z37.string().describe(
|
|
6118
6412
|
"The contact sheet: a thumbnail of each screen with its number, in a red frame when the screen failed."
|
|
6119
6413
|
),
|
|
6120
|
-
scrolledSheet:
|
|
6414
|
+
scrolledSheet: z37.string().optional().describe(
|
|
6121
6415
|
"The contact sheet of the scrolled screens, each with the number of its link. Left out when no screen scrolled."
|
|
6122
6416
|
),
|
|
6123
|
-
screens:
|
|
6124
|
-
failed:
|
|
6417
|
+
screens: z37.number().describe("The screens checked: one for each link, and each scrolled one."),
|
|
6418
|
+
failed: z37.number()
|
|
6125
6419
|
});
|
|
6126
|
-
var sweepReportSchema =
|
|
6127
|
-
out:
|
|
6128
|
-
passed:
|
|
6129
|
-
variants:
|
|
6130
|
-
screens:
|
|
6131
|
-
warnings:
|
|
6420
|
+
var sweepReportSchema = z37.object({
|
|
6421
|
+
out: z37.string().describe("The folder with each file of the sweep."),
|
|
6422
|
+
passed: z37.boolean().describe("True when every screen passed."),
|
|
6423
|
+
variants: z37.array(sweepVariantSchema),
|
|
6424
|
+
screens: z37.array(sweepScreenSchema),
|
|
6425
|
+
warnings: z37.array(z37.string())
|
|
6132
6426
|
});
|
|
6133
6427
|
function fileNumber(number, count) {
|
|
6134
6428
|
return String(number).padStart(Math.max(2, String(count).length), "0");
|
|
@@ -6469,7 +6763,7 @@ function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5
|
|
|
6469
6763
|
timeout: coldTimeout
|
|
6470
6764
|
});
|
|
6471
6765
|
const needMetro = () => {
|
|
6472
|
-
if (!metro || app !==
|
|
6766
|
+
if (!metro || app !== EXPO_GO) {
|
|
6473
6767
|
throw new LoupeError(
|
|
6474
6768
|
"invalid_input",
|
|
6475
6769
|
"A sweep with direction needs the app in Expo Go: app host.exp.exponent."
|
|
@@ -6484,7 +6778,7 @@ function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5
|
|
|
6484
6778
|
}),
|
|
6485
6779
|
open: async (url, { cold, direction }) => {
|
|
6486
6780
|
lastUrl = url;
|
|
6487
|
-
if (cold && app ===
|
|
6781
|
+
if (cold && app === EXPO_GO) {
|
|
6488
6782
|
await openCold(url, direction);
|
|
6489
6783
|
return;
|
|
6490
6784
|
}
|
|
@@ -6498,7 +6792,7 @@ function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5
|
|
|
6498
6792
|
direction === "rtl" ? "on" : "off"
|
|
6499
6793
|
);
|
|
6500
6794
|
if (!change.changed) return { restarted: false };
|
|
6501
|
-
await forceStopAndroid(target,
|
|
6795
|
+
await forceStopAndroid(target, EXPO_GO);
|
|
6502
6796
|
return { restarted: true };
|
|
6503
6797
|
},
|
|
6504
6798
|
reload: async () => {
|
|
@@ -6558,7 +6852,7 @@ function androidSweepDriver(target, app, rules, { waitTimeout, rotateTimeout = 5
|
|
|
6558
6852
|
...changed.direction && metro ? await orWarning(async () => {
|
|
6559
6853
|
const change = await switchRtl(metro.context, metro.port, "off");
|
|
6560
6854
|
if (!change.changed) return;
|
|
6561
|
-
await forceStopAndroid(target,
|
|
6855
|
+
await forceStopAndroid(target, EXPO_GO);
|
|
6562
6856
|
if (lastUrl) await openCold(lastUrl, directionOf(change));
|
|
6563
6857
|
}) : []
|
|
6564
6858
|
]
|
|
@@ -6591,9 +6885,9 @@ var failureSchema = sweepScreenSchema.pick({
|
|
|
6591
6885
|
screenshot: true,
|
|
6592
6886
|
error: true
|
|
6593
6887
|
}).extend({
|
|
6594
|
-
rules:
|
|
6595
|
-
findings:
|
|
6596
|
-
findingSchema.pick({ element: true, message: true }).extend({ rule:
|
|
6888
|
+
rules: z38.array(z38.string()).describe("The rules that failed."),
|
|
6889
|
+
findings: z38.array(
|
|
6890
|
+
findingSchema.pick({ element: true, message: true }).extend({ rule: z38.enum(RULES) })
|
|
6597
6891
|
).describe(
|
|
6598
6892
|
"Each finding of those rules: the element, and a message with the numbers in dp. The report also has the numbers by name."
|
|
6599
6893
|
)
|
|
@@ -6601,37 +6895,37 @@ var failureSchema = sweepScreenSchema.pick({
|
|
|
6601
6895
|
var sweepCommand = defineCommand({
|
|
6602
6896
|
name: "sweep",
|
|
6603
6897
|
summary: "Open each link in each orientation, theme and direction, check each screen, and write a report, the screenshots and a contact sheet for each variant",
|
|
6604
|
-
input:
|
|
6605
|
-
url:
|
|
6606
|
-
|
|
6898
|
+
input: z38.object({
|
|
6899
|
+
url: z38.array(
|
|
6900
|
+
z38.string().regex(
|
|
6607
6901
|
/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/,
|
|
6608
6902
|
"A URL starts with a scheme, for example https: or exp:, and has no spaces."
|
|
6609
6903
|
)
|
|
6610
6904
|
).min(1).describe(
|
|
6611
6905
|
"A link to open and check: a deep link or a web page. Give it once for each screen."
|
|
6612
6906
|
),
|
|
6613
|
-
orientation:
|
|
6907
|
+
orientation: z38.string().regex(LIST, "The orientations are a comma list.").optional().describe(
|
|
6614
6908
|
`The orientations to check, as a comma list of ${ORIENTATIONS.join(", ")}. Left out: only the one that the device has, and loupe turns nothing.`
|
|
6615
6909
|
),
|
|
6616
|
-
theme:
|
|
6910
|
+
theme: z38.string().regex(LIST, "The themes are a comma list.").optional().describe(
|
|
6617
6911
|
`The themes to check, as a comma list of ${SWEEP_THEMES.join(", ")}. Left out: only the one that the device has, and loupe sets nothing.`
|
|
6618
6912
|
),
|
|
6619
|
-
rules:
|
|
6913
|
+
rules: z38.string().regex(LIST, "The rules are a comma list.").optional().describe(
|
|
6620
6914
|
`The rules to run on each screen, as a comma list. Each one by default: ${SWEEP_RULES.join(", ")}.`
|
|
6621
6915
|
),
|
|
6622
|
-
out:
|
|
6916
|
+
out: z38.string().min(1).default("loupe-sweep").describe(
|
|
6623
6917
|
"The folder for report.json, the screenshots (<variant>/<number>.png) and the contact sheets (<variant>.png). Files that are there are replaced."
|
|
6624
6918
|
),
|
|
6625
|
-
scroll:
|
|
6919
|
+
scroll: z38.boolean().optional().describe(
|
|
6626
6920
|
"Also scroll each screen down once, by 60 % of its largest vertical scroll view, and check it again: <variant>/<number>-scrolled.png and <variant>-scrolled.png. Then loupe scrolls back to the top."
|
|
6627
6921
|
),
|
|
6628
|
-
direction:
|
|
6629
|
-
`The layout directions to check, as a comma list of ${SWEEP_DIRECTIONS.join(", ")}. Only for an app in Expo Go (app ${
|
|
6922
|
+
direction: z38.string().regex(LIST, "The directions are a comma list.").optional().describe(
|
|
6923
|
+
`The layout directions to check, as a comma list of ${SWEEP_DIRECTIONS.join(", ")}. Only for an app in Expo Go (app ${EXPO_GO}): loupe sets each one in app.json as expo-rtl does, opens the app again, and puts app.json back at the end. Left out: only the direction that the app has.`
|
|
6630
6924
|
),
|
|
6631
6925
|
port: portField.describe(
|
|
6632
6926
|
`The port of Metro on this machine (npx expo start), for direction. ${DEFAULT_PORT} by default.`
|
|
6633
6927
|
),
|
|
6634
|
-
reloadEvery:
|
|
6928
|
+
reloadEvery: z38.number().int().min(1).optional().describe(
|
|
6635
6929
|
"Stop the app before each N-th link that the sweep opens, over all the variants, so the link starts it again: stacked screens slow an app down. In Expo Go, loupe then waits until the app shows the route of the link. Needs app. Left out: no restart."
|
|
6636
6930
|
),
|
|
6637
6931
|
waitTimeout: timeoutField.describe(
|
|
@@ -6642,19 +6936,19 @@ var sweepCommand = defineCommand({
|
|
|
6642
6936
|
),
|
|
6643
6937
|
device: deviceField
|
|
6644
6938
|
}),
|
|
6645
|
-
output:
|
|
6646
|
-
out:
|
|
6647
|
-
report:
|
|
6939
|
+
output: z38.object({
|
|
6940
|
+
out: z38.string().describe("The folder with each file of the sweep."),
|
|
6941
|
+
report: z38.string().describe(
|
|
6648
6942
|
"report.json: each screen with its number, link, variant, the result of each rule with its numbers, and its screenshot."
|
|
6649
6943
|
),
|
|
6650
|
-
passed:
|
|
6651
|
-
screens:
|
|
6652
|
-
failed:
|
|
6653
|
-
variants:
|
|
6654
|
-
failures:
|
|
6944
|
+
passed: z38.boolean().describe("True when every screen passed."),
|
|
6945
|
+
screens: z38.number().describe("Links \xD7 variants, and each scrolled screen."),
|
|
6946
|
+
failed: z38.number(),
|
|
6947
|
+
variants: z38.array(sweepVariantSchema),
|
|
6948
|
+
failures: z38.array(failureSchema).describe(
|
|
6655
6949
|
"The screens that failed, each with its findings or its error. The report also has the screens that passed, and the warnings of each rule."
|
|
6656
6950
|
),
|
|
6657
|
-
warnings:
|
|
6951
|
+
warnings: z38.array(z38.string())
|
|
6658
6952
|
}),
|
|
6659
6953
|
run: async (input, context) => {
|
|
6660
6954
|
const rules = input.rules === void 0 ? SWEEP_RULES : rulesOf(input.rules);
|
|
@@ -6683,10 +6977,10 @@ var sweepCommand = defineCommand({
|
|
|
6683
6977
|
);
|
|
6684
6978
|
const port = input.port ?? DEFAULT_PORT;
|
|
6685
6979
|
if (directions) {
|
|
6686
|
-
if (input.app !==
|
|
6980
|
+
if (input.app !== EXPO_GO) {
|
|
6687
6981
|
throw new LoupeError(
|
|
6688
6982
|
"invalid_input",
|
|
6689
|
-
`direction needs the app in Expo Go: app ${
|
|
6983
|
+
`direction needs the app in Expo Go: app ${EXPO_GO}. loupe sets the direction in app.json, as expo-rtl does.`
|
|
6690
6984
|
);
|
|
6691
6985
|
}
|
|
6692
6986
|
const { projectRoot, dynamicConfigPath } = await expoProject(
|
|
@@ -6695,7 +6989,7 @@ var sweepCommand = defineCommand({
|
|
|
6695
6989
|
);
|
|
6696
6990
|
await requireAppJson(projectRoot, "on", dynamicConfigPath);
|
|
6697
6991
|
}
|
|
6698
|
-
const target = await
|
|
6992
|
+
const target = await selectAndroidOnly(context, input.device);
|
|
6699
6993
|
requireAppOnDevice(target, input.app);
|
|
6700
6994
|
const report = await sweep(
|
|
6701
6995
|
androidSweepDriver(
|
|
@@ -6794,11 +7088,11 @@ var sweepCommand = defineCommand({
|
|
|
6794
7088
|
});
|
|
6795
7089
|
|
|
6796
7090
|
// src/commands/swipe.ts
|
|
6797
|
-
import { z as
|
|
7091
|
+
import { z as z39 } from "zod";
|
|
6798
7092
|
var swipeCommand = defineCommand({
|
|
6799
7093
|
name: "swipe",
|
|
6800
7094
|
summary: "Move one touch in a straight line from one point to another",
|
|
6801
|
-
input:
|
|
7095
|
+
input: z39.object({
|
|
6802
7096
|
fromX: coordinateField("x"),
|
|
6803
7097
|
fromY: coordinateField("y"),
|
|
6804
7098
|
toX: coordinateField("x"),
|
|
@@ -6811,7 +7105,7 @@ var swipeCommand = defineCommand({
|
|
|
6811
7105
|
positionals: ["fromX", "fromY", "toX", "toY"],
|
|
6812
7106
|
output: touchSchema.extend({ waited: waitedSchema.optional() }),
|
|
6813
7107
|
run: async ({ fromX, fromY, toX, toY, duration, app, device, ...wait }, context) => {
|
|
6814
|
-
const target = await
|
|
7108
|
+
const target = await selectAndroidOnly(context, device);
|
|
6815
7109
|
const touch2 = await swipeAndroid(
|
|
6816
7110
|
target,
|
|
6817
7111
|
{ x: fromX, y: fromY },
|
|
@@ -6829,11 +7123,11 @@ var swipeCommand = defineCommand({
|
|
|
6829
7123
|
});
|
|
6830
7124
|
|
|
6831
7125
|
// src/commands/tap.ts
|
|
6832
|
-
import { z as
|
|
7126
|
+
import { z as z40 } from "zod";
|
|
6833
7127
|
var tapCommand = defineCommand({
|
|
6834
7128
|
name: "tap",
|
|
6835
7129
|
summary: "Tap one point of the screen, or the element with a text, label or id",
|
|
6836
|
-
input:
|
|
7130
|
+
input: z40.object({
|
|
6837
7131
|
x: coordinateField("x").optional(),
|
|
6838
7132
|
y: coordinateField("y").optional(),
|
|
6839
7133
|
...selectorFields,
|
|
@@ -6844,7 +7138,7 @@ var tapCommand = defineCommand({
|
|
|
6844
7138
|
positionals: ["x", "y"],
|
|
6845
7139
|
output: aimedTouchSchema.extend({ waited: waitedSchema.optional() }),
|
|
6846
7140
|
run: async ({ app, device, waitStill, waitText, waitTimeout, ...input }, context) => {
|
|
6847
|
-
const target = await
|
|
7141
|
+
const target = await selectAndroidOnly(context, device);
|
|
6848
7142
|
const { point, element } = await aimAndroid(target, targetOf(input), app);
|
|
6849
7143
|
const touch2 = await tapAndroid(target, point, app);
|
|
6850
7144
|
const waited = await waitAfterAction(
|
|
@@ -6862,8 +7156,8 @@ var tapCommand = defineCommand({
|
|
|
6862
7156
|
});
|
|
6863
7157
|
|
|
6864
7158
|
// src/commands/theme.ts
|
|
6865
|
-
import { z as
|
|
6866
|
-
var settingSchema =
|
|
7159
|
+
import { z as z41 } from "zod";
|
|
7160
|
+
var settingSchema = z41.enum(THEME_SETTINGS).describe(
|
|
6867
7161
|
"light or dark; auto: Android picks one by the time of day; custom: by a schedule."
|
|
6868
7162
|
);
|
|
6869
7163
|
function describeSetting(setting) {
|
|
@@ -6879,9 +7173,9 @@ function describeSetting(setting) {
|
|
|
6879
7173
|
var themeCommand = defineCommand({
|
|
6880
7174
|
name: "theme",
|
|
6881
7175
|
summary: "Set the system theme to light or dark, and wait until the app shows it. With no theme, read it",
|
|
6882
|
-
input:
|
|
6883
|
-
theme:
|
|
6884
|
-
timeout:
|
|
7176
|
+
input: z41.object({
|
|
7177
|
+
theme: z41.enum(THEMES).optional().describe("light or dark. Left out: loupe only reads the setting."),
|
|
7178
|
+
timeout: z41.number().int().min(0).default(5e3).describe(
|
|
6885
7179
|
"Milliseconds to wait until the app's probe shows the theme. A screen with no probe has no wait."
|
|
6886
7180
|
),
|
|
6887
7181
|
...waitFields,
|
|
@@ -6889,18 +7183,18 @@ var themeCommand = defineCommand({
|
|
|
6889
7183
|
device: deviceField
|
|
6890
7184
|
}),
|
|
6891
7185
|
positionals: ["theme"],
|
|
6892
|
-
output:
|
|
7186
|
+
output: z41.object({
|
|
6893
7187
|
theme: settingSchema.describe("The system theme setting now."),
|
|
6894
7188
|
was: settingSchema.optional().describe("The setting before. Left out when loupe only read it."),
|
|
6895
|
-
source:
|
|
7189
|
+
source: z41.enum(["probe", "setting"]).optional().describe(
|
|
6896
7190
|
"What showed the theme: probe, the app's probe on the screen; setting, the system setting alone (no probe on the screen, or a probe that kept the other scheme)."
|
|
6897
7191
|
),
|
|
6898
|
-
ms:
|
|
6899
|
-
warnings:
|
|
7192
|
+
ms: z41.number().optional().describe("Milliseconds from the write until the source showed it."),
|
|
7193
|
+
warnings: z41.array(z41.string()),
|
|
6900
7194
|
waited: waitedSchema.optional()
|
|
6901
7195
|
}),
|
|
6902
7196
|
run: async ({ theme, timeout, app, device, ...wait }, context) => {
|
|
6903
|
-
const target = await
|
|
7197
|
+
const target = await selectAndroidOnly(context, device);
|
|
6904
7198
|
if (!theme) return { theme: await readThemeAndroid(target), warnings: [] };
|
|
6905
7199
|
const change = await setThemeAndroid(target, theme, app, { timeout });
|
|
6906
7200
|
const waited = await waitAfterAction(target, app, wait, "theme");
|
|
@@ -6920,12 +7214,12 @@ var themeCommand = defineCommand({
|
|
|
6920
7214
|
});
|
|
6921
7215
|
|
|
6922
7216
|
// src/commands/type.ts
|
|
6923
|
-
import { z as
|
|
7217
|
+
import { z as z42 } from "zod";
|
|
6924
7218
|
var typeCommand = defineCommand({
|
|
6925
7219
|
name: "type",
|
|
6926
7220
|
summary: "Type text into the field that has the focus",
|
|
6927
|
-
input:
|
|
6928
|
-
text:
|
|
7221
|
+
input: z42.object({
|
|
7222
|
+
text: z42.string().min(1).describe(
|
|
6929
7223
|
"The text to type. On Android, printable ASCII only; press Enter with the key command."
|
|
6930
7224
|
),
|
|
6931
7225
|
...waitFields,
|
|
@@ -6934,12 +7228,12 @@ var typeCommand = defineCommand({
|
|
|
6934
7228
|
}),
|
|
6935
7229
|
positionals: ["text"],
|
|
6936
7230
|
// The output has no text: it can be a password.
|
|
6937
|
-
output:
|
|
6938
|
-
characters:
|
|
7231
|
+
output: z42.object({
|
|
7232
|
+
characters: z42.number().int(),
|
|
6939
7233
|
waited: waitedSchema.optional()
|
|
6940
7234
|
}),
|
|
6941
7235
|
run: async ({ text, app, device, ...wait }, context) => {
|
|
6942
|
-
const target = await
|
|
7236
|
+
const target = await selectAndroidOnly(context, device);
|
|
6943
7237
|
const typed = await typeAndroid(target, text, app);
|
|
6944
7238
|
const waited = await waitAfterAction(target, app, wait, "type");
|
|
6945
7239
|
return { ...typed, waited };
|
|
@@ -6951,17 +7245,17 @@ var typeCommand = defineCommand({
|
|
|
6951
7245
|
});
|
|
6952
7246
|
|
|
6953
7247
|
// src/commands/version.ts
|
|
6954
|
-
import { z as
|
|
7248
|
+
import { z as z43 } from "zod";
|
|
6955
7249
|
var versionCommand = defineCommand({
|
|
6956
7250
|
name: "version",
|
|
6957
7251
|
summary: "Print the loupe version and the host it runs on",
|
|
6958
7252
|
readOnly: true,
|
|
6959
|
-
input:
|
|
6960
|
-
output:
|
|
6961
|
-
loupe:
|
|
6962
|
-
node:
|
|
6963
|
-
platform:
|
|
6964
|
-
arch:
|
|
7253
|
+
input: z43.object({}),
|
|
7254
|
+
output: z43.object({
|
|
7255
|
+
loupe: z43.string(),
|
|
7256
|
+
node: z43.string(),
|
|
7257
|
+
platform: z43.string(),
|
|
7258
|
+
arch: z43.string()
|
|
6965
7259
|
}),
|
|
6966
7260
|
run: () => ({
|
|
6967
7261
|
loupe: version,
|
|
@@ -6973,7 +7267,7 @@ var versionCommand = defineCommand({
|
|
|
6973
7267
|
});
|
|
6974
7268
|
|
|
6975
7269
|
// src/commands/wait.ts
|
|
6976
|
-
import { z as
|
|
7270
|
+
import { z as z44 } from "zod";
|
|
6977
7271
|
function sentence(text) {
|
|
6978
7272
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
6979
7273
|
}
|
|
@@ -6981,8 +7275,8 @@ var waitCommand = defineCommand({
|
|
|
6981
7275
|
name: "wait",
|
|
6982
7276
|
summary: "Wait until the screen keeps still, or until an element is on the screen",
|
|
6983
7277
|
readOnly: true,
|
|
6984
|
-
input:
|
|
6985
|
-
still:
|
|
7278
|
+
input: z44.object({
|
|
7279
|
+
still: z44.boolean().optional().describe(
|
|
6986
7280
|
"Wait until the screen keeps still: two equal screenshots in a row, with the system bars left out (the clock ticks there)."
|
|
6987
7281
|
),
|
|
6988
7282
|
text: selectorFields.text.describe(
|
|
@@ -6995,7 +7289,7 @@ var waitCommand = defineCommand({
|
|
|
6995
7289
|
"Wait until an element with this id is on the screen."
|
|
6996
7290
|
),
|
|
6997
7291
|
timeout: timeoutField,
|
|
6998
|
-
interval:
|
|
7292
|
+
interval: z44.number().int().min(0).max(1e4).optional().describe(
|
|
6999
7293
|
`The pause between two screenshots or two reads, in ms. ${DEFAULT_WAIT_INTERVAL} by default.`
|
|
7000
7294
|
),
|
|
7001
7295
|
app: appField,
|
|
@@ -7019,7 +7313,7 @@ var waitCommand = defineCommand({
|
|
|
7019
7313
|
timeout: input.timeout ?? DEFAULT_WAIT_TIMEOUT,
|
|
7020
7314
|
interval: input.interval ?? DEFAULT_WAIT_INTERVAL
|
|
7021
7315
|
};
|
|
7022
|
-
const target = await
|
|
7316
|
+
const target = await selectAndroidOnly(context, device);
|
|
7023
7317
|
if (!selector) {
|
|
7024
7318
|
const result2 = await waitStillAndroid(target, app, options);
|
|
7025
7319
|
if (!result2.still) {
|
|
@@ -7085,7 +7379,12 @@ var localFetch = async (input, init) => {
|
|
|
7085
7379
|
return fetch(input, init);
|
|
7086
7380
|
};
|
|
7087
7381
|
function createContext() {
|
|
7088
|
-
return {
|
|
7382
|
+
return {
|
|
7383
|
+
exec: nodeExec,
|
|
7384
|
+
env: process.env,
|
|
7385
|
+
fetch: localFetch,
|
|
7386
|
+
hostPlatform: process.platform
|
|
7387
|
+
};
|
|
7089
7388
|
}
|
|
7090
7389
|
|
|
7091
7390
|
// src/core/run-command.ts
|