fix: 修复 Wi-Fi ADB 拔线后刷新丢失 (#27)
This commit is contained in:
@@ -266,6 +266,7 @@ class SettingsPageEventBinder(QObject):
|
||||
self._worker: Optional[CurrentClientSaveWorker] = None
|
||||
self._search_busy = False
|
||||
self._search_restore_serial = ""
|
||||
self._search_is_startup_restore = False
|
||||
self._search_thread: Optional[QThread] = None
|
||||
self._search_worker: Optional[AndroidDeviceSearchWorker] = None
|
||||
self._wifi_conversion_busy = False
|
||||
@@ -406,15 +407,27 @@ class SettingsPageEventBinder(QObject):
|
||||
|
||||
@pyqtSlot()
|
||||
def _start_search(self) -> None:
|
||||
self._start_search_worker()
|
||||
restore_serial = (
|
||||
self._saved_android_serial
|
||||
if ":" in self._saved_android_serial
|
||||
else ""
|
||||
)
|
||||
self._start_search_worker(restore_serial)
|
||||
|
||||
@pyqtSlot()
|
||||
def _request_restore_saved_android_device(self) -> None:
|
||||
if not self._saved_android_serial:
|
||||
return
|
||||
self._start_search_worker(self._saved_android_serial)
|
||||
self._start_search_worker(
|
||||
self._saved_android_serial,
|
||||
is_startup_restore=True,
|
||||
)
|
||||
|
||||
def _start_search_worker(self, restore_serial: str = "") -> None:
|
||||
def _start_search_worker(
|
||||
self,
|
||||
restore_serial: str = "",
|
||||
is_startup_restore: bool = False,
|
||||
) -> None:
|
||||
if (
|
||||
self._closing
|
||||
or self._busy
|
||||
@@ -427,12 +440,14 @@ class SettingsPageEventBinder(QObject):
|
||||
|
||||
self._search_busy = True
|
||||
self._search_restore_serial = restore_serial
|
||||
self._search_is_startup_restore = is_startup_restore
|
||||
self._sync_button_state()
|
||||
status = (
|
||||
f"正在恢复已保存设备:{restore_serial}…"
|
||||
if restore_serial
|
||||
else "正在搜索 Android 设备…"
|
||||
)
|
||||
if is_startup_restore:
|
||||
status = f"正在恢复已保存设备:{restore_serial}…"
|
||||
elif restore_serial:
|
||||
status = f"正在重新连接已保存 Wi-Fi 设备:{restore_serial}…"
|
||||
else:
|
||||
status = "正在搜索 Android 设备…"
|
||||
self._page.deviceStatusLabel.setText(status)
|
||||
|
||||
thread = QThread(self)
|
||||
@@ -726,11 +741,26 @@ class SettingsPageEventBinder(QObject):
|
||||
self._page.deviceTableModel.set_checked_serial(
|
||||
self._saved_android_serial
|
||||
)
|
||||
action = "恢复完成" if self._search_restore_serial else "搜索完成"
|
||||
action = (
|
||||
"恢复完成"
|
||||
if self._search_is_startup_restore
|
||||
else "搜索完成"
|
||||
)
|
||||
self._page.deviceStatusLabel.setText(
|
||||
f"{action}:找到 {len(rows)} 台 Android 设备;"
|
||||
"已自动选择当前使用设备"
|
||||
)
|
||||
elif saved_device is not None and saved_device.status == "unauthorized":
|
||||
self._page.deviceStatusLabel.setText(
|
||||
"已重新连接 Wi-Fi 设备,但尚未授权:"
|
||||
f"{self._saved_android_serial};请在手机上允许调试后重试"
|
||||
)
|
||||
elif saved_device is not None:
|
||||
self._page.deviceStatusLabel.setText(
|
||||
"已保存设备当前不可用:"
|
||||
f"{self._saved_android_serial}({saved_device.status});"
|
||||
"配置已保留"
|
||||
)
|
||||
elif self._saved_android_serial:
|
||||
self._page.deviceStatusLabel.setText(
|
||||
"已保存设备当前未连接:"
|
||||
@@ -749,11 +779,16 @@ class SettingsPageEventBinder(QObject):
|
||||
def _on_search_failed(self, message: str) -> None:
|
||||
if self._closing:
|
||||
return
|
||||
if self._search_restore_serial:
|
||||
if self._search_is_startup_restore:
|
||||
self._page.deviceStatusLabel.setText(
|
||||
f"自动恢复失败:{message};已保存配置未更改,"
|
||||
"可点击搜索重试"
|
||||
)
|
||||
elif self._search_restore_serial:
|
||||
self._page.deviceStatusLabel.setText(
|
||||
f"搜索失败:无法重新连接已保存 Wi-Fi 设备;{message};"
|
||||
"已保存配置未更改,可重试"
|
||||
)
|
||||
else:
|
||||
self._page.deviceStatusLabel.setText(
|
||||
f"搜索失败:{message};设备列表和已保存配置未更改"
|
||||
@@ -765,6 +800,7 @@ class SettingsPageEventBinder(QObject):
|
||||
self._search_thread = None
|
||||
self._search_busy = False
|
||||
self._search_restore_serial = ""
|
||||
self._search_is_startup_restore = False
|
||||
if not self._closing:
|
||||
self._sync_button_state()
|
||||
|
||||
@@ -792,7 +828,7 @@ class SettingsPageEventBinder(QObject):
|
||||
self._page.deviceTableModel.set_checked_serial(result.wifi_serial)
|
||||
self._page.deviceStatusLabel.setText(
|
||||
f"Wi-Fi 设备 {result.wifi_serial} 已连接并勾选;"
|
||||
"请确认后点击保存,仅在可信网络使用"
|
||||
"请确认后点击保存,再拔掉 USB 数据线"
|
||||
)
|
||||
|
||||
@pyqtSlot(str)
|
||||
|
||||
Reference in New Issue
Block a user