mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-02-22 04:49:42 +01:00
perf: ⚡️ Optimize the method of obtaining the available displays of the device
This commit is contained in:
parent
d25714a43f
commit
9e31c847fe
@ -7,7 +7,6 @@ import appStore from '$electron/helpers/store.js'
|
|||||||
import { formatFileSize } from '$renderer/utils/index'
|
import { formatFileSize } from '$renderer/utils/index'
|
||||||
import { Adb } from '@devicefarmer/adbkit'
|
import { Adb } from '@devicefarmer/adbkit'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { uniq } from 'lodash-es'
|
|
||||||
import adbConnectionMonitor from './helpers/adbConnectionMonitor/index.js'
|
import adbConnectionMonitor from './helpers/adbConnectionMonitor/index.js'
|
||||||
import { streamToBase64 } from '$electron/helpers/index.js'
|
import { streamToBase64 } from '$electron/helpers/index.js'
|
||||||
import { parseBatteryDump } from './helpers/battery/index.js'
|
import { parseBatteryDump } from './helpers/battery/index.js'
|
||||||
@ -160,26 +159,6 @@ const isInstalled = async (id, pkg) => client.getDevice(id).isInstalled(pkg)
|
|||||||
|
|
||||||
const version = async () => client.version()
|
const version = async () => client.version()
|
||||||
|
|
||||||
const display = async (deviceId) => {
|
|
||||||
let value = []
|
|
||||||
try {
|
|
||||||
const res = await deviceShell(deviceId, 'dumpsys display')
|
|
||||||
|
|
||||||
const regex = /Display Id=(\d+)/g
|
|
||||||
|
|
||||||
const match = res.match(regex) || []
|
|
||||||
|
|
||||||
const mapValue = match.map(item => item.split('=')[1])
|
|
||||||
|
|
||||||
value = uniq(mapValue)
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.warn(error?.message || error)
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
const watch = async (callback) => {
|
const watch = async (callback) => {
|
||||||
const tracker = await client.trackDevices()
|
const tracker = await client.trackDevices()
|
||||||
tracker.on('add', async (ret) => {
|
tracker.on('add', async (ret) => {
|
||||||
@ -354,7 +333,6 @@ export default {
|
|||||||
install,
|
install,
|
||||||
isInstalled,
|
isInstalled,
|
||||||
version,
|
version,
|
||||||
display,
|
|
||||||
push,
|
push,
|
||||||
pull,
|
pull,
|
||||||
watch,
|
watch,
|
||||||
|
@ -106,3 +106,30 @@ export function parseScrcpyCodecList(rawText) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of available display ids
|
||||||
|
* @param {*} text
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function parseDisplayIds(text) {
|
||||||
|
if (!text || typeof text !== 'string') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const displayIdPattern = /--display-id=(\d+)/g
|
||||||
|
|
||||||
|
const matches = Array.from(text.matchAll(displayIdPattern))
|
||||||
|
|
||||||
|
const displayIds = matches.map(match => Number.parseInt(match[1], 10))
|
||||||
|
|
||||||
|
const uniqueDisplayIds = [...new Set(displayIds)].filter(id => !Number.isNaN(id))
|
||||||
|
|
||||||
|
return uniqueDisplayIds.sort((a, b) => a - b)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('Error parsing display IDs:', error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { adbPath, scrcpyPath } from '$electron/configs/index.js'
|
|||||||
import appStore from '$electron/helpers/store.js'
|
import appStore from '$electron/helpers/store.js'
|
||||||
import commandHelper from '$renderer/utils/command/index.js'
|
import commandHelper from '$renderer/utils/command/index.js'
|
||||||
|
|
||||||
import { getDisplayOverlay, parseScrcpyAppList, parseScrcpyCodecList } from './helper.js'
|
import { getDisplayOverlay, parseDisplayIds, parseScrcpyAppList, parseScrcpyCodecList } from './helper.js'
|
||||||
|
|
||||||
const exec = util.promisify(_exec)
|
const exec = util.promisify(_exec)
|
||||||
|
|
||||||
@ -132,6 +132,15 @@ async function getAppList(serial) {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getDisplayIds(serial) {
|
||||||
|
const res = await execShell(`--serial="${serial}" --list-displays`)
|
||||||
|
|
||||||
|
const stdout = res.stdout
|
||||||
|
const value = parseDisplayIds(stdout)
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
async function startApp(serial, args = {}) {
|
async function startApp(serial, args = {}) {
|
||||||
let { commands, packageName, ...options } = args
|
let { commands, packageName, ...options } = args
|
||||||
|
|
||||||
@ -167,4 +176,5 @@ export default {
|
|||||||
helper,
|
helper,
|
||||||
getAppList,
|
getAppList,
|
||||||
startApp,
|
startApp,
|
||||||
|
getDisplayIds,
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ export default {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await this.$adb.display(deviceId)
|
const res = await this.$scrcpy.getDisplayIds(deviceId)
|
||||||
|
|
||||||
this.deviceOptions
|
this.deviceOptions
|
||||||
= res?.map((item) => {
|
= res?.map((item) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user