Skip to content

Commit 07d6a62

Browse files
committed
optimize: Update changelog
optimize: Update index optimize: Update render optimize: Update main optimize: Update type.d optimize: Update en-US optimize: Update zh-CN optimize: Update device
1 parent 6c75c84 commit 07d6a62

8 files changed

Lines changed: 275 additions & 99 deletions

File tree

‎changelog.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
- 新增:摄像头投屏支持枚举手机摄像头(含超广角、外接摄像头),按实际能力选择分辨率与帧率,新增画面方向、变焦、手电筒、码率与置顶/全屏/无边框开关,并记住上次选择
44
- 优化:摄像头启动失败时显示真实原因(相机被占用、权限拒绝等),关闭摄像头窗口或删除设备时结束残留进程
5+
- 修复:连接自动投屏时会先弹出「投屏失败」、随后画面又正常出现的问题,现在只有真正没连上才报失败,投上之后再掉线只提示设备已断开
6+
- 修复:投屏期间同时运行预览进程,部分机型会因两个画面编码互相抢占而让投屏断开,现在投屏时不再额外启动预览,投屏结束后自动恢复预览
7+
- 修复:部分机型预览进程反复启动失败时每几秒重试一次,导致投屏窗口被拖断、投屏状态反复跳变,现在失败会逐步退避并在多次失败后停止重试
8+
- 修复:设备已经从电脑断开时仍会尝试拉起投屏窗口并报错,现在会先确认设备在线,掉线重连时也不会短时间内反复弹窗
59

610
## v2.5.0 自动更新上线,软件自己检查并安装新版本
711

‎electron/mapi/app/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const spawnShell = async (
8484
env?: Record<string, any>
8585
shell?: boolean
8686
maxLogLines?: number // 0 = unlimited
87+
// 显式指定哪些退出码算成功(scrcpy 用 0=正常 / 1=启动失败 / 2=运行中掉线,
88+
// 不能用 Windows 下默认的 1 也算成功的规则)
89+
successExitCodes?: number[]
8790
} | null = null,
8891
): Promise<{
8992
stop: () => void
@@ -147,7 +150,11 @@ const spawnShell = async (
147150
// console.log('App.spawnShell.exit', code)
148151
Log.info('App.spawnShell.exit', {code, signal})
149152
exitCode = code
150-
if (isWin) {
153+
if (option.successExitCodes) {
154+
if (null !== code && option.successExitCodes.includes(code)) {
155+
isSuccess = true
156+
}
157+
} else if (isWin) {
151158
if (0 === code || 1 === code) {
152159
isSuccess = true
153160
}

‎electron/mapi/scrcpy/render.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const spawnShell = async (
2222
outputEncoding?: string
2323
env?: Record<string, any>
2424
maxLogLines?: number
25+
successExitCodes?: number[]
2526
} | null = null,
2627
) => {
2728
option = Object.assign(
@@ -204,6 +205,7 @@ const mirror = async (
204205
error?: (msg: string, exitCode: number, process: any) => void
205206
env?: Record<string, any>
206207
maxLogLines?: number
208+
successExitCodes?: number[]
207209
},
208210
) => {
209211
option = Object.assign(
@@ -222,6 +224,7 @@ const mirror = async (
222224
error: option.error,
223225
env: option.env,
224226
maxLogLines: option.maxLogLines,
227+
successExitCodes: option.successExitCodes,
225228
})
226229
}
227230

‎electron/mapi/serve/main.ts‎

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ const start = async (): Promise<number> => {
116116
Log.info(`${clientType}.msg.${deviceId}`, data)
117117
}
118118
} else if (clientType === 'DeviceMirror') {
119-
if (data.type === 'ready') {
119+
if (data.type === 'preview') {
120+
// 投屏进程也负责发送设备卡片预览图(投屏期间不再单独启动预览进程)
121+
broadcast('Render', {
122+
type: 'DevicePreview',
123+
deviceId,
124+
data: data.data,
125+
})
126+
} else if (data.type === 'ready') {
120127
ws.send(JSON.stringify(getPanelConfig(deviceId)))
121128
Log.info(`Sent panel config to DeviceMirror: deviceId=${deviceId}`)
122129
// 查询设备实际屏幕状态,确保图标与真实状态一致
@@ -312,6 +319,30 @@ const panelButtonToKeyCode = (buttonId: string): number | null => {
312319
return keyCodeMap[buttonId] || null
313320
}
314321

322+
// 随动目标:其它设备的预览进程或投屏进程(投屏期间预览进程已停止);
323+
// 同一设备可能同时有主投屏与应用投屏多个连接,每台设备只下发一次,避免手机上执行两次
324+
const followTargets = (sourceDeviceId: string): Array<{ws: WebSocket; deviceId: string; type: string}> => {
325+
const targets: Array<{ws: WebSocket; deviceId: string; type: string}> = []
326+
const seen = new Set<string>()
327+
wss?.clients.forEach((client) => {
328+
const ws = client as any
329+
const clientDeviceId = ws._deviceId
330+
const clientType = ws._clientType
331+
if (clientType !== 'DeviceManage' && clientType !== 'DeviceMirror') {
332+
return
333+
}
334+
if (!clientDeviceId || clientDeviceId === sourceDeviceId || seen.has(clientDeviceId)) {
335+
return
336+
}
337+
if (client.readyState !== WebSocket.OPEN) {
338+
return
339+
}
340+
seen.add(clientDeviceId)
341+
targets.push({ws: client, deviceId: clientDeviceId, type: clientType})
342+
})
343+
return targets
344+
}
345+
315346
// 处理面板按钮的随动模式 - 将按钮操作转换为key事件并广播
316347
const handlePanelButtonFollowMode = (sourceDeviceId: string, buttonId: string) => {
317348
const keyCode = panelButtonToKeyCode(buttonId)
@@ -343,25 +374,18 @@ const handlePanelButtonFollowMode = (sourceDeviceId: string, buttonId: string) =
343374
}
344375

345376
Log.info(`FollowMode: Broadcasting panel button from ${sourceDeviceId}`, buttonId)
346-
let targetCount = 0
347-
wss?.clients.forEach((client) => {
348-
if (client.readyState === WebSocket.OPEN) {
349-
const ws = client as any
350-
const clientDeviceId = ws._deviceId
351-
const clientType = ws._clientType
352-
if (clientType === 'DeviceManage' && clientDeviceId && clientDeviceId !== sourceDeviceId) {
353-
try {
354-
// 发送按下和抬起两个事件
355-
client.send(JSON.stringify(keyDownEvent))
356-
client.send(JSON.stringify(keyUpEvent))
357-
targetCount++
358-
Log.info(`FollowMode: Panel button sent to ${clientType}:${clientDeviceId} ${buttonId}->${keyCode}`)
359-
} catch (error) {
360-
Log.error(`FollowMode: Failed to send panel button to ${clientDeviceId}: ${error.message}`)
361-
}
362-
}
377+
const targets = followTargets(sourceDeviceId)
378+
for (const target of targets) {
379+
try {
380+
// 发送按下和抬起两个事件
381+
target.ws.send(JSON.stringify(keyDownEvent))
382+
target.ws.send(JSON.stringify(keyUpEvent))
383+
Log.info(`FollowMode: Panel button sent to ${target.type}:${target.deviceId} ${buttonId}->${keyCode}`)
384+
} catch (error) {
385+
Log.error(`FollowMode: Failed to send panel button to ${target.deviceId}: ${error.message}`)
363386
}
364-
})
387+
}
388+
const targetCount = targets.length
365389

366390
if (targetCount === 0) {
367391
Log.info(`FollowMode: No target devices to forward panel button (source: ${sourceDeviceId})`)
@@ -376,23 +400,16 @@ const broadcastRotateToOtherDevices = (sourceDeviceId: string) => {
376400
}
377401

378402
Log.info(`FollowMode: Broadcasting rotate from ${sourceDeviceId}`)
379-
let targetCount = 0
380-
wss?.clients.forEach((client) => {
381-
if (client.readyState === WebSocket.OPEN) {
382-
const ws = client as any
383-
const clientDeviceId = ws._deviceId
384-
const clientType = ws._clientType
385-
if (clientType === 'DeviceManage' && clientDeviceId && clientDeviceId !== sourceDeviceId) {
386-
try {
387-
client.send(JSON.stringify(rotateEvent))
388-
targetCount++
389-
Log.info(`FollowMode: Rotate sent to ${clientType}:${clientDeviceId}`)
390-
} catch (error) {
391-
Log.error(`FollowMode: Failed to send rotate to ${clientDeviceId}: ${error.message}`)
392-
}
393-
}
403+
const targets = followTargets(sourceDeviceId)
404+
for (const target of targets) {
405+
try {
406+
target.ws.send(JSON.stringify(rotateEvent))
407+
Log.info(`FollowMode: Rotate sent to ${target.type}:${target.deviceId}`)
408+
} catch (error) {
409+
Log.error(`FollowMode: Failed to send rotate to ${target.deviceId}: ${error.message}`)
394410
}
395-
})
411+
}
412+
const targetCount = targets.length
396413

397414
if (targetCount === 0) {
398415
Log.info(`FollowMode: No target devices to forward rotate (source: ${sourceDeviceId})`)
@@ -402,23 +419,16 @@ const broadcastRotateToOtherDevices = (sourceDeviceId: string) => {
402419
// 处理随动模式 - 在main进程中直接转发事件给其他设备,不经过Render进程
403420
const handleFollowMode = (sourceDeviceId: string, eventData: any) => {
404421
Log.info(`FollowMode: Broadcasting event from ${sourceDeviceId}`, eventData.type)
405-
let targetCount = 0
406-
wss?.clients.forEach((client) => {
407-
if (client.readyState === WebSocket.OPEN) {
408-
const ws = client as any
409-
const clientDeviceId = ws._deviceId
410-
const clientType = ws._clientType
411-
if (clientType === 'DeviceManage' && clientDeviceId && clientDeviceId !== sourceDeviceId) {
412-
try {
413-
client.send(JSON.stringify(eventData))
414-
targetCount++
415-
Log.info(`FollowMode: Event sent to ${clientType}:${clientDeviceId} ${JSON.stringify(eventData)}`)
416-
} catch (error) {
417-
Log.error(`FollowMode: Failed to send event to ${clientDeviceId}: ${error.message}`)
418-
}
419-
}
422+
const targets = followTargets(sourceDeviceId)
423+
for (const target of targets) {
424+
try {
425+
target.ws.send(JSON.stringify(eventData))
426+
Log.info(`FollowMode: Event sent to ${target.type}:${target.deviceId} ${JSON.stringify(eventData)}`)
427+
} catch (error) {
428+
Log.error(`FollowMode: Failed to send event to ${target.deviceId}: ${error.message}`)
420429
}
421-
})
430+
}
431+
const targetCount = targets.length
422432

423433
if (targetCount === 0) {
424434
Log.info(`FollowMode: No target devices to forward (source: ${sourceDeviceId})`)

‎src/declarations/type.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ type DefsMapi = {
505505
error?: (msg: string, exitCode: number, process: any) => void
506506
env?: Record<string, any>
507507
maxLogLines?: number
508+
successExitCodes?: number[]
508509
},
509510
) => Promise<any>
510511
}

‎src/lang/en-US.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ const messages: Messages = {
297297
'device.maxFps': 'Frame Rate',
298298
'device.maxFpsHint': 'Default 60, presets 30/60/90/120/144/240, or enter a custom value',
299299
'device.mirrorFailed': 'Mirror Failed',
300+
'device.mirrorDisconnected': 'Device disconnected, mirroring ended',
300301
'device.mirrorUnauthorized':
301302
'Device not authorized. Please tap "Allow USB debugging" on your phone to authorize the connection',
302303
'device.mirrorApp': 'Mirror an app',

‎src/lang/zh-CN.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ const messages: Messages = {
293293
'device.maxFps': '刷新率',
294294
'device.maxFpsHint': '默认 60,可选 30/60/90/120/144/240,也可直接输入自定义数值',
295295
'device.mirrorFailed': '投屏失败',
296+
'device.mirrorDisconnected': '设备连接已断开,投屏已结束',
296297
'device.mirrorUnauthorized': '手机未授权,请在手机上点击「允许 USB 调试」以授权连接',
297298
'device.mirrorApp': '应用投屏',
298299
'device.mirrorAppDesc': '在独立虚拟屏中投屏指定应用,不修改手机物理分辨率,手机可同时正常使用',

0 commit comments

Comments
 (0)