perf: ⚗️ Experimental support for turning off screen controls

This commit is contained in:
viarotel 2024-10-28 11:26:26 +08:00
parent 4be2cf4f14
commit 9555f58df5
9 changed files with 27 additions and 35 deletions

View File

@ -24,14 +24,6 @@ export const trayPath
export const logPath = process.env.LOG_PATH export const logPath = process.env.LOG_PATH
export function getLogoPath() { export function getLogoPath() {
let icon = logoPath const icon = logoPath
return icon
if (process.platform === 'win32') {
icon = icoLogoPath
}
else if (process.platform === 'darwin') {
icon = icnsLogoPath
}
return logoPath
} }

View File

@ -9,7 +9,7 @@ let adbkit
const exec = util.promisify(_exec) const exec = util.promisify(_exec)
async function shell(command, { stdout, stderr } = {}) { async function shell(command, { stdout, stderr, ...options } = {}) {
const spawnPath = appStore.get('common.scrcpyPath') || scrcpyPath const spawnPath = appStore.get('common.scrcpyPath') || scrcpyPath
const ADB = appStore.get('common.adbPath') || adbPath const ADB = appStore.get('common.adbPath') || adbPath
const args = command.split(' ') const args = command.split(' ')
@ -18,6 +18,7 @@ async function shell(command, { stdout, stderr } = {}) {
env: { ...process.env, ADB }, env: { ...process.env, ADB },
shell: true, shell: true,
encoding: 'utf8', encoding: 'utf8',
...options,
}) })
scrcpyProcess.stdout.on('data', (data) => { scrcpyProcess.stdout.on('data', (data) => {
@ -168,13 +169,17 @@ async function mirrorGroup(serial, { openNum = 1, ...options } = {}) {
return Promise.allSettled(results) return Promise.allSettled(results)
} }
async function control(serial, { command, exec = true, ...options } = {}) { async function helper(
const currentShell = exec ? execShell : shell serial,
command = '',
{ hiddenWindow = false, ...options } = {},
) {
const stringCommand = commandHelper.stringify(command) const stringCommand = commandHelper.stringify(command)
return currentShell( return execShell(
`--serial="${serial}" --no-video --no-audio ${stringCommand}`, `--serial="${serial}" --window-title="EscrcpyHelper" ${
hiddenWindow ? '--window-x=-300 --window-y=-300' : ''
} --no-video --no-audio --mouse=disabled ${stringCommand}`,
options, options,
) )
} }
@ -189,6 +194,6 @@ export default (options = {}) => {
mirror, mirror,
record, record,
mirrorGroup, mirrorGroup,
control, helper,
} }
} }

View File

@ -1,12 +1,5 @@
// import { globalShortcut } from 'electron' // import { globalShortcut } from 'electron'
export default (mainWindow) => { export default (mainWindow) => {
// mainWindow.on('focus', () => { // globalShortcut.register('Alt+O', () => {})
// globalShortcut.register('CommandOrControl+F', (event) => {
// mainWindow.webContents.send('focus-on-search')
// })
// })
// mainWindow.on('blur', () => {
// globalShortcut.unregister('CommandOrControl+F')
// })
} }

View File

@ -16,7 +16,7 @@
<Scrollable ref="scrollableRef" class="flex-1 w-0 flex items-center"> <Scrollable ref="scrollableRef" class="flex-1 w-0 flex items-center">
<component <component
:is="item.component || 'div'" :is="item.component || 'div'"
v-for="(item, index) in controlModel" v-for="(item, index) of controlModel"
:key="index" :key="index"
class="flex-none" class="flex-none"
v-bind="{ v-bind="{
@ -32,7 +32,7 @@
:disabled="device.$unauthorized" :disabled="device.$unauthorized"
:title="$t(item.tips || item.label)" :title="$t(item.tips || item.label)"
:loading="loading" :loading="loading"
@click="handleClick(item, trigger)" @click="handleClick(item, trigger || item.trigger)"
> >
<template #icon> <template #icon>
<svg-icon <svg-icon
@ -120,8 +120,10 @@ export default {
{ {
label: 'device.control.turnScreenOff', label: 'device.control.turnScreenOff',
elIcon: 'TurnOff', elIcon: 'TurnOff',
scrcpyCommand: '--turn-screen-off',
tips: 'device.control.turnScreenOff.tips', tips: 'device.control.turnScreenOff.tips',
trigger: () => {
window.scrcpy.helper(this.device.id, '--turn-screen-off')
},
}, },
{ {
label: 'device.control.notification', label: 'device.control.notification',

View File

@ -167,7 +167,7 @@
"device.control.capture.success.message.title": "Screenshot Success", "device.control.capture.success.message.title": "Screenshot Success",
"device.control.reboot": "Reboot", "device.control.reboot": "Reboot",
"device.control.turnScreenOff": "Turn screen off", "device.control.turnScreenOff": "Turn screen off",
"device.control.turnScreenOff.tips": "Turn off the screen without affecting control", "device.control.turnScreenOff.tips": "Turn off the screen while maintaining control (Experimental): This action will create an EscrcpyHelper process; manually closing this process will reopen the screen.",
"device.control.power": "Power", "device.control.power": "Power",
"device.control.power.tips": "Turn screen on/off", "device.control.power.tips": "Turn screen on/off",
"device.control.notification": "Notification", "device.control.notification": "Notification",

View File

@ -167,7 +167,7 @@
"device.control.capture.success.message.title": "Скриншот успешно создан", "device.control.capture.success.message.title": "Скриншот успешно создан",
"device.control.reboot": "Перезагрузить", "device.control.reboot": "Перезагрузить",
"device.control.turnScreenOff": "Выключить экран", "device.control.turnScreenOff": "Выключить экран",
"device.control.turnScreenOff.tips": "Выключить экран без потери управления", "device.control.turnScreenOff.tips": "Отключение экрана с сохранением контроля (экспериментально): это действие создаст процесс EscrcpyHelper; при ручном завершении этого процесса экран снова включится.",
"device.control.power": "Питание", "device.control.power": "Питание",
"device.control.power.tips": "Включить/выключить экран", "device.control.power.tips": "Включить/выключить экран",
"device.control.notification": "Уведомление", "device.control.notification": "Уведомление",

View File

@ -167,7 +167,7 @@
"device.control.capture.success.message.title": "截屏成功", "device.control.capture.success.message.title": "截屏成功",
"device.control.reboot": "重启设备", "device.control.reboot": "重启设备",
"device.control.turnScreenOff": "关闭屏幕", "device.control.turnScreenOff": "关闭屏幕",
"device.control.turnScreenOff.tips": "关闭屏幕而不影响控制", "device.control.turnScreenOff.tips": "关闭屏幕且保持控制(实验功能):此操作将创建一个 EscrcpyHelper 进程,手动关闭进程将重新打开屏幕。",
"device.control.power": "电源键", "device.control.power": "电源键",
"device.control.power.tips": "可以用来开启或关闭屏幕", "device.control.power.tips": "可以用来开启或关闭屏幕",
"device.control.notification": "通知栏", "device.control.notification": "通知栏",

View File

@ -167,7 +167,7 @@
"device.control.capture.success.message.title": "截圖成功", "device.control.capture.success.message.title": "截圖成功",
"device.control.reboot": "重啟裝置", "device.control.reboot": "重啟裝置",
"device.control.turnScreenOff": "關閉螢幕", "device.control.turnScreenOff": "關閉螢幕",
"device.control.turnScreenOff.tips": "關閉螢幕而不影響控制", "device.control.turnScreenOff.tips": "關閉螢幕且保持控制(實驗功能):此操作將創建一個 EscrcpyHelper 進程,手動關閉該進程將重新打開螢幕。",
"device.control.power": "電源鍵", "device.control.power": "電源鍵",
"device.control.power.tips": "可以用來開啟或關閉螢幕", "device.control.power.tips": "可以用來開啟或關閉螢幕",
"device.control.notification": "通知欄", "device.control.notification": "通知欄",

View File

@ -67,7 +67,7 @@ function stringify(options) {
// Process each option // Process each option
for (const [key, value] of Object.entries(options)) { for (const [key, value] of Object.entries(options)) {
// Skip null or undefined values // Skip null or undefined values
if ([null, undefined, false].includes(value)) { if ([null, undefined, false, ''].includes(value)) {
continue continue
} }
@ -87,10 +87,10 @@ function stringify(options) {
continue // 跳过空数组 continue // 跳过空数组
} }
value.forEach((item) => { value.forEach((item) => {
if (item !== null && item !== undefined) { if (![null, undefined, false, ''].includes(item)) {
const formattedValue = formatValue(item) const formattedValue = formatValue(item)
if (formattedValue) { if (formattedValue) {
args.push(`${paramName} ${formattedValue}`) args.push(`${paramName}=${formattedValue}`)
} }
} }
}) })