Skip to content

Commit

Permalink
新增:投屏自定义参数支持,方便个性化设置
Browse files Browse the repository at this point in the history
  • Loading branch information
modstart committed Jan 15, 2025
1 parent 013e9fe commit 87e0e64
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 19 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- 新增:时间戳获取方法
- 新增:集成 arm64 架构 adb( 二进制包来自 prife/adb )
- 新增:投屏自定义参数支持,方便个性化设置
- 优化:投屏失败弹出错误图示对话框
- 优化:Linux 平台获取 UUID 方法优化

## v0.4.0 投屏时关闭屏幕,工单反馈,文件夹下载,已知问题修复
Expand Down
15 changes: 15 additions & 0 deletions src/components/Device/DeviceDefaultSettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ defineExpose({
</a-input>
</div>
</div>
<div class="flex mb-3">
<div class="flex-grow">
{{ $t('自定义参数') }}
<a-tooltip :content="$t('该参数在投屏时会追加到scrcpy命令')">
<icon-info-circle/>
</a-tooltip>
</div>
<div class="">
<a-input :model-value="setting.configGet('Device.scrcpyArgs', '').value"
style="width:10rem;"
size="small"
@input="setting.onConfigChange('Device.scrcpyArgs',$event)">
</a-input>
</div>
</div>
</div>
</div>
</div>
Expand Down
13 changes: 7 additions & 6 deletions src/components/Device/DeviceFileManagerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const doDownload = async () => {
const downloadDirectory = async (deviceId: string, sourcePath: string, targetPath: string) => {
// 创建目标文件夹
await window.$mapi.file.mkdir(targetPath, { isFullPath: true });
await window.$mapi.file.mkdir(targetPath, {isFullPath: true});
// 获取源文件夹内容
const files = await window.$mapi.adb.fileList(deviceId, sourcePath);
for (let f of files) {
Expand Down Expand Up @@ -263,27 +263,28 @@ const toggleSortByModifiedTime = () => {
</a-button>
<a-button class="mr-1" @click="toggleView">
<template #icon>
<icon-swap/>
<icon-view :type="isListView ? 'list' : 'grid'"/>
<icon-list v-if="isListView"/>
<icon-apps v-else/>
</template>
{{ isListView ? $t('网格视图') : $t('列表视图') }}
</a-button>
<a-button class="mr-1" @click="toggleSortByName">
<template #icon>
<component :is="sortOrderName === 'asc' ? 'icon-down' : 'icon-up'" />
<component :is="sortOrderName === 'asc' ? 'icon-down' : 'icon-up'"/>
</template>
{{ $t('按文件名排序') }} ({{ sortOrderName === 'asc' ? $t('降序') : $t('升序') }})
</a-button>
<a-button class="mr-1" @click="toggleSortByModifiedTime">
<template #icon>
<component :is="sortOrderModifiedTime === 'asc' ? 'icon-down' : 'icon-up'" />
<component :is="sortOrderModifiedTime === 'asc' ? 'icon-down' : 'icon-up'"/>
</template>
{{ $t('按修改时间排序') }} ({{ sortOrderModifiedTime === 'asc' ? $t('降序') : $t('升序') }})
</a-button>
</div>
<div class="flex-grow overflow-auto border border-solid border-gray-200 rounded p-2">
<div v-if="isListView" class="flex flex-col">
<div v-for="f in sortedFileRecords" class="flex items-center border-b border-gray-200 p-2" :key="f.name">
<div v-for="f in sortedFileRecords" class="flex items-center border-b border-gray-200 p-2"
:key="f.name">
<div class="flex items-center flex-grow" @click="doOpen(f)" style="cursor: pointer;">
<FileExt :is-folder="f.isDirectory" :name="f.name" size="30px" class="mr-2"/>
<div class="flex-grow">
Expand Down
14 changes: 14 additions & 0 deletions src/components/Device/DeviceSettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const formData = ref({
previewImage: '',
videoBitRate: '',
maxFps: '',
scrcpyArgs:'',
})
const device = ref<DeviceRecord | null>(null)
const infoColumns = [
Expand Down Expand Up @@ -41,6 +42,7 @@ const show = (record: DeviceRecord) => {
formData.value.previewImage = record.setting?.previewImage || ''
formData.value.videoBitRate = record.setting?.videoBitRate || ''
formData.value.maxFps = record.setting?.maxFps || ''
formData.value.scrcpyArgs = record.setting?.scrcpyArgs || ''
visible.value = true
}
Expand All @@ -52,6 +54,7 @@ const doSubmit = async () => {
previewImage: formData.value.previewImage,
videoBitRate: formData.value.videoBitRate,
maxFps: formData.value.maxFps,
scrcpyArgs: formData.value.scrcpyArgs,
})
visible.value = false
}
Expand Down Expand Up @@ -117,6 +120,17 @@ defineExpose({
<a-input v-model="formData.maxFps" size="small" :placeholder="$t('留空使用默认配置')"/>
</div>
</div>
<div class="flex mb-3">
<div class="flex-grow">
{{ $t('自定义参数') }}
<a-tooltip :content="$t('该参数在投屏时会追加到scrcpy命令')">
<icon-info-circle/>
</a-tooltip>
</div>
<div class="">
<a-input v-model="formData.scrcpyArgs" size="small" :placeholder="$t('留空使用默认配置')"/>
</div>
</div>
<div class="font-bold text-xl mb-3">
{{ $t('其他') }}
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/declarations/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ declare interface Window {
mirror: (serial: string, option: {
title?: string,
args?: string,
stdout?: Function,
stderr?: Function,
success?: Function,
error?: Function,
stdout?: (data: string, process: any) => void,
stderr?: (data: string, process: any) => void,
success?: (process: any) => void,
error?: (msg: string, exitCode: number, process: any) => void,
env?: Record<string, any>,
}) => Promise<any>,
},
ffmpeg: {
Expand Down
3 changes: 3 additions & 0 deletions src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"2c977f94": "Recording Format",
"2cc56099": "Application Management",
"2df5f84f": "Screenshot Editing",
"2e35f7ee": "Mirror Failed",
"2e36d069": "Mirror Success",
"2f5eaf14": "File Management",
"2fae8dba": "Disconnect",
Expand All @@ -123,6 +124,7 @@
"32a57afe": "Confirm",
"338045e9": "Shell",
"33cd44f1": "Test Connection",
"35e8f4f5": "This args will pass to scrcpy command",
"35f3e924": "Environment",
"379a84eb": "Quit",
"398335e3": "Waiting for Connection",
Expand Down Expand Up @@ -153,6 +155,7 @@
"4f59d0b6": "Close screen when mirror",
"4f997a55": "Delete",
"508513f9": "Are you sure you want to delete the selected files?",
"518dad07": "Custom Args",
"59950117": "Leave blank to use default",
"5affe2ba": "Click Close",
"5e1bac63": "Enter keywords to filter",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"找不到设备": "6f506676",
"投屏": "000c4c5a",
"投屏到电脑": "6793a9ee",
"投屏失败": "2e35f7ee",
"投屏总在最上层": "196deb0f",
"投屏成功": "2e36d069",
"投屏时关闭屏幕": "4f59d0b6",
Expand Down Expand Up @@ -168,6 +169,7 @@
"网络": "000fe9ab",
"网络设备": "3bcd6ff4",
"网络连接": "3bcdfa72",
"自定义参数": "518dad07",
"视图": "001105f8",
"视频比特率": "23886069",
"记住我的选择": "160fdc0e",
Expand All @@ -181,6 +183,7 @@
"设备连接失败": "60b3039c",
"设备连接成功": "60b22b21",
"设置": "00116b70",
"该参数在投屏时会追加到scrcpy命令": "35e8f4f5",
"语言": "00117bb3",
"请求错误": "4148da61",
"跟随系统": "42c281d4",
Expand Down
3 changes: 3 additions & 0 deletions src/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"2c977f94": "录制格式",
"2cc56099": "应用管理",
"2df5f84f": "截图编辑",
"2e35f7ee": "投屏失败",
"2e36d069": "投屏成功",
"2ec70814": "执行成功",
"2f5eaf14": "文件管理",
Expand All @@ -142,6 +143,7 @@
"338045e9": "命令行工具",
"33cd44f1": "测试连接",
"358601fe": "使用USB连接电脑",
"35e8f4f5": "该参数在投屏时会追加到scrcpy命令",
"35f3e924": "环境设置",
"36bc2185": "用户中心",
"379a84eb": "直接退出",
Expand Down Expand Up @@ -182,6 +184,7 @@
"4f59d0b6": "投屏时关闭屏幕",
"4f997a55": "delete",
"508513f9": "确定删除选中的文件吗?",
"518dad07": "自定义参数",
"53f5fcc1": "支持的命令:",
"59950117": "留空使用默认配置",
"5affe2ba": "点击关闭时",
Expand Down
35 changes: 26 additions & 9 deletions src/store/modules/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getEmptySetting = () => {
previewImage: '',
videoBitRate: '',
maxFps: '',
scrcpyArgs: '',
}))
}

Expand Down Expand Up @@ -262,6 +263,7 @@ export const deviceStore = defineStore("device", {
mirrorSound: await this.settingGet(device, 'mirrorSound', 'no'),
videoBitRate: await this.settingGet(device, 'videoBitRate', '8M'),
maxFps: await this.settingGet(device, 'maxFps', '60'),
scrcpyArgs: await this.settingGet(device, 'scrcpyArgs', ''),
}
// console.log('setting', setting)
const args: string[] = []
Expand All @@ -281,34 +283,49 @@ export const deviceStore = defineStore("device", {
if (setting.dimWhenMirror === 'yes') {
args.push('--turn-screen-off')
}
if (setting.scrcpyArgs) {
args.push(setting.scrcpyArgs)
}

const mirrorStart = async () => {
}
const mirrorEnd = async () => {
}
let successTimer: any = null
try {
runtime.value.mirrorController = await window.$mapi.scrcpy.mirror(device.id, {
title: device.name as string,
args: args.join(' '),
stdout: (data: string) => {
console.log('mirror.stdout', data)
stdout: (data: string, process: any) => {
console.log('mirror.stdout', {data})
window.$mapi.log.info('Mirror.stdout', {data})
if (!successTimer) {
successTimer = setTimeout(() => {
if (runtime.value.mirrorController) {
Dialog.tipSuccess(t('投屏成功'))
}
}, 2000)
}
},
stderr: (data: string) => {
console.error('mirror.stderr', data)
stderr: (data: string, process: any) => {
console.log('mirror.stderr', {data})
window.$mapi.log.error('Mirror.stderr', {data})
},
success: (code: number) => {
console.log('mirror.success', code)
success: (process: any) => {
console.log('mirror.success')
window.$mapi.log.info('Mirror.success')
runtime.value.mirrorController = null
mirrorEnd().then()
},
error: (code: number) => {
console.error('mirror.error', code)
error: (msg: string, exitCode: number, process: any) => {
console.log('mirror.error', {msg, exitCode})
window.$mapi.log.error('Mirror.error', {msg, exitCode})
runtime.value.mirrorController = null
Dialog.alertError(t('投屏失败') + ` : <code>${msg}</code>`)
mirrorEnd().then()
}
})
await sleep(1000)
Dialog.tipSuccess(t('投屏成功'))
await mirrorStart()
} catch (error) {
Dialog.tipError(mapError(error))
Expand Down
1 change: 1 addition & 0 deletions src/types/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type DeviceRecord = {
previewImage?: any,
videoBitRate?: any,
maxFps?: any,
scrcpyArgs?: any,
},
}

Expand Down

0 comments on commit 87e0e64

Please sign in to comment.