Skip to content

Commit

Permalink
新增:投屏时调暗屏幕设置
Browse files Browse the repository at this point in the history
  • Loading branch information
modstart committed Oct 18, 2024
1 parent f8962e2 commit f48cdbe
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- 新增:本地日志默认保留14天,超过14天自动删除
- 新增:投屏总在最上层设置
- 新增:投屏时转发声音到电脑设置
- 新增:投屏时调暗屏幕设置
- 优化:问题反馈链接直达反馈页面
- 优化:配置页面逻辑功能优化
- 优化:快捷键优化重构修改
Expand Down
20 changes: 15 additions & 5 deletions electron/mapi/adb/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,29 @@ const getClient = async (): Promise<Client> => {
return client
}

const adbShell = async (command: string) => {
const adbShell = async (command: string, deviceId?: string) => {
const adbPath = await getBinPath()
return await Apps.shell(`"${adbPath}" ${command}`)
if (deviceId) {
deviceId = `-s "${deviceId}"`
} else {
deviceId = ''
}
return await Apps.shell(`"${adbPath}" ${deviceId} ${command}`)
}

const adbSpawnShell = async (command: string, option: {
const adbSpawnShell = async (command: string, option?: {
stdout?: Function,
stderr?: Function,
success?: Function,
error?: Function,
} | null = null) => {
} | null, deviceId?: string) => {
const adbPath = await getBinPath()
return await Apps.spawnShell(`"${adbPath}" ${command}`, option)
if (deviceId) {
deviceId = `-s "${deviceId}"`
} else {
deviceId = ''
}
return await Apps.spawnShell(`"${adbPath}" ${deviceId} ${command}`, option)
}

const devices = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Device/DeviceSettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defineExpose({
<div class="overflow-y-auto p-5" style="height:calc(80vh - 200px);">
<a-form :model="{}" layout="vertical">
<a-form-item :label="$t('投屏')">
<a-checkbox v-if="0" v-model="formData.dimWhenMirror" size="small" class="mr-2">
<a-checkbox v-model="formData.dimWhenMirror" size="small" class="mr-2">
{{ $t('投屏时调暗屏幕') }}
</a-checkbox>
<a-checkbox v-model="formData.alwaysTop" size="small" class="mr-2">
Expand Down
4 changes: 2 additions & 2 deletions src/declarations/mapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ declare interface Window {
adb: {
getBinPath: () => Promise<string>,
setBinPath: (binPath: string) => Promise<boolean>,
adbShell: (command: string) => Promise<string>,
adbShell: (command: string, deviceId?: string) => Promise<string>,
adbSpawnShell: (command: string, option?: {
stdout?: Function | null,
stderr?: Function | null,
success?: Function | null,
error?: Function | null,
}) => Promise<string>,
}, deviceId?: string) => Promise<string>,
devices: () => Promise<any>,
screencap: (serial: string) => Promise<string>,
screenrecord: (serial: string, option?: {
Expand Down
8 changes: 7 additions & 1 deletion src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"29d2c176": "Basic",
"2a35bd16": "Processing Failed",
"2a369591": "Processing Successful",
"2a3bec13": "处理超时",
"2ba8d170": "Installation Failed",
"2ba96070": "Install Application",
"2ba9a9eb": "Installation Successful",
Expand Down Expand Up @@ -116,15 +117,19 @@
"3d329aff": "Default {port}",
"3dc180fa": "Are you sure you want to delete the device?",
"40e57868": "Detail",
"4148da61": "请求错误",
"42554fbd": "Shell of {name} started",
"42ed4ed0": "Connect Device",
"42fe6375": "Select Path",
"43cf49a0": "Reload",
"43d76c93": "文件未找到",
"43fae06d": "文件已存在",
"45722a7e": "Recorded {time}",
"4671999f": "Hide Others",
"467699ab": "Hide",
"4b9352c5": "Recorded %s",
"4c2d6613": "Add as network device",
"4f59d0b6": "投屏时调暗屏幕",
"4f997a55": "Delete",
"508513f9": "Are you sure you want to delete the selected files?",
"5affe2ba": "Click Close",
Expand All @@ -139,9 +144,10 @@
"69f87f08": "Open Command Line",
"6a51c6b3": "Device {name} shell",
"6f369807": "Screenshot Editor",
"6f506676": "找不到设备",
"73b90d88": "已经在投屏中",
"7553a957": "Connect via Wifi",
"7b11c571": "No devices available, connect to the computer via USB to get started~",
"7cb31927": "Confirm Uninstall Application {name}?",
"7d2a202f": "New version v{version} found, download now?"
}
}
10 changes: 8 additions & 2 deletions src/lang/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"声明": "000b2b1e",
"处理失败": "2a35bd16",
"处理成功": "2a369591",
"处理超时": "2a3bec13",
"复制": "000b1ac9",
"如何使用?": "129d57c3",
"如何连接?": "138cdd85",
Expand Down Expand Up @@ -87,16 +88,20 @@
"打开摄像头": "11b1a85f",
"打开摄像头成功": "6bf53f2e",
"执行成功": "2ec70814",
"找不到设备": "6f506676",
"投屏": "000c4c5a",
"投屏到电脑": "6793a9ee",
"投屏时转发声音": "0ec1e5c8",
"投屏总在最上层": "196deb0f",
"投屏成功": "2e36d069",
"投屏时调暗屏幕": "4f59d0b6",
"投屏时转发声音": "0ec1e5c8",
"提示": "000c8f6a",
"撤销": "000cc4dc",
"支持的命令:": "53f5fcc1",
"放大": "000c9ba9",
"教程": "000cbfd2",
"文件已存在": "43fae06d",
"文件未找到": "43d76c93",
"文件管理": "2f5eaf14",
"断开设备成功": "03b9a935",
"断开连接": "2fae8dba",
Expand Down Expand Up @@ -164,6 +169,7 @@
"设备连接成功": "60b22b21",
"设置": "00116b70",
"语言": "00117bb3",
"请求错误": "4148da61",
"输入 help 查看帮助": "3afad06e",
"输入关键词过滤": "5e1bac63",
"返回": "0011c18a",
Expand All @@ -186,4 +192,4 @@
"隐藏其他": "4671999f",
"隐藏窗口": "467699ab",
"默认端口 {port}": "3d329aff"
}
}
8 changes: 7 additions & 1 deletion src/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"29d2c176": "基础设置",
"2a35bd16": "处理失败",
"2a369591": "处理成功",
"2a3bec13": "处理超时",
"2ba8d170": "安装失败",
"2ba96070": "安装应用",
"2ba9a9eb": "安装成功",
Expand Down Expand Up @@ -142,12 +143,15 @@
"3dad1885": "设备版本过低,不支持此功能",
"3dc180fa": "确定删除设备?",
"40e57868": "设备设置",
"4148da61": "请求错误",
"42554fbd": "进入设备 {name} 的命令行",
"42bad8e1": "退出软件",
"42e83c56": "连接成功",
"42ed4ed0": "连接设备",
"42fe6375": "选择路径",
"43cf49a0": "重新加载",
"43d76c93": "文件未找到",
"43fae06d": "文件已存在",
"45722a7e": "已录制 {time}",
"45dba75c": "测试连接中",
"4671999f": "隐藏其他",
Expand All @@ -156,6 +160,7 @@
"4b9352c5": "已录制 %s",
"4c2d6613": "添加为网络设备",
"4e980c75": "正在连接设备",
"4f59d0b6": "投屏时调暗屏幕",
"4f997a55": "delete",
"508513f9": "确定删除选中的文件吗?",
"53f5fcc1": "支持的命令:",
Expand All @@ -176,6 +181,7 @@
"6a51c6b3": "设备 {name} 命令行",
"6bf53f2e": "打开摄像头成功",
"6f369807": "截图编辑器",
"6f506676": "找不到设备",
"73b90d88": "已经在投屏中",
"7553a957": "通过网络连接",
"759b26c5": "测试连接失败",
Expand All @@ -185,4 +191,4 @@
"7b5e9f5a": "正在打开摄像头",
"7cb31927": "确认卸载应用 {name} ?",
"7d2a202f": "发现新版本{version},是否立即下载更新?"
}
}
32 changes: 25 additions & 7 deletions src/store/modules/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,48 @@ export const deviceStore = defineStore("device", {
} else {
args.push('--no-audio')
}
const mirrorStart = async () => {
if (device.setting?.dimWhenMirror) {
try {
const result = await window.$mapi.adb.adbShell('shell settings get system screen_brightness', device.id)
// @ts-ignore
device.runtime.screenBrightness = parseInt(result?.stdout)
await window.$mapi.adb.adbShell('shell settings put system screen_brightness 1', device.id)
} catch (e) {
}
}
}
const mirrorEnd = async () => {
if (device.setting?.dimWhenMirror) {
if (device.runtime.screenBrightness) {
await window.$mapi.adb.adbShell(`shell settings put system screen_brightness ${device.runtime.screenBrightness}`, device.id)
}
}
}
try {
runtime.mirrorController = await window.$mapi.scrcpy.mirror(device.id, {
title: device.name as string,
args: args.join(' '),
stdout: (data: string) => {
console.log('stdout', data)
console.log('mirror.stdout', data)
},
stderr: (data: string) => {
console.error('stderr', data)
console.error('mirror.stderr', data)
},
success: (code: number) => {
console.log('success', code)
console.log('mirror.success', code)
runtime.mirrorController = null
mirrorEnd().then()
},
error: (code: number) => {
console.error('error', code)
console.error('mirror.error', code)
runtime.mirrorController = null
mirrorEnd().then()
}
})
await sleep(1000)
Dialog.tipSuccess(t('投屏成功'))
if (device.setting?.dimWhenMirror) {

}
await mirrorStart()
} catch (error) {
Dialog.tipError(mapError(error))
} finally {
Expand Down
1 change: 1 addition & 0 deletions src/types/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export type DeviceRecord = {
export type DeviceRuntime = {
status: EnumDeviceStatus,
mirrorController: any,
screenBrightness?: number,
}

0 comments on commit f48cdbe

Please sign in to comment.