fix: 🐛 Recording prompt and file format errors

This commit is contained in:
viarotel 2023-11-10 16:09:00 +08:00
parent 4a3575f8ed
commit bfdad9e8de
7 changed files with 81 additions and 39 deletions
src
components/Device
components/ControlBar
AppInstall
FileManage
Gnirehtet
MirrorGroup
Screenshot
index.vue
store/device

@ -48,7 +48,7 @@ export default {
const messageEl = this.$message({ const messageEl = this.$message({
message: this.$t('device.control.install.progress', { message: this.$t('device.control.install.progress', {
deviceName: device.$name, deviceName: this.$store.device.getLabel(device),
}), }),
icon: LoadingIcon, icon: LoadingIcon,
duration: 0, duration: 0,
@ -73,7 +73,7 @@ export default {
if (totalCount > 1) { if (totalCount > 1) {
this.$message.success( this.$message.success(
this.$t('device.control.install.success', { this.$t('device.control.install.success', {
deviceName: device.$name, deviceName: this.$store.device.getLabel(device),
totalCount, totalCount,
successCount, successCount,
failCount, failCount,
@ -83,7 +83,7 @@ export default {
else { else {
this.$message.success( this.$message.success(
this.$t('device.control.install.success.single', { this.$t('device.control.install.success.single', {
deviceName: device.$name, deviceName: this.$store.device.getLabel(device),
}), }),
) )
} }

@ -6,7 +6,9 @@
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item @click="handlePush"> <el-dropdown-item @click="handlePush">
{{ $t("device.control.file.push") }} <span class="" title="/sdcard/Download/">
{{ $t("device.control.file.push") }}
</span>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
@ -73,7 +75,7 @@ export default {
if (totalCount > 1) { if (totalCount > 1) {
this.$message.success( this.$message.success(
this.$t('device.control.file.push.success', { this.$t('device.control.file.push.success', {
deviceName: this.device.$name, deviceName: this.$store.device.getLabel(this.device),
totalCount, totalCount,
successCount, successCount,
failCount, failCount,
@ -83,7 +85,7 @@ export default {
else { else {
this.$message.success( this.$message.success(
this.$t('device.control.file.push.success.single', { this.$t('device.control.file.push.success.single', {
deviceName: this.device.$name, deviceName: this.$store.device.getLabel(this.device),
}), }),
) )
} }

@ -25,7 +25,14 @@ export default {
}, },
}, },
data() { data() {
return { return {}
},
created() {
if (!Object.hasOwnProperty.call(this.device, '$gnirehtetLoading')) {
Object.assign(this.device, {
$gnirehtetLoading: false,
$gnirehtetLoadingText: '',
})
} }
}, },
methods: { methods: {
@ -33,7 +40,9 @@ export default {
return this.$store.preference.getData(...args) return this.$store.preference.getData(...args)
}, },
async handleStart() { async handleStart() {
this.device.$gnirehtetLoadingText = this.$t('device.control.gnirehtet.running') this.device.$gnirehtetLoadingText = this.$t(
'device.control.gnirehtet.running',
)
this.device.$gnirehtetLoading = true this.device.$gnirehtetLoading = true
try { try {
@ -50,7 +59,9 @@ export default {
} }
}, },
async handleStop() { async handleStop() {
this.device.$gnirehtetLoadingText = this.$t('device.control.gnirehtet.stopping') this.device.$gnirehtetLoadingText = this.$t(
'device.control.gnirehtet.stopping',
)
try { try {
await this.$gnirehtet.stop(this.device.id) await this.$gnirehtet.stop(this.device.id)

@ -42,9 +42,9 @@ export default {
const res = await this.$scrcpy.mirrorGroup(this.device.id, { const res = await this.$scrcpy.mirrorGroup(this.device.id, {
open, open,
title: ({ displayId }) => title: ({ displayId }) =>
`${this.device.$remark ? `${this.device.$remark}-` : ''}${ `${this.$store.device.getLabel(
this.device.$name this.device,
}-${this.device.id}-display-${displayId}`, )}-displayId-${displayId}`,
args: this.scrcpyArgs(this.device.id), args: this.scrcpyArgs(this.device.id),
}) })

@ -5,7 +5,6 @@
</template> </template>
<script> <script>
import dayjs from 'dayjs'
import LoadingIcon from '@/components/Device/components/LoadingIcon/index.vue' import LoadingIcon from '@/components/Device/components/LoadingIcon/index.vue'
export default { export default {
@ -25,17 +24,16 @@ export default {
async handleScreenCap(device) { async handleScreenCap(device) {
const messageEl = this.$message({ const messageEl = this.$message({
message: this.$t('device.control.capture.progress', { message: this.$t('device.control.capture.progress', {
deviceName: device.$name, deviceName: this.$store.device.getLabel(device),
}), }),
icon: LoadingIcon, icon: LoadingIcon,
duration: 0, duration: 0,
}) })
const fileName = `${device.$remark ? `${device.$remark}-` : ''}${ const fileName = this.$store.device.getLabel(
device.$name device,
}-${this.$replaceIP(device.id)}-screencap-${dayjs().format( ({ time }) => `screenshot-${time}.png`,
'YYYY-MM-DD-HH-mm-ss', )
)}.png`
const deviceConfig = this.preferenceData(device.id) const deviceConfig = this.preferenceData(device.id)
const savePath = this.$path.resolve(deviceConfig.savePath, fileName) const savePath = this.$path.resolve(deviceConfig.savePath, fileName)

@ -154,7 +154,6 @@
</template> </template>
<script> <script>
import dayjs from 'dayjs'
import ControlBar from './components/ControlBar/index.vue' import ControlBar from './components/ControlBar/index.vue'
import Remark from './components/Remark/index.vue' import Remark from './components/Remark/index.vue'
import Wireless from './components/Wireless/index.vue' import Wireless from './components/Wireless/index.vue'
@ -242,14 +241,14 @@ export default {
this.$refs.elTable.toggleRowExpansion(...params) this.$refs.elTable.toggleRowExpansion(...params)
}, },
getRecordPath(row) { getRecordPath(row) {
const rowConfig = this.preferenceData(row.id) const config = this.preferenceData(row.id)
const basePath = rowConfig.savePath const basePath = config.savePath
const ext = config['--record-format'] || 'mp4'
const fileName = `${row.$remark ? `${row.$remark}-` : ''}${ const fileName = this.$store.device.getLabel(
row.$name row,
}-${this.$replaceIP(row.id)}-recording-${dayjs().format( ({ time }) => `record-${time}.${ext}`,
'YYYY-MM-DD-HH-mm-ss', )
)}`
const joinValue = this.$path.join(basePath, fileName) const joinValue = this.$path.join(basePath, fileName)
const value = this.$path.normalize(joinValue) const value = this.$path.normalize(joinValue)
@ -265,14 +264,21 @@ export default {
try { try {
await this.$scrcpy.record(row.id, { await this.$scrcpy.record(row.id, {
title: `${row.$remark ? `${row.$remark}-` : ''}${row.$name}-${ title: this.$store.device.getLabel(row, 'recording'),
row.id
}-🎥${this.$t('device.record.progress')}...`,
savePath, savePath,
args: this.scrcpyArgs(row.id, { isRecord: true }), args: this.scrcpyArgs(row.id, { isRecord: true }),
stdout: this.onStdout, stdout: this.onStdout,
}) })
}
catch (error) {
console.warn(error)
if (error.message) {
this.$message.warning(error.message)
}
this.handleReset()
}
try {
await this.$confirm( await this.$confirm(
this.$t('device.record.success.message'), this.$t('device.record.success.message'),
this.$t('device.record.success.title'), this.$t('device.record.success.title'),
@ -290,11 +296,9 @@ export default {
) )
} }
catch (error) { catch (error) {
if (error.message) { console.warn(error)
this.$message.warning(error.message)
}
this.handleReset()
} }
row.$recordLoading = false row.$recordLoading = false
}, },
async handleMirror(row) { async handleMirror(row) {
@ -304,17 +308,17 @@ export default {
try { try {
await this.$scrcpy.mirror(row.id, { await this.$scrcpy.mirror(row.id, {
title: `${row.$remark ? `${row.$remark}-` : ''}${row.$name}-${ title: this.$store.device.getLabel(row),
row.id
}`,
args: this.scrcpyArgs(row.id), args: this.scrcpyArgs(row.id),
stdout: this.onStdout, stdout: this.onStdout,
}) })
} }
catch (error) { catch (error) {
console.warn(error)
if (error.message) { if (error.message) {
this.$message.warning(error.message) this.$message.warning(error.message)
} }
this.handleReset() this.handleReset()
} }
row.$loading = false row.$loading = false
@ -379,8 +383,6 @@ export default {
$loading: false, $loading: false,
$recordLoading: false, $recordLoading: false,
$stopLoading: false, $stopLoading: false,
$gnirehtetLoading: false,
$gnirehtetLoadingText: '',
})) || [] })) || []
console.log('getDeviceData.data', this.deviceList) console.log('getDeviceData.data', this.deviceList)

@ -1,5 +1,7 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import dayjs from 'dayjs'
import { t } from '@/locales/index.js'
import { isIPWithPort, replaceIP } from '@/utils/index.js' import { isIPWithPort, replaceIP } from '@/utils/index.js'
const $appStore = window.appStore const $appStore = window.appStore
@ -25,6 +27,33 @@ export const useDeviceStore = defineStore({
setList(data) { setList(data) {
this.list = data this.list = data
}, },
getLabel(device, param) {
if (!device) {
return ''
}
const data = device?.id
? device
: this.list.find(item => item.id === device)
const labels = [data.$remark, data.$name, replaceIP(data.id)]
const model = {
recording: `🎥${t('device.record.progress')}...`,
time: dayjs().format('YYYY_MM_DD_HH_mm_ss'),
}
if (typeof param === 'function') {
labels.push(param(model))
}
else if (param && typeof param === 'string') {
labels.push(model[param])
}
const value = labels.filter(item => !!item).join('-')
return value
},
async getList() { async getList() {
const res = await window.adbkit.getDevices() const res = await window.adbkit.getDevices()