重写真机虚拟屏幕生命周期 by megumiss · Pull Request #301 · megumiss/NIKKEAutoScript · GitHub
Skip to content

重写真机虚拟屏幕生命周期 - #301

Open
megumiss wants to merge 3 commits into
masterfrom
codex/virtual-display-minimal
Open

megumiss wants to merge 3 commits into
masterfrom
codex/virtual-display-minimal

Conversation

@megumiss

@megumiss megumiss commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Sourcery 摘要

将物理设备的虚拟显示器作为由后端拥有的持久会话进行管理,并将所有现有控制连接到经过验证的当前屏幕。

新功能:

  • 添加稳定的虚拟显示器标识符,在重新创建后仍保持不变,同时报告当前 Android 显示器 ID 和会话元数据。
  • 为 WebUI 控件公开受管理的虚拟显示器目标,并将 WebUI 和移动端控制连接到现有屏幕,而不是创建重复的显示器。

错误修复:

  • 当受管理的目标不可用时,防止虚拟显示器输入、屏幕截图、应用启动和控制连接静默回退到主显示器。
  • 在 worker 停止期间保留有效显示器,并将清理范围限制为经过验证的会话、设备、进程和转发。
  • 使实例副本获得独立的虚拟显示器标识符,并改进对同名 Windows 游戏实例的进程匹配。

增强功能:

  • 将虚拟显示器的所有权和生命周期管理移至后端会话管理器,并支持 worker IPC、取消、复用、恢复和定向清理。
  • 改进后端和服务的关闭处理,确保在报告成功之前验证 worker 终止和资源清理已完成。
  • 在帧捕获和客户端通信期间,更安全地处理虚拟显示器桥接断开和会话变更。

部署:

  • 为后端进程添加基于所有权的服务停止机制,并报告未完成的虚拟显示器清理。

文档:

  • 记录虚拟显示器的标识、生命周期、恢复、控制行为和验证约束。

测试:

  • 增加对稳定标识迁移和并发、会话复用和所有权、取消和清理、API 目标解析、服务关闭以及受保护的 Windows 进程控制的测试覆盖。
Original summary in English

Summary by Sourcery

Manage physical-device virtual displays as persistent backend-owned sessions and reconnect all existing controls to the verified current screen.

New Features:

  • Add stable virtual-display identities that persist across recreation while reporting the current Android display ID and session metadata.
  • Expose the managed virtual-display target for WebUI controls and connect WebUI and mobile control to the existing screen without creating duplicate displays.

Bug Fixes:

  • Prevent virtual-display input, screenshots, application startup, and control connections from silently falling back to the primary display when the managed target is unavailable.
  • Preserve valid displays across worker stops and restrict cleanup to verified sessions, devices, processes, and forwards.
  • Make instance copies receive independent virtual-display identities and improve process matching for same-named Windows game instances.

Enhancements:

  • Move virtual-display ownership and lifecycle management into a backend session manager with worker IPC, cancellation, reuse, recovery, and targeted cleanup.
  • Improve backend and service shutdown handling so worker termination and resource cleanup are verified before reporting success.
  • Handle virtual-display bridge disconnects and session changes more safely during frame capture and client communication.

Deployment:

  • Add ownership-aware service stopping for backend processes and incomplete virtual-display cleanup reporting.

Documentation:

  • Document virtual-display identity, lifecycle, recovery, control behavior, and validation constraints.

Tests:

  • Add coverage for stable identity migration and concurrency, session reuse and ownership, cancellation and cleanup, API target resolution, service shutdown, and guarded Windows process control.
Original summary in English

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @megumiss, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 1 hour by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New security issues found

Comment on lines +40 to +44
result = subprocess.run(
[self.adb_binary, '-s', self.serial, *map(str, args)],
capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=timeout,
creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

Comment on lines +314 to +318

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'Popen' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant