Skip to content

Commit

Permalink
perf: 🚀 Optimize device connection experience
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Dec 20, 2024
1 parent c214e5a commit 0690f2d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/locales/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
"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: 0 additions & 2 deletions src/locales/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
"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
2 changes: 0 additions & 2 deletions src/locales/languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
"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
2 changes: 0 additions & 2 deletions src/locales/languages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@
"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
64 changes: 37 additions & 27 deletions src/pages/device/components/WirelessGroup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export default {
host: void 0,
port: void 0,
},
firstFlag: true,
}
},
computed: {
Expand Down Expand Up @@ -131,8 +133,41 @@ export default {
},
},
},
watch: {
'wirelessList.length': {
handler(val) {
if (val) {
this.getFormData()
}
},
immediate: true,
},
},
async created() {
if (this.wirelessList?.length) {
const unwatch = this.$watch('wirelessList', async (val) => {
unwatch()
if (!val) {
return false
}
this.getFormData()
if (this.firstFlag) {
this.firstFlag = false
this.handleConnectAuto()
}
})
},
methods: {
async handleConnectAuto() {
const autoConnect = this.$store.preference.data.autoConnect
if (autoConnect) {
await this.handleBatch()
this.handleRefresh()
}
},
getFormData() {
const lastIndex = this.wirelessList.length - 1
const lastWireless = this.wirelessList[lastIndex]
Expand All @@ -143,16 +178,7 @@ export default {
id: `${lastWireless.host}:${lastWireless.port}`,
}
}
const autoConnect = this.$store.preference.data.autoConnect
if (autoConnect) {
await this.handleBatch()
this.handleRefresh()
}
}
},
methods: {
},
connect(...args) {
return this.handleConnect(...args)
},
Expand Down Expand Up @@ -233,22 +259,6 @@ export default {
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'))
},
handleUnConnect() {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/device/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

<div class="flex-none flex items-center py-1 overflow-x-auto py-2">
<div class="flex-none">
<WirelessGroup :key="deviceList.length" ref="wirelessGroupRef" v-bind="{ handleRefresh }" />
<WirelessGroup ref="wirelessGroupRef" v-bind="{ handleRefresh }" />
</div>

<div class="flex-1 w-0 space-x-2 flex items-center justify-end">
Expand Down
8 changes: 6 additions & 2 deletions src/store/device/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ export function mergeDevices(historyDevices, currentDevices) {
return obj
}, {})

const value = Object.values(defaultsDeep(currentMap, historyMap))
.sort((a, b) => sortModel[a.status] - sortModel[b.status])
const mergeList = Object.values(defaultsDeep(currentMap, historyMap))

const excludedKeywords = ['_adb-tls-connect', '_tcp']
const filterList = mergeList.filter(({ id = '' }) => !excludedKeywords.some(keyword => id.includes(keyword)))

const value = filterList.sort((a, b) => sortModel[a.status] - sortModel[b.status])

return value
}
Expand Down

0 comments on commit 0690f2d

Please sign in to comment.