mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-02-13 00:54:40 +01:00
110 lines
2.7 KiB
JavaScript
110 lines
2.7 KiB
JavaScript
import appStore from '$electron/helpers/store.js'
|
|
import { replaceIP } from '$renderer/utils/index.js'
|
|
|
|
/**
|
|
* Parse scrcpy app list output into structured data
|
|
* @param {string} rawText - Raw text output from scrcpy --list-apps command
|
|
* @returns {Array<{
|
|
* name: string,
|
|
* packageName: string,
|
|
* isSystemApp: boolean
|
|
* }>} Array of parsed app objects
|
|
*/
|
|
export function parseScrcpyAppList(rawText) {
|
|
if (typeof rawText !== 'string') {
|
|
throw new TypeError('scrcpy content must be a string')
|
|
}
|
|
|
|
return rawText
|
|
.split('\n')
|
|
.filter(line => line.startsWith(' * ') || line.startsWith(' - '))
|
|
.map((line) => {
|
|
const isSystemApp = line.startsWith(' * ')
|
|
// Remove prefix and trim
|
|
const content = line.substring(3).trim()
|
|
// Find last space to separate name and package
|
|
const lastSpaceIndex = content.lastIndexOf(' ')
|
|
|
|
return {
|
|
name: content.substring(0, lastSpaceIndex).trim(),
|
|
packageName: content.substring(lastSpaceIndex + 1).trim(),
|
|
isSystemApp,
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Get the --display-overlay value
|
|
* @param {*} serial
|
|
* @returns {string}
|
|
*/
|
|
export function getDisplayOverlay(serial) {
|
|
const value = appStore.get(`scrcpy.${replaceIP(serial)}.--display-overlay`)
|
|
|| appStore.get('scrcpy.global.--display-overlay')
|
|
|| ''
|
|
return value
|
|
}
|
|
|
|
/**
|
|
* Parse scrcpy codec output into structured data
|
|
* @param {*} rawText
|
|
* @returns
|
|
*/
|
|
export function parseScrcpyCodecList(rawText) {
|
|
try {
|
|
const result = {
|
|
video: [],
|
|
audio: [],
|
|
}
|
|
|
|
const lines = rawText.split('\n')
|
|
|
|
for (const line of lines) {
|
|
const trimmedLine = line.trim()
|
|
|
|
if (!trimmedLine || !trimmedLine.startsWith('--')) {
|
|
continue
|
|
}
|
|
|
|
const pairs = trimmedLine.match(/--[\w-]+=[\w.-]+/g)
|
|
if (!pairs || pairs.length < 2)
|
|
continue
|
|
|
|
const info = pairs.reduce((acc, pair) => {
|
|
const [key, value] = pair.substring(2).split('=')
|
|
acc[key] = value
|
|
return acc
|
|
}, {})
|
|
|
|
if (info['video-codec'] && info['video-encoder']) {
|
|
result.video.push({
|
|
type: 'video',
|
|
codec: info['video-codec'],
|
|
encoder: info['video-encoder'],
|
|
})
|
|
}
|
|
else if (info['audio-codec'] && info['audio-encoder']) {
|
|
result.audio.push({
|
|
type: 'audio',
|
|
codec: info['audio-codec'],
|
|
encoder: info['audio-encoder'],
|
|
})
|
|
}
|
|
}
|
|
|
|
if (result.video.length === 0 && result.audio.length === 0) {
|
|
throw new Error('No valid codec information found in the log content')
|
|
}
|
|
|
|
return result
|
|
}
|
|
catch (error) {
|
|
console.error('Error parsing codec information:', error)
|
|
return {
|
|
video: [],
|
|
audio: [],
|
|
error: error.message,
|
|
}
|
|
}
|
|
}
|