Skip to content

Commit

Permalink
perf: ♻️ Optimize historical device connections
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Nov 10, 2023
1 parent 4b99a6d commit 83f8c04
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/components/Device/components/Wireless/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions src/locales/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/languages/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "断开连接成功",
Expand Down

0 comments on commit 83f8c04

Please sign in to comment.