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] ?? ''));
|
$eurekaName = trim((string) ($eureka[$ip] ?? ''));
|
||||||
if ($eurekaName !== '') {
|
if ($eurekaName !== '') {
|
||||||
$name = $eurekaName;
|
$name = $eurekaName;
|
||||||
} elseif ($name === '') {
|
|
||||||
$lookup = lookup_device_name($ip);
|
|
||||||
if ($lookup !== null && $lookup !== '') $name = $lookup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$portOpen = in_array($ip, $port5555, true);
|
$portOpen = in_array($ip, $port5555, true);
|
||||||
|
|
@ -243,8 +240,6 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($results, function ($a, $b) {
|
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)) {
|
if (($a['port_open'] ?? false) !== ($b['port_open'] ?? false)) {
|
||||||
return ($a['port_open'] ? 0 : 1) <=> ($b['port_open'] ? 0 : 1);
|
return ($a['port_open'] ? 0 : 1) <=> ($b['port_open'] ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
@ -254,6 +249,7 @@ try {
|
||||||
json_out([
|
json_out([
|
||||||
'ok' => true,
|
'ok' => true,
|
||||||
'adb_available' => adb_available(),
|
'adb_available' => adb_available(),
|
||||||
|
'adb_devices' => $adb,
|
||||||
'devices' => $results,
|
'devices' => $results,
|
||||||
'scanned_at' => gmdate('c'),
|
'scanned_at' => gmdate('c'),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -309,15 +309,10 @@
|
||||||
if (!!a.port_open !== !!b.port_open) return a.port_open ? -1 : 1;
|
if (!!a.port_open !== !!b.port_open) return a.port_open ? -1 : 1;
|
||||||
return a.ip.localeCompare(b.ip, undefined, { numeric: true });
|
return a.ip.localeCompare(b.ip, undefined, { numeric: true });
|
||||||
});
|
});
|
||||||
// refresh adb states from status
|
state.adbDevices = data.adb_devices || [];
|
||||||
const st = await api('status');
|
for (const d of state.devices) {
|
||||||
if (st.ok) {
|
const a = state.adbDevices.find(x => x.ip === d.ip);
|
||||||
state.adbDevices = st.adb_devices || [];
|
d.adb_state = a ? a.state : d.adb_state;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateAdbStatus();
|
updateAdbStatus();
|
||||||
renderDevices();
|
renderDevices();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue