perf: 🚀 Optimize batch operation interaction

This commit is contained in:
viarotel 2024-07-13 23:26:23 +08:00
parent 2f389af834
commit 343eab2e11
11 changed files with 109 additions and 42 deletions

View File

@ -50,9 +50,22 @@ export default {
this.loading = true this.loading = true
const closeMessage = this.$message.loading(
this.$t('device.control.install.progress', {
deviceName: window.t('common.device'),
}),
).close
await allSettledWrapper(this.devices, (item) => { await allSettledWrapper(this.devices, (item) => {
return this.$refs.applicationProxyRef.invoke(item, { files }) return this.$refs.applicationProxyRef.invoke(item, {
files,
silent: true,
}) })
})
closeMessage()
ElMessage.success(window.t('common.success.batch'))
this.loading = false this.loading = false
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<el-dropdown :hide-on-click="false"> <el-dropdown :hide-on-click="false" :disabled="loading">
<div class=""> <div class="">
<slot :loading="loading" /> <slot :loading="loading" />
<FileManageProxy ref="fileManageProxyRef" /> <FileManageProxy ref="fileManageProxyRef" />
@ -58,10 +58,16 @@ async function handlePush(devices) {
loading.value = true loading.value = true
const closeMessage = ElMessage.loading(
window.t('device.control.file.push.loading'),
).close
await allSettledWrapper(devices, (item) => { await allSettledWrapper(devices, (item) => {
return fileManageProxyRef.value.handlePush(item, { files }) return fileManageProxyRef.value.handlePush(item, { files, silent: true })
}) })
closeMessage()
ElMessage.success(window.t('common.success.batch')) ElMessage.success(window.t('common.success.batch'))
loading.value = false loading.value = false

View File

@ -28,10 +28,20 @@ export default {
async handleClick() { async handleClick() {
this.loading = true this.loading = true
const closeMessage = this.$message.loading(
window.t('device.control.capture.progress', {
deviceName: window.t('common.device'),
}),
).close
await allSettledWrapper(this.devices, (item) => { await allSettledWrapper(this.devices, (item) => {
return this.$refs.screenshotProxyRef.invoke(item) return this.$refs.screenshotProxyRef.invoke(item, { silent: true })
}) })
closeMessage()
ElMessage.success(window.t('common.success.batch'))
this.loading = false this.loading = false
}, },
}, },

View File

@ -42,13 +42,16 @@ async function handleClick(devices) {
loading.value = true loading.value = true
const closeLoading = ElMessage.loading(
window.t('device.control.shell.push.loading'),
).close
const failFiles = [] const failFiles = []
await allSettledWrapper(devices, async (device) => { await allSettledWrapper(devices, async (device) => {
const successFiles = await selectAndSendFileToDevice(device.id, { const successFiles = await selectAndSendFileToDevice(device.id, {
files, files,
loadingText: window.t('device.control.shell.push.loading'), silent: true,
successText: window.t('device.control.shell.push.success'),
}).catch((e) => { }).catch((e) => {
console.warn(e.message) console.warn(e.message)
failFiles.push(e.message) failFiles.push(e.message)
@ -74,6 +77,8 @@ async function handleClick(devices) {
return false return false
} }
closeLoading()
await ElMessage.success(window.t('device.control.shell.success')) await ElMessage.success(window.t('device.control.shell.success'))
loading.value = false loading.value = false

View File

@ -24,7 +24,7 @@ export default {
preferenceData(...args) { preferenceData(...args) {
return this.$store.preference.getData(...args) return this.$store.preference.getData(...args)
}, },
async handleInstall(device, { files } = {}) { async handleInstall(device, { files, silent = false } = {}) {
if (!files) { if (!files) {
try { try {
files = await this.$electron.ipcRenderer.invoke('show-open-dialog', { files = await this.$electron.ipcRenderer.invoke('show-open-dialog', {
@ -47,11 +47,14 @@ export default {
} }
} }
const messageEl = this.$message.loading( let closeLoading = null
if (!silent) {
closeLoading = this.$message.loading(
this.$t('device.control.install.progress', { this.$t('device.control.install.progress', {
deviceName: this.$store.device.getLabel(device), deviceName: this.$store.device.getLabel(device),
}), }),
) ).close
}
let failCount = 0 let failCount = 0
@ -62,7 +65,11 @@ export default {
}) })
}) })
messageEl.close() if (silent) {
return false
}
closeLoading()
const totalCount = files.length const totalCount = files.length
const successCount = totalCount - failCount const successCount = totalCount - failCount

View File

@ -32,7 +32,7 @@ const deviceStore = useDeviceStore()
const loading = ref(false) const loading = ref(false)
async function handlePush(device, { files } = {}) { async function handlePush(device, { files, silent = false } = {}) {
if (!files) { if (!files) {
try { try {
files = await window.electron.ipcRenderer.invoke('show-open-dialog', { files = await window.electron.ipcRenderer.invoke('show-open-dialog', {
@ -58,10 +58,15 @@ async function handlePush(device, { files } = {}) {
loading.value = true loading.value = true
const closeMessage = ElMessage.loading( let closeLoading
window.t('device.control.file.push.loading'),
{ grouping: true }, if (!silent) {
closeLoading = ElMessage.loading(
`${deviceStore.getLabel(device)}: ${window.t(
'device.control.file.push.loading',
)}`,
).close ).close
}
let failCount = 0 let failCount = 0
@ -73,11 +78,15 @@ async function handlePush(device, { files } = {}) {
loading.value = false loading.value = false
if (silent) {
return false
}
const totalCount = files.length const totalCount = files.length
const successCount = totalCount - failCount const successCount = totalCount - failCount
if (successCount) { if (successCount) {
closeMessage() closeLoading()
if (totalCount > 1) { if (totalCount > 1) {
ElMessage.success( ElMessage.success(
@ -100,7 +109,7 @@ async function handlePush(device, { files } = {}) {
return false return false
} }
closeMessage() closeLoading()
ElMessage.warning(window.t('device.control.file.push.error')) ElMessage.warning(window.t('device.control.file.push.error'))
} }

View File

@ -22,12 +22,15 @@ export default {
preferenceData(...args) { preferenceData(...args) {
return this.$store.preference.getData(...args) return this.$store.preference.getData(...args)
}, },
async handleCapture(device) { async handleCapture(device, { silent = false } = {}) {
const messageEl = this.$message.loading( let closeLoading
if (!silent) {
closeLoading = this.$message.loading(
this.$t('device.control.capture.progress', { this.$t('device.control.capture.progress', {
deviceName: this.$store.device.getLabel(device), deviceName: this.$store.device.getLabel(device),
}), }),
) ).close
}
const fileName = this.$store.device.getLabel( const fileName = this.$store.device.getLabel(
device, device,
@ -39,18 +42,21 @@ export default {
try { try {
await this.$adb.screencap(device.id, { savePath }) await this.$adb.screencap(device.id, { savePath })
await this.handleSuccess(savePath)
} }
catch (error) { catch (error) {
if (error.message) { if (error.message) {
this.$message.warning(error.message) this.$message.warning(error.message)
} }
return false
} }
messageEl.close() if (silent) {
}, return false
async handleSuccess(savePath) { }
return this.$message.success(
closeLoading()
this.$message.success(
`${this.$t( `${this.$t(
'device.control.capture.success.message.title', 'device.control.capture.success.message.title',
)}: ${savePath}`, )}: ${savePath}`,

View File

@ -12,6 +12,7 @@
"common.loading": "Loading", "common.loading": "Loading",
"common.search": "Search", "common.search": "Search",
"common.batch": "Batch", "common.batch": "Batch",
"common.device": "Device",
"common.language.name": "Language", "common.language.name": "Language",
"common.language.placeholder": "Select language", "common.language.placeholder": "Select language",
@ -100,7 +101,7 @@
"device.control.file.name": "File Manager", "device.control.file.name": "File Manager",
"device.control.file.push": "Push File", "device.control.file.push": "Push File",
"device.control.file.push.placeholder": "Please select the file to push", "device.control.file.push.placeholder": "Please select the file to push",
"device.control.file.push.loading": "Push file", "device.control.file.push.loading": "Push file...",
"device.control.file.push.success.name": "Push files successfully", "device.control.file.push.success.name": "Push files successfully",
"device.control.file.push.success": "Successfully pushed {totalCount} files to the /sdcard/Download/ directory of {deviceName}, {successCount} succeeded, and {failCount} failed", "device.control.file.push.success": "Successfully pushed {totalCount} files to the /sdcard/Download/ directory of {deviceName}, {successCount} succeeded, and {failCount} failed",
"device.control.file.push.success.single": "Files successfully pushed to the /sdcard/Download/ directory of {deviceName}", "device.control.file.push.success.single": "Files successfully pushed to the /sdcard/Download/ directory of {deviceName}",
@ -108,7 +109,7 @@
"device.control.shell.name": "Execute Script", "device.control.shell.name": "Execute Script",
"device.control.shell.tips": "Perform custom script through the ADB command", "device.control.shell.tips": "Perform custom script through the ADB command",
"device.control.shell.select": "Please select the script you want to execute", "device.control.shell.select": "Please select the script you want to execute",
"device.control.shell.push.loading": "Push script", "device.control.shell.push.loading": "Push script...",
"device.control.shell.push.success": "Push script success", "device.control.shell.push.success": "Push script success",
"device.control.shell.enter": "Please enter the Enter key to confirm the execution of the script", "device.control.shell.enter": "Please enter the Enter key to confirm the execution of the script",
"device.control.shell.success": "Script execution successfully", "device.control.shell.success": "Script execution successfully",

View File

@ -12,6 +12,7 @@
"common.loading": "加载中", "common.loading": "加载中",
"common.search": "搜索", "common.search": "搜索",
"common.batch": "批量", "common.batch": "批量",
"common.device": "设备",
"common.language.name": "语言", "common.language.name": "语言",
"common.language.placeholder": "选择你需要的语言", "common.language.placeholder": "选择你需要的语言",
@ -100,7 +101,7 @@
"device.control.file.name": "文件管理", "device.control.file.name": "文件管理",
"device.control.file.push": "推送文件", "device.control.file.push": "推送文件",
"device.control.file.push.placeholder": "请选择要推送的文件", "device.control.file.push.placeholder": "请选择要推送的文件",
"device.control.file.push.loading": "推送文件中", "device.control.file.push.loading": "推送文件中...",
"device.control.file.push.success.name": "推送文件成功", "device.control.file.push.success.name": "推送文件成功",
"device.control.file.push.success": "已成功将 {totalCount} 个文件推送到 {deviceName} 的 /sdcard/Download/ 目录,{successCount} 成功,{failCount} 失败。", "device.control.file.push.success": "已成功将 {totalCount} 个文件推送到 {deviceName} 的 /sdcard/Download/ 目录,{successCount} 成功,{failCount} 失败。",
"device.control.file.push.success.single": "文件已成功推送到 {deviceName} 的 /sdcard/Download/ 目录", "device.control.file.push.success.single": "文件已成功推送到 {deviceName} 的 /sdcard/Download/ 目录",
@ -108,7 +109,7 @@
"device.control.shell.name": "执行脚本", "device.control.shell.name": "执行脚本",
"device.control.shell.tips": "通过 ADB 命令执行自定义脚本", "device.control.shell.tips": "通过 ADB 命令执行自定义脚本",
"device.control.shell.select": "请选择要执行的脚本", "device.control.shell.select": "请选择要执行的脚本",
"device.control.shell.push.loading": "推送脚本中", "device.control.shell.push.loading": "推送脚本中...",
"device.control.shell.push.success": "推送脚本成功", "device.control.shell.push.success": "推送脚本成功",
"device.control.shell.enter": "请输入回车键确认执行该脚本", "device.control.shell.enter": "请输入回车键确认执行该脚本",
"device.control.shell.success": "脚本执行成功", "device.control.shell.success": "脚本执行成功",

View File

@ -12,6 +12,7 @@
"common.loading": "載入中", "common.loading": "載入中",
"common.search": "搜尋", "common.search": "搜尋",
"common.batch": "批量", "common.batch": "批量",
"common.device": "裝置",
"common.language.name": "語言", "common.language.name": "語言",
"common.language.placeholder": "選擇你要的語言", "common.language.placeholder": "選擇你要的語言",
@ -100,7 +101,7 @@
"device.control.file.name": "檔案管理", "device.control.file.name": "檔案管理",
"device.control.file.push": "推送檔案", "device.control.file.push": "推送檔案",
"device.control.file.push.placeholder": "請選擇要推送的檔案", "device.control.file.push.placeholder": "請選擇要推送的檔案",
"device.control.file.push.loading": "推送檔案中", "device.control.file.push.loading": "推送檔案中...",
"device.control.file.push.success.name": "推送檔案成功", "device.control.file.push.success.name": "推送檔案成功",
"device.control.file.push.success": "已成功將 {totalCount} 個檔案推送到 {deviceName} 的 /sdcard/Download/ 目錄,{successCount} 成功,{failCount} 失敗。", "device.control.file.push.success": "已成功將 {totalCount} 個檔案推送到 {deviceName} 的 /sdcard/Download/ 目錄,{successCount} 成功,{failCount} 失敗。",
"device.control.file.push.success.single": "檔案已成功推送到 {deviceName} 的 /sdcard/Download/ 目錄", "device.control.file.push.success.single": "檔案已成功推送到 {deviceName} 的 /sdcard/Download/ 目錄",
@ -108,7 +109,7 @@
"device.control.shell.name": "執行腳本", "device.control.shell.name": "執行腳本",
"device.control.shell.tips": "透過 ADB 命令執行自訂腳本", "device.control.shell.tips": "透過 ADB 命令執行自訂腳本",
"device.control.shell.select": "請選擇要執行的腳本", "device.control.shell.select": "請選擇要執行的腳本",
"device.control.shell.push.loading": "推送腳本中", "device.control.shell.push.loading": "推送腳本中...",
"device.control.shell.push.success": "推送腳本成功", "device.control.shell.push.success": "推送腳本成功",
"device.control.shell.enter": "請輸入回車鍵確認執行該腳本", "device.control.shell.enter": "請輸入回車鍵確認執行該腳本",
"device.control.shell.success": "腳本執行成功", "device.control.shell.success": "腳本執行成功",

View File

@ -1,5 +1,5 @@
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { allSettledWrapper } from '$/utils' import { allSettledWrapper, sleep } from '$/utils'
/** /**
* 选择并将文件发送到设备 * 选择并将文件发送到设备
*/ */
@ -8,6 +8,7 @@ export async function selectAndSendFileToDevice(
{ {
files, files,
multiSelections = false, multiSelections = false,
silent = false,
extensions = ['*'], extensions = ['*'],
selectText = window.t('device.control.file.push.placeholder'), selectText = window.t('device.control.file.push.placeholder'),
loadingText = window.t('device.control.file.push.loading'), loadingText = window.t('device.control.file.push.loading'),
@ -37,7 +38,10 @@ export async function selectAndSendFileToDevice(
} }
} }
const closeMessage = ElMessage.loading(loadingText).close let closeLoading
if (!silent) {
closeLoading = ElMessage.loading(`${deviceId}: ${loadingText}`).close
}
const successFiles = [] const successFiles = []
const failFiles = [] const failFiles = []
@ -53,14 +57,18 @@ export async function selectAndSendFileToDevice(
} }
}) })
await sleep()
if (failFiles.length) { if (failFiles.length) {
closeMessage() closeLoading?.()
throw new Error(`Push file failed: ${failFiles.join(',')}`) throw new Error(`Push file failed: ${failFiles.join(',')}`)
} }
closeMessage() closeLoading?.()
if (!silent) {
ElMessage.success({ message: successText, grouping: true }) ElMessage.success({ message: successText, grouping: true })
}
return successFiles return successFiles
} }