Skip to content

Commit

Permalink
fix: 🐛 Make StartApp compatible with scrcpy v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Nov 25, 2024
1 parent 8c3de04 commit 1082e0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
44 changes: 16 additions & 28 deletions electron/exposes/scrcpy/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,26 @@ import { replaceIP } from '$renderer/utils/index.js'
* }>} Array of parsed app objects
*/
export function parseScrcpyAppList(rawText) {
try {
// Split by lines and filter out non-app lines
const lines = rawText.split('\n').filter((line) => {
const trimmed = line.trim()
return trimmed.startsWith('*') || trimmed.startsWith('-')
})

return lines.map((line) => {
// Remove leading * or - and trim
const cleanLine = line.trim().replace(/^[*\-]\s+/, '')

// Extract app name and package name using a more precise regex
// Matches any characters up to the last [ followed by package name and ]
const match = cleanLine.match(/^([^[]+)\[([^\]]+)\]$/)

if (!match) {
return null
}
if (typeof rawText !== 'string') {
throw new TypeError('scrcpy content must be a string')
}

const [, name, packageName] = match
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: name.trim(),
packageName: packageName.trim(),
isSystemApp: line.trim().startsWith('*'),
name: content.substring(0, lastSpaceIndex).trim(),
packageName: content.substring(lastSpaceIndex + 1).trim(),
isSystemApp,
}
}).filter(item => item !== null)
}
catch (error) {
console.error('Error parsing scrcpy app list:', error)
return []
}
})
}

/**
Expand Down
2 changes: 1 addition & 1 deletion electron/exposes/scrcpy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async function startApp(serial, args = {}) {
commands += ` --start-app=${packageName}`
}

const res = await mirror(serial, { ...options, args: commands, signal: /display id: (\d+)/i })
const res = await mirror(serial, { ...options, args: commands, signal: /New display:.+?\(id=(\d+)\)/i })

const displayId = res?.[1]

Expand Down

0 comments on commit 1082e0d

Please sign in to comment.