Refactor scan: remove redundant lookup/sort, return adb_devices in scan response
This commit is contained in:
parent
717277ae87
commit
cd5734f3d3
2 changed files with 5 additions and 14 deletions
6
api.php
6
api.php
|
|
@ -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'),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -309,16 +309,11 @@
|
|||
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;
|
||||
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();
|
||||
renderControl();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue