From 1082e0d6623a5e91af37ff206c4dc4e6023b64fa Mon Sep 17 00:00:00 2001 From: viarotel Date: Mon, 25 Nov 2024 14:34:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Make=20StartApp=20compati?= =?UTF-8?q?ble=20with=20scrcpy=20v3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/exposes/scrcpy/helper.js | 44 +++++++++++-------------------- electron/exposes/scrcpy/index.js | 2 +- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/electron/exposes/scrcpy/helper.js b/electron/exposes/scrcpy/helper.js index 3a8cf4c6..62dab81e 100644 --- a/electron/exposes/scrcpy/helper.js +++ b/electron/exposes/scrcpy/helper.js @@ -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 [] - } + }) } /** diff --git a/electron/exposes/scrcpy/index.js b/electron/exposes/scrcpy/index.js index 506c987f..fd9e5b47 100644 --- a/electron/exposes/scrcpy/index.js +++ b/electron/exposes/scrcpy/index.js @@ -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]