perf: ♻️ Optimize historical device connections

This commit is contained in:
viarotel 2023-11-10 13:50:55 +08:00
parent 4b99a6d97d
commit 83f8c041de
3 changed files with 42 additions and 8 deletions

View File

@ -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)
}

View File

@ -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",

View File

@ -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": "断开连接成功",