From 3dd75252591b8ea24ff2c02f12355b01b888c650 Mon Sep 17 00:00:00 2001 From: viarotel Date: Thu, 31 Oct 2024 14:49:13 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E2=99=BB=EF=B8=8F=20Enhance=20recordin?= =?UTF-8?q?g=20stability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 +- .../components/ControlBar/Synergy/index.vue | 3 +- .../Device/components/MirrorAction/index.vue | 2 +- .../MoreDropdown/components/Camera/index.vue | 4 +- .../MoreDropdown/components/Custom/index.vue | 2 +- .../MoreDropdown/components/Record/index.vue | 11 ++-- src/composables/useScreenshotAction/index.js | 6 +-- src/store/device/index.js | 51 ++++++++++++++----- 8 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/App.vue b/src/App.vue index 68785cd..f032b0b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -100,8 +100,8 @@ async function showTips() { ElMessageBox.alert( `
${window.t('dependencies.lack.content', { - name: 'scrcpy', - })} + name: 'scrcpy', + })}
`, window.t('dependencies.lack.title'), { diff --git a/src/components/Device/components/ControlBar/Synergy/index.vue b/src/components/Device/components/ControlBar/Synergy/index.vue index 35a7b22..c46d90f 100644 --- a/src/components/Device/components/ControlBar/Synergy/index.vue +++ b/src/components/Device/components/ControlBar/Synergy/index.vue @@ -81,7 +81,8 @@ export default { title: ({ displayId }) => `${this.$store.device.getLabel( this.device, - )}-displayId-${displayId}`, + 'synergy', + )}-${displayId}`, args: this.scrcpyParams(this.device.id), }) diff --git a/src/components/Device/components/MirrorAction/index.vue b/src/components/Device/components/MirrorAction/index.vue index efcb32b..3139b79 100644 --- a/src/components/Device/components/MirrorAction/index.vue +++ b/src/components/Device/components/MirrorAction/index.vue @@ -43,7 +43,7 @@ export default { try { const mirroring = this.$scrcpy.mirror(row.id, { - title: this.$store.device.getLabel(row), + title: this.$store.device.getLabel(row, 'mirror'), args, stdout: this.onStdout, stderr: this.onStderr, diff --git a/src/components/Device/components/MoreDropdown/components/Camera/index.vue b/src/components/Device/components/MoreDropdown/components/Camera/index.vue index c41d9f8..ee7e164 100644 --- a/src/components/Device/components/MoreDropdown/components/Camera/index.vue +++ b/src/components/Device/components/MoreDropdown/components/Camera/index.vue @@ -46,11 +46,9 @@ export default { }, )}` - console.log('args', args) - try { const mirroring = this.$scrcpy.mirror(row.id, { - title: this.$store.device.getLabel(row), + title: this.$store.device.getLabel(row, 'camera'), args, stdout: this.onStdout, stderr: this.onStderr, diff --git a/src/components/Device/components/MoreDropdown/components/Custom/index.vue b/src/components/Device/components/MoreDropdown/components/Custom/index.vue index 2fd8703..0b3ef11 100644 --- a/src/components/Device/components/MoreDropdown/components/Custom/index.vue +++ b/src/components/Device/components/MoreDropdown/components/Custom/index.vue @@ -51,7 +51,7 @@ export default { try { const mirroring = this.$scrcpy.mirror(row.id, { - title: this.$store.device.getLabel(row), + title: this.$store.device.getLabel(row, 'custom'), args, stdout: this.onStdout, stderr: this.onStderr, diff --git a/src/components/Device/components/MoreDropdown/components/Record/index.vue b/src/components/Device/components/MoreDropdown/components/Record/index.vue index e255c61..3426e4b 100644 --- a/src/components/Device/components/MoreDropdown/components/Record/index.vue +++ b/src/components/Device/components/MoreDropdown/components/Record/index.vue @@ -18,7 +18,7 @@ const recordModel = { extname: config => config['--audio-record-format'] || 'opus', }, camera: { - excludes: ['--video-source', '--turn-screen-off'], + excludes: ['--video-source', '--turn-screen-off', '--show-touches', '--no-power-on'], commands: ['--video-source=camera'], extname: config => config['--record-format'] || 'mp4', }, @@ -61,14 +61,13 @@ export default { const savePath = this.getRecordPath(row) let args = this.$store.preference.scrcpyParameter(row.id, { - isRecord: ['default', 'audio'].includes(this.recordType), + isRecord: true, isCamera: ['camera'].includes(this.recordType), excludes: [ ...new Set([ '--otg', '--mouse=aoa', '--keyboard=aoa', - '--show-touches', ...this.activeModel.excludes, ]), ], @@ -115,10 +114,10 @@ export default { const extension = this.activeModel.extname(deviceConfig) - const fileName = this.$store.device.getLabel( + const fileName = `${this.$store.device.getLabel( row, - ({ time }) => `record-${time}.${extension}`, - ) + 'recorded', + )}.${extension}` const filePath = this.$path.join(savePath, fileName) diff --git a/src/composables/useScreenshotAction/index.js b/src/composables/useScreenshotAction/index.js index 3800b61..20ecb0d 100644 --- a/src/composables/useScreenshotAction/index.js +++ b/src/composables/useScreenshotAction/index.js @@ -32,10 +32,10 @@ export function useScreenshotAction({ floating } = {}) { ).close } - const fileName = deviceStore.getLabel( + const fileName = `${deviceStore.getLabel( device, - ({ time }) => `screenshot-${time}.jpg`, - ) + 'screenshot', + )}.jpg` const deviceConfig = preferenceStore.getData(device.id) const savePath = window.nodePath.resolve(deviceConfig.savePath, fileName) diff --git a/src/store/device/index.js b/src/store/device/index.js index 19efc9f..a013985 100644 --- a/src/store/device/index.js +++ b/src/store/device/index.js @@ -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 dayjs from 'dayjs' -import { defineStore } from 'pinia' +import { name as packageName } from '$root/package.json' const $appStore = window.appStore @@ -24,7 +25,7 @@ export const useDeviceStore = defineStore({ return this.config }, - getLabel(device, param) { + getLabel(device, params) { if (!device) { return '' } @@ -33,22 +34,44 @@ export const useDeviceStore = defineStore({ ? device : this.list.find(item => item.id === device) - const labels = [data.$remark, data.$name, replaceIP(data.id)] + const appName = capitalize(packageName) - const model = { - recording: `🎥${t('device.record.progress')}...`, - time: dayjs().format('YYYY_MM_DD_HH_mm_ss'), + const deviceName = `${data.$remark || data.$name}${data.$wifi ? '(WIFI)' : ''}` + + 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') { - labels.push(param(model)) + if (typeof params === 'function') { + value = params({ + data, + appName, + deviceName, + currentTime, + }) } - else if (param && typeof param === 'string') { - labels.push(model[param]) + else if (params && typeof params === 'string') { + value = presets[params] } - const value = labels.filter(item => !!item).join('-') - return value }, setList(data) {