perf: ♻️ Enhance recording stability

This commit is contained in:
viarotel 2024-10-31 14:49:13 +08:00
parent 3f829b1d06
commit 3dd7525259
8 changed files with 52 additions and 31 deletions

View File

@ -81,7 +81,8 @@ export default {
title: ({ displayId }) => title: ({ displayId }) =>
`${this.$store.device.getLabel( `${this.$store.device.getLabel(
this.device, this.device,
)}-displayId-${displayId}`, 'synergy',
)}-${displayId}`,
args: this.scrcpyParams(this.device.id), args: this.scrcpyParams(this.device.id),
}) })

View File

@ -43,7 +43,7 @@ export default {
try { try {
const mirroring = this.$scrcpy.mirror(row.id, { const mirroring = this.$scrcpy.mirror(row.id, {
title: this.$store.device.getLabel(row), title: this.$store.device.getLabel(row, 'mirror'),
args, args,
stdout: this.onStdout, stdout: this.onStdout,
stderr: this.onStderr, stderr: this.onStderr,

View File

@ -46,11 +46,9 @@ export default {
}, },
)}` )}`
console.log('args', args)
try { try {
const mirroring = this.$scrcpy.mirror(row.id, { const mirroring = this.$scrcpy.mirror(row.id, {
title: this.$store.device.getLabel(row), title: this.$store.device.getLabel(row, 'camera'),
args, args,
stdout: this.onStdout, stdout: this.onStdout,
stderr: this.onStderr, stderr: this.onStderr,

View File

@ -51,7 +51,7 @@ export default {
try { try {
const mirroring = this.$scrcpy.mirror(row.id, { const mirroring = this.$scrcpy.mirror(row.id, {
title: this.$store.device.getLabel(row), title: this.$store.device.getLabel(row, 'custom'),
args, args,
stdout: this.onStdout, stdout: this.onStdout,
stderr: this.onStderr, stderr: this.onStderr,

View File

@ -18,7 +18,7 @@ const recordModel = {
extname: config => config['--audio-record-format'] || 'opus', extname: config => config['--audio-record-format'] || 'opus',
}, },
camera: { camera: {
excludes: ['--video-source', '--turn-screen-off'], excludes: ['--video-source', '--turn-screen-off', '--show-touches', '--no-power-on'],
commands: ['--video-source=camera'], commands: ['--video-source=camera'],
extname: config => config['--record-format'] || 'mp4', extname: config => config['--record-format'] || 'mp4',
}, },
@ -61,14 +61,13 @@ export default {
const savePath = this.getRecordPath(row) const savePath = this.getRecordPath(row)
let args = this.$store.preference.scrcpyParameter(row.id, { let args = this.$store.preference.scrcpyParameter(row.id, {
isRecord: ['default', 'audio'].includes(this.recordType), isRecord: true,
isCamera: ['camera'].includes(this.recordType), isCamera: ['camera'].includes(this.recordType),
excludes: [ excludes: [
...new Set([ ...new Set([
'--otg', '--otg',
'--mouse=aoa', '--mouse=aoa',
'--keyboard=aoa', '--keyboard=aoa',
'--show-touches',
...this.activeModel.excludes, ...this.activeModel.excludes,
]), ]),
], ],
@ -115,10 +114,10 @@ export default {
const extension = this.activeModel.extname(deviceConfig) const extension = this.activeModel.extname(deviceConfig)
const fileName = this.$store.device.getLabel( const fileName = `${this.$store.device.getLabel(
row, row,
({ time }) => `record-${time}.${extension}`, 'recorded',
) )}.${extension}`
const filePath = this.$path.join(savePath, fileName) const filePath = this.$path.join(savePath, fileName)

View File

@ -32,10 +32,10 @@ export function useScreenshotAction({ floating } = {}) {
).close ).close
} }
const fileName = deviceStore.getLabel( const fileName = `${deviceStore.getLabel(
device, device,
({ time }) => `screenshot-${time}.jpg`, 'screenshot',
) )}.jpg`
const deviceConfig = preferenceStore.getData(device.id) const deviceConfig = preferenceStore.getData(device.id)
const savePath = window.nodePath.resolve(deviceConfig.savePath, fileName) const savePath = window.nodePath.resolve(deviceConfig.savePath, fileName)

View File

@ -1,8 +1,9 @@
import { t } from '$/locales/index.js' import { defineStore } from 'pinia'
import dayjs from 'dayjs'
import { capitalize } from 'lodash-es'
import { isIPWithPort, replaceIP } from '$/utils/index.js' import { isIPWithPort, replaceIP } from '$/utils/index.js'
import dayjs from 'dayjs' import { name as packageName } from '$root/package.json'
import { defineStore } from 'pinia'
const $appStore = window.appStore const $appStore = window.appStore
@ -24,7 +25,7 @@ export const useDeviceStore = defineStore({
return this.config return this.config
}, },
getLabel(device, param) { getLabel(device, params) {
if (!device) { if (!device) {
return '' return ''
} }
@ -33,22 +34,44 @@ export const useDeviceStore = defineStore({
? device ? device
: this.list.find(item => item.id === device) : this.list.find(item => item.id === device)
const labels = [data.$remark, data.$name, replaceIP(data.id)] const appName = capitalize(packageName)
const model = { const deviceName = `${data.$remark || data.$name}${data.$wifi ? '(WIFI)' : ''}`
recording: `🎥${t('device.record.progress')}...`,
time: dayjs().format('YYYY_MM_DD_HH_mm_ss'), const currentTime = dayjs().format('YYYYMMDDHHmmss')
let value = `${appName}-${deviceName}`
const createPreset = type => `${appName}${capitalize(type)}-${deviceName}`
const presets = {
...[
'mirror',
'camera',
'custom',
'recording',
'synergy',
]
.reduce((obj, type) => {
obj[type] = createPreset(type)
return obj
}, {}),
recorded: `Record-${deviceName}-${currentTime}`,
screenshot: `Screenshot-${deviceName}-${currentTime}`,
} }
if (typeof param === 'function') { if (typeof params === 'function') {
labels.push(param(model)) value = params({
data,
appName,
deviceName,
currentTime,
})
} }
else if (param && typeof param === 'string') { else if (params && typeof params === 'string') {
labels.push(model[param]) value = presets[params]
} }
const value = labels.filter(item => !!item).join('-')
return value return value
}, },
setList(data) { setList(data) {