Refactor scan: remove redundant lookup/sort, return adb_devices in scan response

This commit is contained in:
Clarth 2026-12-03 20:57:01 -05:00
parent 717277ae87
commit cd5734f3d3
2 changed files with 5 additions and 14 deletions

View file

@ -206,9 +206,6 @@ try {
$eurekaName = trim((string) ($eureka[$ip] ?? ''));
if ($eurekaName !== '') {
$name = $eurekaName;
} elseif ($name === '') {
$lookup = lookup_device_name($ip);
if ($lookup !== null && $lookup !== '') $name = $lookup;
}
$portOpen = in_array($ip, $port5555, true);
@ -243,8 +240,6 @@ try {
}
usort($results, function ($a, $b) {
$aDisc = !empty($a['last_seen']) && ($a['port_open'] || ($a['adb_state'] ?? null));
$bDisc = !empty($b['last_seen']) && ($b['port_open'] || ($b['adb_state'] ?? null));
if (($a['port_open'] ?? false) !== ($b['port_open'] ?? false)) {
return ($a['port_open'] ? 0 : 1) <=> ($b['port_open'] ? 0 : 1);
}
@ -254,6 +249,7 @@ try {
json_out([
'ok' => true,
'adb_available' => adb_available(),
'adb_devices' => $adb,
'devices' => $results,
'scanned_at' => gmdate('c'),
]);

View file

@ -309,15 +309,10 @@
if (!!a.port_open !== !!b.port_open) return a.port_open ? -1 : 1;
return a.ip.localeCompare(b.ip, undefined, { numeric: true });
});
// refresh adb states from status
const st = await api('status');
if (st.ok) {
state.adbDevices = st.adb_devices || [];
state.adbAvailable = !!st.adb_available;
for (const d of state.devices) {
const a = state.adbDevices.find(x => x.ip === d.ip);
d.adb_state = a ? a.state : d.adb_state;
}
state.adbDevices = data.adb_devices || [];
for (const d of state.devices) {
const a = state.adbDevices.find(x => x.ip === d.ip);
d.adb_state = a ? a.state : d.adb_state;
}
updateAdbStatus();
renderDevices();