diff --git a/electron/exposes/adb/helpers/adbConnectionMonitor/index.js b/electron/exposes/adb/helpers/adbConnectionMonitor/index.js index 60bee225..b02a5aab 100644 --- a/electron/exposes/adb/helpers/adbConnectionMonitor/index.js +++ b/electron/exposes/adb/helpers/adbConnectionMonitor/index.js @@ -1,5 +1,6 @@ import { Bonjour } from 'bonjour-service' import net from 'node:net' +import appStore from '$electron/helpers/store.js' export const MDNS_CONFIG = { PAIRING_TYPE: 'adb-tls-pairing', @@ -78,6 +79,7 @@ export class AdbConnectionMonitor { this.deviceScanner = new DeviceScanner() this.isActive = false this.adb = null + this.onStatus = () => {} } async startQrCodeScanning(options) { @@ -87,20 +89,38 @@ export class AdbConnectionMonitor { adb, password, onStatus = () => {}, - onError = () => {}, } = options this.adb = adb this.isActive = true + this.onStatus = onStatus try { - const device = await this.scanForDevice(onStatus) + this.onStatus('pairing') + const device = await this.scanForDevice() await this.pairWithDevice(device, password) - onStatus('Paired successfully, waiting to connect...') - const connectDevice = await this.waitForDeviceConnect(device) - console.log('connectDevice', connectDevice) - await this.connectToDevice(connectDevice) + this.onStatus('connecting') + try { + const connectDevice = await this.waitForDeviceConnect(device) + await this.connectToDevice(connectDevice) + } + catch (error) { + if (error.code === ERROR_CODES.TIMEOUT) { + this.onStatus('connecting-fallback') + // 使用回退端口尝试连接 + const fallbackPort = this.getBackPort(device) + await this.connectToDevice({ + ...device, + port: fallbackPort, + }) + } + else { + throw error + } + } + + this.onStatus('connected') return { success: true, @@ -108,7 +128,8 @@ export class AdbConnectionMonitor { } } catch (error) { - onError(error.message) + this.onStatus('error', error.message) + return { success: false, error: error.message, @@ -134,9 +155,7 @@ export class AdbConnectionMonitor { } } - async scanForDevice(onStatus) { - onStatus('Waiting for device to scan QR code...') - + async scanForDevice() { return new Promise((resolve, reject) => { const timeoutHandle = setTimeout(() => { this.dispose() @@ -205,6 +224,19 @@ export class AdbConnectionMonitor { } } + getBackPort(device) { + const devices = appStore.get('device') + + const value = Object.entries(devices).reduce((port, [key, value]) => { + if (key.includes(device.address)) { + port = key.split(':')[1] + } + return port + }, 5555) + + return value + } + dispose() { this.deviceScanner.dispose() this.isActive = false diff --git a/electron/exposes/adb/index.js b/electron/exposes/adb/index.js index 20d990d7..3ec92827 100644 --- a/electron/exposes/adb/index.js +++ b/electron/exposes/adb/index.js @@ -271,13 +271,14 @@ async function pair(host, port, code) { return shell(`pair ${host}:${port} ${code}`) } -async function connectCode(password) { +async function connectCode(password, options = {}) { return adbConnectionMonitor.startQrCodeScanning({ password, adb: { pair, connect, }, + ...options }) } diff --git a/electron/resources/extra/win/scrcpy/icon.png b/electron/resources/extra/win/scrcpy/icon.png new file mode 100755 index 00000000..22bb69ff Binary files /dev/null and b/electron/resources/extra/win/scrcpy/icon.png differ diff --git a/package.json b/package.json index ba75b38a..dc592a35 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "fs-extra": "11.2.0", "husky": "9.0.11", "lodash-es": "4.17.21", - "multicast-dns": "^7.2.5", "nanoid": "5.0.7", "pinia": "2.1.7", "pinia-plugin-persistedstate": "3.2.1", diff --git a/src/locales/languages/en-US.json b/src/locales/languages/en-US.json index f3002dbf..5f5aad64 100644 --- a/src/locales/languages/en-US.json +++ b/src/locales/languages/en-US.json @@ -27,6 +27,7 @@ "common.warning": "Warning", "common.info": "Message", "common.danger": "Error", + "common.connecting": "Connecting", "common.language.name": "Language", "common.language.placeholder": "Select language", @@ -62,6 +63,10 @@ "device.remark": "Remark", "device.permission.error": "Device permission error, please reconnect device and allow USB debugging", "device.terminal.name": "Terminal", + "device.status": "Status", + "device.status.connected": "Connected", + "device.status.offline": "Offline", + "device.status.unauthorized": "Unauthorized", "device.task.name": "Scheduled Task", "device.task.tips": " Note: Please ensure that your computer stays awake, otherwise scheduled tasks will not be executed properly.", @@ -83,6 +88,11 @@ "device.wireless.name": "Wireless", "device.wireless.mode": "Wireless", "device.wireless.mode.error": "Do not get the local area network connection address, please check the network", + "device.wireless.connect.qr": "QR Code Connection", + "device.wireless.connect.qr.pairing": "Pairing", + "device.wireless.connect.qr.connecting": "Connecting", + "device.wireless.connect.qr.connected": "Connection Successful", + "device.wireless.connect.qr.error": "QR Code Connection", "device.wireless.connect.name": "Connect", "device.wireless.connect.error.title": "Connect failed", "device.wireless.connect.error.detail": "Error details", diff --git a/src/locales/languages/ru-RU.json b/src/locales/languages/ru-RU.json index 38d0bb30..fbda2115 100644 --- a/src/locales/languages/ru-RU.json +++ b/src/locales/languages/ru-RU.json @@ -27,6 +27,7 @@ "common.warning": "Предупреждение", "common.info": "Сообщение", "common.danger": "Ошибка", + "common.connecting": "Подключение", "common.language.name": "Язык", "common.language.placeholder": "Выберите язык", @@ -62,6 +63,10 @@ "device.remark": "Примечание", "device.permission.error": "Ошибка разрешения устройства, пожалуйста, переподключите устройство и разрешите отладку по USB", "device.terminal.name": "Терминал", + "device.status": "Статус", + "device.status.connected": "Подключено", + "device.status.offline": "Не в сети", + "device.status.unauthorized": "Не авторизован", "device.task.name": "Запланированная задача", "device.task.tips": "Примечание: Пожалуйста, убедитесь, что ваш компьютер не переходит в спящий режим, иначе запланированные задачи не будут выполнены правильно.", @@ -83,6 +88,11 @@ "device.wireless.name": "По WiFi", "device.wireless.mode": "беспроводной", "device.wireless.mode.error": "Не удалось получить адрес подключения локальной сети, проверьте сеть", + "device.wireless.connect.qr": "Подключение по QR-коду", + "device.wireless.connect.qr.pairing": "Сопряжение", + "device.wireless.connect.qr.connecting": "Подключение", + "device.wireless.connect.qr.connected": "Подключение успешно", + "device.wireless.connect.qr.error": "Подключение по QR-коду", "device.wireless.connect.name": "Подключиться", "device.wireless.connect.error.title": "Не удалось подключиться", "device.wireless.connect.error.detail": "Детали ошибки", diff --git a/src/locales/languages/zh-CN.json b/src/locales/languages/zh-CN.json index 8548943f..9c360435 100644 --- a/src/locales/languages/zh-CN.json +++ b/src/locales/languages/zh-CN.json @@ -89,6 +89,10 @@ "device.wireless.mode": "无线模式", "device.wireless.mode.error": "没有获取到局域网连接地址,请检查网络", "device.wireless.connect.qr": "二维码连接", + "device.wireless.connect.qr.pairing": "配对中", + "device.wireless.connect.qr.connecting": "连接中", + "device.wireless.connect.qr.connected": "连接成功", + "device.wireless.connect.qr.error": "二维码连接", "device.wireless.connect.name": "连接设备", "device.wireless.connect.error.title": "连接设备失败", "device.wireless.connect.error.detail": "错误详情", diff --git a/src/locales/languages/zh-TW.json b/src/locales/languages/zh-TW.json index f82d42f3..cc4c2510 100644 --- a/src/locales/languages/zh-TW.json +++ b/src/locales/languages/zh-TW.json @@ -27,6 +27,7 @@ "common.warning": "警告", "common.info": "消息", "common.danger": "錯誤", + "common.connecting": "連接中", "common.language.name": "語言", "common.language.placeholder": "選擇你要的語言", @@ -62,6 +63,10 @@ "device.remark": "備註", "device.permission.error": "裝置權限錯誤,請重新連接裝置並允許 USB 偵錯", "device.terminal.name": "終端偵錯", + "device.status": "狀態", + "device.status.connected": "已連接", + "device.status.offline": "已離線", + "device.status.unauthorized": "未授權", "device.task.name": "計劃任務", "device.task.tips": "注意:請確保您的電腦保持唤醒状态,否則計劃任務將無法正常執行。", @@ -83,6 +88,11 @@ "device.wireless.name": "無線", "device.wireless.mode": "無線模式", "device.wireless.mode.error": "未取得區域網路連接位址,請檢查網路", + "device.wireless.connect.qr": "二維碼連接", + "device.wireless.connect.qr.pairing": "配對中", + "device.wireless.connect.qr.connecting": "連接中", + "device.wireless.connect.qr.connected": "連接成功", + "device.wireless.connect.qr.error": "二維碼連接", "device.wireless.connect.name": "連接裝置", "device.wireless.connect.error.title": "連接裝置失敗", "device.wireless.connect.error.detail": "錯誤詳細資訊", diff --git a/src/pages/device/components/DevicePopover/index.vue b/src/pages/device/components/DevicePopover/index.vue index c64c3c4a..f1a6c7d4 100644 --- a/src/pages/device/components/DevicePopover/index.vue +++ b/src/pages/device/components/DevicePopover/index.vue @@ -2,7 +2,7 @@ @@ -10,7 +10,7 @@ - + {{ device.id }} diff --git a/src/pages/device/components/RemoveAction/index.vue b/src/pages/device/components/RemoveAction/index.vue new file mode 100644 index 00000000..fcf09759 --- /dev/null +++ b/src/pages/device/components/RemoveAction/index.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/src/pages/device/components/WirelessGroup/QrAction/index.vue b/src/pages/device/components/WirelessGroup/QrAction/index.vue index 754aa2d6..40ebd5ff 100644 --- a/src/pages/device/components/WirelessGroup/QrAction/index.vue +++ b/src/pages/device/components/WirelessGroup/QrAction/index.vue @@ -14,7 +14,7 @@ class="flex-none !border-none" @click="handleClick" > - {{ loading ? $t('common.connecting') : $t('device.wireless.connect.qr') }} + {{ loading ? loadingText : $t('device.wireless.connect.qr') }} @@ -24,6 +24,7 @@