From 83f8c041dec72996af932d1e18833a295646cdce Mon Sep 17 00:00:00 2001 From: viarotel Date: Fri, 10 Nov 2023 13:50:55 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=99=BB=EF=B8=8F=20Optimize=20histori?= =?UTF-8?q?cal=20device=20connections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/components/Wireless/index.vue | 46 +++++++++++++++---- src/locales/languages/en_US.json | 2 + src/locales/languages/zh_CN.json | 2 + 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/components/Device/components/Wireless/index.vue b/src/components/Device/components/Wireless/index.vue index a86a6ab..3713b7c 100644 --- a/src/components/Device/components/Wireless/index.vue +++ b/src/components/Device/components/Wireless/index.vue @@ -112,13 +112,44 @@ export default { this.handleConnect() }, async handleBatch() { - for (let index = 0; index < this.wirelessList.length; index++) { - const item = this.wirelessList[index] - await this.handleConnect(item, { successTips: false }) + const totalCount = this.wirelessList.length + + let failCount = 0 + + const promises = [] + + for (let index = 0; index < totalCount; index++) { + const { host, port } = this.wirelessList[index] + + promises.push( + this.$adb.connect(host, port || 5555).catch(() => { + ++failCount + }), + ) } - this.$message.success(this.$t('device.wireless.connect.success')) + + this.loading = true + await Promise.allSettled(promises) + this.loading = false + + const successCount = totalCount - failCount + + if (successCount) { + this.$message({ + message: this.$t('device.wireless.connect.batch.success', { + totalCount, + successCount, + failCount, + }), + type: totalCount === successCount ? 'success' : 'warning', + }) + return + } + + this.$message.warning(this.$t('device.wireless.connect.batch.error')) }, - async handleConnect(params = this.formData, { successTips = true } = {}) { + + async handleConnect(params = this.formData) { if (!params.host) { this.$message.warning( this.$t('device.wireless.connect.error.no-address'), @@ -130,9 +161,8 @@ export default { try { await this.$adb.connect(params.host, params.port || 5555) - if (successTips) { - this.$message.success(this.$t('device.wireless.connect.success')) - } + + this.$message.success(this.$t('device.wireless.connect.success')) this.handleSave(params) } diff --git a/src/locales/languages/en_US.json b/src/locales/languages/en_US.json index f4c1ec3..a6b752f 100644 --- a/src/locales/languages/en_US.json +++ b/src/locales/languages/en_US.json @@ -42,6 +42,8 @@ "device.wireless.connect.error.no-address": "Wireless debug address cannot be empty", "device.wireless.connect.success": "Connect success", "device.wireless.connect.batch.name": "Connect all historical devices", + "device.wireless.connect.batch.success": "Connected {totalCount} historical devices, {successCount} succeeded, {failCount} failed", + "device.wireless.connect.batch.error": "Failed to connect historical devices", "device.wireless.disconnect.start": "Disconnect", "device.wireless.disconnect.progress": "Disconnecting", "device.wireless.disconnect.success": "Disconnected", diff --git a/src/locales/languages/zh_CN.json b/src/locales/languages/zh_CN.json index 47a7b4a..b5355bb 100644 --- a/src/locales/languages/zh_CN.json +++ b/src/locales/languages/zh_CN.json @@ -42,6 +42,8 @@ "device.wireless.connect.error.no-address": "无线调试地址不能为空", "device.wireless.connect.success": "连接设备成功", "device.wireless.connect.batch.name": "连接所有历史设备", + "device.wireless.connect.batch.success": "连接历史设备成功,共 {totalCount}个,成功 {successCount}个,失败 {failCount}个", + "device.wireless.connect.batch.error": "连接历史设备失败", "device.wireless.disconnect.start": "断开连接", "device.wireless.disconnect.progress": "正在断开", "device.wireless.disconnect.success": "断开连接成功",