fix(webgui): harden config bool parsing and action error handling
This commit is contained in:
1 parent
3659d5b7da
commit
37f736c158
10 files changed
+1366
-233
No files matched your search
@@ -38,7 +38,13 @@ function getConfigValue(cfg, key) {
|
||||
}
|
||||
|
||||
function coerceValue(type, raw, isCheckbox) {
|
||||
if (type === "bool") return !!raw;
|
||||
if (type === "bool") {
|
||||
if (typeof raw === "boolean") return raw;
|
||||
const text = String(raw ?? "").trim().toLowerCase();
|
||||
if (["1", "true", "yes", "y", "on"].includes(text)) return true;
|
||||
if (["0", "false", "no", "n", "off", ""].includes(text)) return false;
|
||||
return !!raw;
|
||||
}
|
||||
if (type === "int") {
|
||||
const n = parseInt(String(raw ?? "0"), 10);
|
||||
return Number.isFinite(n) ? n : 0;
|
||||
|
||||
+27
-232
@@ -23,7 +23,6 @@ async function refreshDevices() {
|
||||
|
||||
// 选中后在外层包装上反映状态点
|
||||
decorateDeviceSelect();
|
||||
sel.addEventListener("change", decorateDeviceSelect);
|
||||
}
|
||||
|
||||
function decorateDeviceSelect() {
|
||||
@@ -48,209 +47,6 @@ function decorateDeviceSelect() {
|
||||
if (dot) dot.dataset.state = ok ? "ok" : "idle";
|
||||
}
|
||||
|
||||
function selectedDeviceId() {
|
||||
const el = $("device");
|
||||
return el ? (el.value || "") : "";
|
||||
}
|
||||
|
||||
async function postDeviceAction(path, body, successPrefix) {
|
||||
try {
|
||||
const result = await apiPost(path, body || {});
|
||||
const msg = result.message || result.output || result.error || "完成";
|
||||
appendLog([`${successPrefix}: ${msg}`]);
|
||||
if (!result.error) toast(`${successPrefix}: ${msg}`, "success");
|
||||
else toast(`${successPrefix}: ${msg}`, "warn");
|
||||
if (result.devices) await refreshDevices();
|
||||
return result;
|
||||
} catch (e) {
|
||||
appendLog([`${successPrefix}失败: ${e?.message || e}`]);
|
||||
toast(`${successPrefix}失败:${e?.message || e}`, "error", { duration: 5000 });
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function forceStopRun() {
|
||||
await postDeviceAction("/api/force-stop", {}, "[WEB] 强制停止");
|
||||
}
|
||||
|
||||
async function sendBackKey() {
|
||||
const deviceId = selectedDeviceId();
|
||||
await postDeviceAction("/api/back-key", { device_id: deviceId }, "[WEB] 返回键");
|
||||
}
|
||||
|
||||
async function wifiEnable() {
|
||||
const deviceId = selectedDeviceId();
|
||||
if (!deviceId) {
|
||||
appendLog(["[WiFi ADB] 请先选择 USB 设备"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/enable", { device_id: deviceId }, "[WiFi ADB] 启用");
|
||||
setTextIfExists("wifiStatus", result.message || "已发送启用命令");
|
||||
}
|
||||
|
||||
async function wifiConnect() {
|
||||
const ip = ($("wifi_ip")?.value || "").trim();
|
||||
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
|
||||
if (!ip) {
|
||||
appendLog(["[WiFi ADB] 请填写设备 IP"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/connect", { ip, port }, "[WiFi ADB] 连接");
|
||||
setTextIfExists("wifiStatus", result.message || "连接命令已执行");
|
||||
}
|
||||
|
||||
async function wifiDisconnect() {
|
||||
const ip = ($("wifi_ip")?.value || selectedDeviceId() || "").trim();
|
||||
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
|
||||
if (!ip) {
|
||||
appendLog(["[WiFi ADB] 请填写 IP 或选择 WiFi 设备"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/disconnect", { ip, port }, "[WiFi ADB] 断开");
|
||||
setTextIfExists("wifiStatus", result.message || "断开命令已执行");
|
||||
}
|
||||
|
||||
async function tryAutoReconnectLastWifi() {
|
||||
// 启动时调一次 /api/wifi/auto-reconnect。后端做完所有判断(已在线 / 重连成功 /
|
||||
// 智能匹配 / 失败),前端只负责把结果反馈到日志和设备下拉。
|
||||
try {
|
||||
const resp = await apiPost("/api/wifi/auto-reconnect", {});
|
||||
if (!resp || resp.ok === false) return;
|
||||
const action = resp.action || "noop";
|
||||
if (action === "noop") return;
|
||||
|
||||
if (action === "already_online" || action === "reconnected" || action === "matched") {
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (_) {}
|
||||
const sel = $("device");
|
||||
if (sel && resp.target) {
|
||||
// 选中设备到下拉框
|
||||
for (const opt of sel.options) {
|
||||
if (opt.value === resp.target) {
|
||||
sel.value = resp.target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const status = $("wifiStatus");
|
||||
if (status && resp.message) status.textContent = resp.message;
|
||||
appendLog([`[启动] ${resp.message || action}`]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "failed") {
|
||||
appendLog([`[启动] ${resp.message || "WiFi 自动重连失败"}`]);
|
||||
const status = $("wifiStatus");
|
||||
if (status && resp.message) status.textContent = resp.message;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// 启动期任何异常都不打扰用户
|
||||
console.warn("auto-reconnect failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function wifiScan() {
|
||||
const btn = $("btnWifiScan");
|
||||
const status = $("wifiStatus");
|
||||
const results = $("wifiScanResults");
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = "扫描中...";
|
||||
}
|
||||
if (status) status.textContent = "正在扫描局域网...";
|
||||
if (results) {
|
||||
results.style.display = "none";
|
||||
results.innerHTML = "";
|
||||
}
|
||||
try {
|
||||
const resp = await apiPost("/api/wifi/scan", {});
|
||||
if (!resp || resp.ok === false) {
|
||||
const err = (resp && resp.error) || "扫描失败";
|
||||
appendLog([`[WiFi ADB] 扫描失败: ${err}`]);
|
||||
if (status) status.textContent = `扫描失败: ${err}`;
|
||||
return;
|
||||
}
|
||||
const devs = Array.isArray(resp.devices) ? resp.devices : [];
|
||||
const subnet = resp.subnet || "";
|
||||
if (!devs.length) {
|
||||
appendLog([`[WiFi ADB] 扫描完成 (${subnet}),未发现开放 5555 端口的设备`]);
|
||||
if (status) status.textContent = `扫描完成 (${subnet}),未发现设备`;
|
||||
return;
|
||||
}
|
||||
appendLog([
|
||||
`[WiFi ADB] 扫描完成 (${subnet}),发现 ${devs.length} 台候选: ` +
|
||||
devs.map((d) => `${d.target}(${d.state})`).join(", "),
|
||||
]);
|
||||
|
||||
// 单个 connected:自动选中
|
||||
const connected = devs.filter((d) => d.state === "connected");
|
||||
if (connected.length === 1 && devs.length === 1) {
|
||||
const d = connected[0];
|
||||
const ipInput = $("wifi_ip");
|
||||
if (ipInput) ipInput.value = d.target;
|
||||
if (status)
|
||||
status.textContent =
|
||||
`已发现并连接 ${d.target}` + (d.model ? ` (${d.model})` : "") + ",已记住";
|
||||
// 刷新设备下拉
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (_) {}
|
||||
return;
|
||||
}
|
||||
|
||||
// 多个候选:渲染列表,点击就填回 IP
|
||||
if (results) {
|
||||
results.style.display = "block";
|
||||
const lines = devs.map((d) => {
|
||||
const safeTarget = String(d.target || "").replace(/"/g, """);
|
||||
const stateColor =
|
||||
d.state === "connected" ? "#0a7d2c" :
|
||||
d.state === "unauthorized" ? "#b35900" : "#888";
|
||||
return (
|
||||
`<div style="margin:4px 0; cursor:pointer; padding:4px 6px; border:1px solid #ddd; border-radius:4px;" ` +
|
||||
`data-target="${safeTarget}" data-state="${d.state}">` +
|
||||
`<b>${safeTarget}</b> ` +
|
||||
`<span style="color:${stateColor}">[${d.state}]</span> ` +
|
||||
(d.model ? ` <span style="color:#555">${d.model}</span>` : "") +
|
||||
`</div>`
|
||||
);
|
||||
});
|
||||
results.innerHTML =
|
||||
`<div style="margin-bottom:4px; color:#555;">点击下方设备使用:</div>` +
|
||||
lines.join("");
|
||||
results.querySelectorAll("[data-target]").forEach((el) => {
|
||||
el.addEventListener("click", () => {
|
||||
const target = el.getAttribute("data-target");
|
||||
const state = el.getAttribute("data-state");
|
||||
if (state !== "connected") {
|
||||
appendLog([
|
||||
`[WiFi ADB] ${target} 状态=${state},请先在手机上确认 ADB 调试授权`,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
const ipInput = $("wifi_ip");
|
||||
if (ipInput) ipInput.value = target;
|
||||
if (status) status.textContent = `已选 ${target}`;
|
||||
appendLog([`[WiFi ADB] 已选 ${target}`]);
|
||||
try {
|
||||
refreshDevices();
|
||||
} catch (_) {}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (status) status.textContent = `扫描完成,发现 ${devs.length} 台设备`;
|
||||
} catch (e) {
|
||||
appendLog([`[WiFi ADB] 扫描异常: ${e}`]);
|
||||
if (status) status.textContent = `扫描异常: ${e}`;
|
||||
} finally {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = "扫描 WiFi";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function startRun() {
|
||||
setButtonBusy("btnStart", true);
|
||||
@@ -358,20 +154,6 @@ async function startRun() {
|
||||
}
|
||||
}
|
||||
|
||||
async function testYanghao() {
|
||||
const deviceId = $("device").value || "";
|
||||
const seconds = parseInt($("yanghao_recommend_duration_seconds").value || "60", 10);
|
||||
await apiPost("/api/test-yanghao", { device_id: deviceId, seconds });
|
||||
appendLog([`[WEB] 已启动测试养号:device=${deviceId || UI_COPY.device.autoLabel} seconds=${seconds}`]);
|
||||
}
|
||||
|
||||
async function testComment() {
|
||||
const deviceId = $("device").value || "";
|
||||
const text = "";
|
||||
await apiPost("/api/test-comment", { device_id: deviceId, text });
|
||||
appendLog([`[WEB] 已启动测试评论:device=${deviceId || UI_COPY.device.autoLabel}${text ? ' text=自定义' : ''}`]);
|
||||
}
|
||||
|
||||
async function stopRun() {
|
||||
setRunOverview(UI_COPY.runOverview.stopping, UI_COPY.runOverview.stoppingMeta, RUN_TONE.idle);
|
||||
await apiPost("/api/stop", {});
|
||||
@@ -493,11 +275,15 @@ async function pollReservations() {
|
||||
// 显示基本信息
|
||||
const info = document.createElement("div");
|
||||
info.className = "reservationsInfo";
|
||||
const safeRoomPos = Number.isFinite(Number(room_pos)) ? Number(room_pos) : 0;
|
||||
const safeReservationsCount = Number.isFinite(Number(reservations.length))
|
||||
? Number(reservations.length)
|
||||
: 0;
|
||||
info.innerHTML = `
|
||||
<div><strong>当前位置:</strong>${room_pos}</div>
|
||||
<div><strong>当前位置:</strong>${safeRoomPos}</div>
|
||||
<div><strong>当前直播间(清洗后):</strong>${escapeHtml(current_room_title || '-') }</div>
|
||||
<div><strong>当前直播间原文:</strong>${escapeHtml(current_room_title_raw || '-') }</div>
|
||||
<div><strong>预约数量:</strong>${reservations.length}</div>
|
||||
<div><strong>预约数量:</strong>${safeReservationsCount}</div>
|
||||
<div class="hint">更新时间:${updated_ts > 0 ? new Date(updated_ts * 1000).toLocaleTimeString() : '-'}</div>
|
||||
<div class="hint">原因:${escapeHtml(reason || '-') }</div>
|
||||
`;
|
||||
@@ -525,6 +311,10 @@ async function pollReservations() {
|
||||
const future_ts = item.future_ts || 0;
|
||||
const remain = Math.max(0, Math.floor(future_ts - now));
|
||||
const remainStr = remain > 0 ? `${Math.floor(remain / 60)}分${remain % 60}秒后` : "已到开奖时间";
|
||||
const safePrizeValue = Number.isFinite(Number(item.prize_value_yuan))
|
||||
? Number(item.prize_value_yuan)
|
||||
: 0;
|
||||
const safePosSeen = Number.isFinite(Number(item.pos_seen)) ? Number(item.pos_seen) : 0;
|
||||
// 60s 内开奖:高亮提醒
|
||||
if (remain > 0 && remain <= 60) card.classList.add("isImminent");
|
||||
else if (remain === 0) card.classList.add("isDue");
|
||||
@@ -534,13 +324,13 @@ async function pollReservations() {
|
||||
card.innerHTML = `
|
||||
<div class="reservationHeader">
|
||||
<span class="reservationIndex">#${idx + 1}</span>
|
||||
<span class="reservationValue">${item.prize_value_yuan || 0}元</span>
|
||||
<span class="reservationValue">${safePrizeValue}元</span>
|
||||
</div>
|
||||
<div class="reservationBody">
|
||||
<div><strong>内容:</strong>${escapeHtml(item.content || '-')}</div>
|
||||
<div><strong>开奖时间:</strong>${item.future_str || '-'}</div>
|
||||
<div><strong>开奖时间:</strong>${escapeHtml(item.future_str || '-')}</div>
|
||||
<div><strong>剩余时间:</strong><span class="reservationRemain">${remainStr}</span></div>
|
||||
<div><strong>发现位置:</strong>${item.pos_seen || 0}</div>
|
||||
<div><strong>发现位置:</strong>${safePosSeen}</div>
|
||||
<div><strong>直播间(清洗后):</strong>${escapeHtml(item.room_title || '-')}</div>
|
||||
<div><strong>直播间原文:</strong>${escapeHtml(item.room_title_raw || '-')}</div>
|
||||
</div>
|
||||
@@ -580,8 +370,9 @@ async function pollHighValueRooms() {
|
||||
|
||||
const info = document.createElement("div");
|
||||
info.className = "reservationsInfo";
|
||||
const safeTotal = Number.isFinite(Number(total)) ? Number(total) : 0;
|
||||
info.innerHTML = `
|
||||
<div><strong>记录数量:</strong>${total}</div>
|
||||
<div><strong>记录数量:</strong>${safeTotal}</div>
|
||||
<div class="hint">更新时间:${updated_ts > 0 ? new Date(updated_ts * 1000).toLocaleTimeString() : '-'}</div>
|
||||
<div class="hint">原因:${escapeHtml(reason || '-') }</div>
|
||||
`;
|
||||
@@ -650,14 +441,18 @@ async function pollHighValueRooms() {
|
||||
try {
|
||||
const btnExpand = $('hv_expand_all');
|
||||
const btnCollapse = $('hv_collapse_all');
|
||||
if (btnExpand) btnExpand.addEventListener('click', () => {
|
||||
const listEl = container.querySelector(`.${UI_CLASS.reservationsList}`);
|
||||
if (listEl) listEl.classList.remove(UI_CLASS.listCollapsed);
|
||||
});
|
||||
if (btnCollapse) btnCollapse.addEventListener('click', () => {
|
||||
const listEl = container.querySelector(`.${UI_CLASS.reservationsList}`);
|
||||
if (listEl) listEl.classList.add(UI_CLASS.listCollapsed);
|
||||
});
|
||||
if (btnExpand) {
|
||||
btnExpand.onclick = () => {
|
||||
const listEl = container.querySelector(`.${UI_CLASS.reservationsList}`);
|
||||
if (listEl) listEl.classList.remove(UI_CLASS.listCollapsed);
|
||||
};
|
||||
}
|
||||
if (btnCollapse) {
|
||||
btnCollapse.onclick = () => {
|
||||
const listEl = container.querySelector(`.${UI_CLASS.reservationsList}`);
|
||||
if (listEl) listEl.classList.add(UI_CLASS.listCollapsed);
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
// Device and test actions split from runtime_actions.js.
|
||||
|
||||
function selectedDeviceId() {
|
||||
const el = $("device");
|
||||
return el ? (el.value || "") : "";
|
||||
}
|
||||
|
||||
function renderWifiScanResults(resultsEl, devices) {
|
||||
if (!resultsEl) return;
|
||||
resultsEl.innerHTML = "";
|
||||
const title = document.createElement("div");
|
||||
title.style.marginBottom = "4px";
|
||||
title.style.color = "#555";
|
||||
title.textContent = "点击下方设备使用:";
|
||||
resultsEl.appendChild(title);
|
||||
for (const d of devices) {
|
||||
const row = document.createElement("div");
|
||||
row.style.margin = "4px 0";
|
||||
row.style.cursor = "pointer";
|
||||
row.style.padding = "4px 6px";
|
||||
row.style.border = "1px solid #ddd";
|
||||
row.style.borderRadius = "4px";
|
||||
row.dataset.target = String(d.target || "");
|
||||
row.dataset.state = String(d.state || "");
|
||||
const target = document.createElement("b");
|
||||
target.textContent = String(d.target || "");
|
||||
const state = document.createElement("span");
|
||||
const st = String(d.state || "");
|
||||
state.style.color = st === "connected" ? "#0a7d2c" : (st === "unauthorized" ? "#b35900" : "#888");
|
||||
state.textContent = ` [${st}]`;
|
||||
row.appendChild(target);
|
||||
row.appendChild(state);
|
||||
if (d.model) {
|
||||
const model = document.createElement("span");
|
||||
model.style.color = "#555";
|
||||
model.textContent = ` ${String(d.model)}`;
|
||||
row.appendChild(model);
|
||||
}
|
||||
resultsEl.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
async function postDeviceAction(path, body, successPrefix) {
|
||||
try {
|
||||
const result = await apiPost(path, body || {});
|
||||
const msg = result.message || result.output || result.error || "完成";
|
||||
appendLog([`${successPrefix}: ${msg}`]);
|
||||
if (!result.error) toast(`${successPrefix}: ${msg}`, "success");
|
||||
else toast(`${successPrefix}: ${msg}`, "warn");
|
||||
if (result.devices) await refreshDevices();
|
||||
return result;
|
||||
} catch (e) {
|
||||
appendLog([`${successPrefix}失败: ${e?.message || e}`]);
|
||||
toast(`${successPrefix}失败:${e?.message || e}`, "error", { duration: 5000 });
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async function forceStopRun() {
|
||||
await postDeviceAction("/api/force-stop", {}, "[WEB] 强制停止");
|
||||
}
|
||||
|
||||
async function sendBackKey() {
|
||||
const deviceId = selectedDeviceId();
|
||||
try {
|
||||
await postDeviceAction("/api/back-key", { device_id: deviceId }, "[WEB] 返回键");
|
||||
} catch (_) {
|
||||
// 错误已在 postDeviceAction 内展示,避免未捕获 Promise 冒泡到全局。
|
||||
}
|
||||
}
|
||||
|
||||
async function wifiEnable() {
|
||||
const deviceId = selectedDeviceId();
|
||||
if (!deviceId) {
|
||||
appendLog(["[WiFi ADB] 请先选择 USB 设备"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/enable", { device_id: deviceId }, "[WiFi ADB] 启用");
|
||||
setTextIfExists("wifiStatus", result.message || "已发送启用命令");
|
||||
}
|
||||
|
||||
async function wifiConnect() {
|
||||
const ip = ($("wifi_ip")?.value || "").trim();
|
||||
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
|
||||
if (!ip) {
|
||||
appendLog(["[WiFi ADB] 请填写设备 IP"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/connect", { ip, port }, "[WiFi ADB] 连接");
|
||||
setTextIfExists("wifiStatus", result.message || "连接命令已执行");
|
||||
}
|
||||
|
||||
async function wifiDisconnect() {
|
||||
const ip = ($("wifi_ip")?.value || selectedDeviceId() || "").trim();
|
||||
const port = ($("wifi_port")?.value || "5555").trim() || "5555";
|
||||
if (!ip) {
|
||||
appendLog(["[WiFi ADB] 请填写 IP 或选择 WiFi 设备"]);
|
||||
return;
|
||||
}
|
||||
const result = await postDeviceAction("/api/wifi/disconnect", { ip, port }, "[WiFi ADB] 断开");
|
||||
setTextIfExists("wifiStatus", result.message || "断开命令已执行");
|
||||
}
|
||||
|
||||
async function tryAutoReconnectLastWifi() {
|
||||
try {
|
||||
const resp = await apiPost("/api/wifi/auto-reconnect", {});
|
||||
if (!resp || resp.ok === false) return;
|
||||
const action = resp.action || "noop";
|
||||
if (action === "noop") return;
|
||||
|
||||
if (action === "already_online" || action === "reconnected" || action === "matched") {
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (_) {}
|
||||
const sel = $("device");
|
||||
if (sel && resp.target) {
|
||||
for (const opt of sel.options) {
|
||||
if (opt.value === resp.target) {
|
||||
sel.value = resp.target;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const status = $("wifiStatus");
|
||||
if (status && resp.message) status.textContent = resp.message;
|
||||
appendLog([`[启动] ${resp.message || action}`]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "failed") {
|
||||
appendLog([`[启动] ${resp.message || "WiFi 自动重连失败"}`]);
|
||||
const status = $("wifiStatus");
|
||||
if (status && resp.message) status.textContent = resp.message;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("auto-reconnect failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function wifiScan() {
|
||||
const btn = $("btnWifiScan");
|
||||
const status = $("wifiStatus");
|
||||
const results = $("wifiScanResults");
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = "扫描中...";
|
||||
}
|
||||
if (status) status.textContent = "正在扫描局域网...";
|
||||
if (results) {
|
||||
results.style.display = "none";
|
||||
results.innerHTML = "";
|
||||
}
|
||||
try {
|
||||
const resp = await apiPost("/api/wifi/scan", {});
|
||||
if (!resp || resp.ok === false) {
|
||||
const err = (resp && resp.error) || "扫描失败";
|
||||
appendLog([`[WiFi ADB] 扫描失败: ${err}`]);
|
||||
if (status) status.textContent = `扫描失败: ${err}`;
|
||||
return;
|
||||
}
|
||||
const devs = Array.isArray(resp.devices) ? resp.devices : [];
|
||||
const subnet = resp.subnet || "";
|
||||
if (!devs.length) {
|
||||
appendLog([`[WiFi ADB] 扫描完成 (${subnet}),未发现开放 5555 端口的设备`]);
|
||||
if (status) status.textContent = `扫描完成 (${subnet}),未发现设备`;
|
||||
return;
|
||||
}
|
||||
appendLog([
|
||||
`[WiFi ADB] 扫描完成 (${subnet}),发现 ${devs.length} 台候选: ` +
|
||||
devs.map((d) => `${d.target}(${d.state})`).join(", "),
|
||||
]);
|
||||
|
||||
const connected = devs.filter((d) => d.state === "connected");
|
||||
if (connected.length === 1 && devs.length === 1) {
|
||||
const d = connected[0];
|
||||
const ipInput = $("wifi_ip");
|
||||
if (ipInput) ipInput.value = d.target;
|
||||
if (status)
|
||||
status.textContent =
|
||||
`已发现并连接 ${d.target}` + (d.model ? ` (${d.model})` : "") + ",已记住";
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (_) {}
|
||||
return;
|
||||
}
|
||||
|
||||
if (results) {
|
||||
results.style.display = "block";
|
||||
renderWifiScanResults(results, devs);
|
||||
results.querySelectorAll("[data-target]").forEach((el) => {
|
||||
el.addEventListener("click", () => {
|
||||
const target = el.getAttribute("data-target");
|
||||
const state = el.getAttribute("data-state");
|
||||
if (state !== "connected") {
|
||||
appendLog([
|
||||
`[WiFi ADB] ${target} 状态=${state},请先在手机上确认 ADB 调试授权`,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
const ipInput = $("wifi_ip");
|
||||
if (ipInput) ipInput.value = target;
|
||||
if (status) status.textContent = `已选 ${target}`;
|
||||
appendLog([`[WiFi ADB] 已选 ${target}`]);
|
||||
try {
|
||||
refreshDevices();
|
||||
} catch (_) {}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (status) status.textContent = `扫描完成,发现 ${devs.length} 台设备`;
|
||||
} catch (e) {
|
||||
appendLog([`[WiFi ADB] 扫描异常: ${e}`]);
|
||||
if (status) status.textContent = `扫描异常: ${e}`;
|
||||
} finally {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = "扫描 WiFi";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function testYanghao() {
|
||||
const deviceId = $("device").value || "";
|
||||
const seconds = parseInt($("yanghao_recommend_duration_seconds").value || "60", 10);
|
||||
await apiPost("/api/test-yanghao", { device_id: deviceId, seconds });
|
||||
appendLog([`[WEB] 已启动测试养号:device=${deviceId || UI_COPY.device.autoLabel} seconds=${seconds}`]);
|
||||
}
|
||||
|
||||
async function testComment() {
|
||||
const deviceId = $("device").value || "";
|
||||
const text = "";
|
||||
await apiPost("/api/test-comment", { device_id: deviceId, text });
|
||||
appendLog([`[WEB] 已启动测试评论:device=${deviceId || UI_COPY.device.autoLabel}${text ? ' text=自定义' : ''}`]);
|
||||
}
|
||||
Reference in new issue
Block a user