Skip to content

Simplify capture and preview code and restore fast startup - #486

Merged
rz-openai merged 16 commits into
mainfrom
dev/rz/architecture-simplification
Oct 6, 2026
Merged

rz-openai merged 16 commits into
mainfrom
dev/rz/architecture-simplification

Conversation

@rz-openai

@rz-openai rz-openai commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Capture, preview, and window code shared responsibility for the same work. Starting, stopping, and switching views required several objects to coordinate cleanup. This PR separates window state from running operations and gives each resource a clear owner.

Summary

New ownership boundaries

Component Responsibility
AppRuntime / CaptureWorkspaces Create shared services and window sessions. Start device discovery and capture preparation early. Wait for window and service cleanup when the app quits.
CaptureWindowSession Connect window layout to the capture and tool panes. Pass visibility changes to each pane. Close both when the window closes.
CapturePaneSession Handle capture commands, navigation, device selection, and this pane's preview attachment. Keep transport, recording, and export work in their owners.
ScreenshotCapture / RecordingCapture Implement CaptureBatch. Own each device's tasks, temporary files, results, failures, and cleanup. Each device has a stable CaptureItem from the start. Batches do not write to history.
CaptureReviewState Read the batch's items directly. Own review selection, crop and trim edits, playback, and save/export requests. Retain accepted exports until they finish.
LivePreviewService / DevicePreview Share one preview owner per device connection. Give each window its own attachment. Manage video, input, and cleanup without moving these resources into the window.
CaptureCoordinator Reject conflicting work on the same connection. Allow only one recording per emulator connection. Bug-report recording requires exclusive use of its connection.

Capture and review use one source of results

The capture pane has two content states:

enum CapturePaneContent {
  case live(recording: RecordingCapture?)
  case review(CaptureReviewState)
}

Recording stays in the live state, so users can keep watching and switching devices. The picker uses that recording's pending or recording items. Failed devices leave the picker without removing healthy devices. Device Manager and device links can switch between recording targets without stopping the batch.

Review reads the same batch and items, without a separate array of completed results. Pending, ready, failed, and cancelled are item states. Review can appear before every device finishes. New results do not change the selected item. Crop and trim edits stay in review; export code applies them when writing media. Save writes the reviewed media to one history entry. Discard removes temporary files. Saved capture history remains a separate app-wide collection.

Preview sharing follows actual use

Each pane attaches only to the device it displays, not every device in its picker. Two windows showing the same connection share video and device input resources. Selection, rendering, visibility, file-drop work, and control UI remain local to each attachment.

PreviewVideo owns video startup, retries, and stopping. A video failure can recover without restarting healthy keyboard or clipboard resources. The shared service grants input to one attachment at a time and controls clipboard syncing. Video pauses when no attached pane needs it. Closing one attachment leaves other viewers running. The last attachment waits for shared preview cleanup.

Cleanup remains owned after navigation

  • Stop recording: create review immediately, keeping the selected device. The batch collects each recording and updates its existing item.
  • Return to live: show live preview immediately. Retain the old review until its batch and cleanup finish in the background. Prefer its selected device, then remaining batch devices in order, before new devices.
  • Close a window: close its capture and tool panes. Wait for capture work, exports, and preview releases instead of dropping tasks when views disappear.
  • Quit the app: stop accepting new work. Close windows and shared previews, then stop device tracking. Device connections remain available while operations restore temporary settings.

Temporary touch settings track their users. They restore the original setting only after the last user releases it. Connection-bound work uses DeviceTarget identity, so old work cannot act on a replacement connection.

Removed layers and supporting changes

  • Remove CaptureWindowController, CaptureSnapshotController, the old capture-window mode classes, and the old preview manager/lifecycle layer. Their responsibilities move to the owners above.
  • Simplify EmulatorDisplayReader with one result protected by a mutex. Preserve command ordering, first-reply handling, and the existing timeout. Restore the Android SDK installation message.
  • Group code by Workspace, Capture/Operations, Capture/Review, Capture/Export, and LivePreview input, rendering, and views.
  • Prepare startup work before the first window needs it. Look up emulator connection details off the main thread. Scans no longer delay the UI.
  • Gate recording on devices that have finished booting. Handle Snap-O URLs in the app delegate and reuse the active workspace. Update URLs no longer depend on scene routing. Capture, record, and live-preview URLs bring the window forward. Their commands are ignored while it records or saves, and never queued for later. The content owner supplies one replacement rule for both commands and buttons.

Tests check app decisions without running media services

  • Use controlled video metadata, exports, playback, and recording writers. Tests check crop and trim settings, frame timing, errors, and cleanup without processing real video.
  • Use in-memory clipboard contents, fake image results, and fake tool pages in state tests. Recording deadline tests use a controlled stream and TestClock, not socket timeouts.
  • Inject ADBConnection and ToolHTTPExchange in device and tool tests. Script replies, failures, and cancellation without real sockets. Test timers by advancing TestClock.
  • Test Escape decisions without a window. Keep two native routing checks that wait for focus events, with no wall-clock polling.
  • Check generated shell commands and signal cleanup directly, without running child processes.
  • Move pure state and command tests into Snap-OUnitTests. Shared test fixtures no longer require running another suite. Remove duplicate standalone runs and the empty preview-lifetime runner.
  • Use fake HTTP responses and event queues for CLI commands and interception handlers. Trigger reloads directly instead of waiting for the polling interval. Keep separate tests for socket framing and cleanup.

CI diagnostics

Save full build and test logs as artifacts, with short progress updates in the live log. If a test step runs for 45 seconds, capture process stacks, memory, and disk use. Keep existing test and job timeouts.

Validation

  • Debug app build, SwiftFormat, configured strict SwiftLint, shell syntax, and diff checks pass.
  • Headless unit suite: 222 tests reported, no failures. Used build-for-testing followed by test-without-building. New display-reader tests use fake replies that return at once, without XPC or timed waits.
  • Full app-hosted suite: 180 tests reported, no failures. Four opt-in file-transfer tests remain skipped by their existing conditions.
  • The full Mac test job passed locally in 2m14s using Xcode 26.4.1 and a fresh build directory. Both test schemes and all ten standalone checks passed. Package and compiler caches were reused.
  • The diagnostic wrapper passed five mocked checks for logging, failures, sampling, and cancellation. All 222 headless tests also passed through the wrapper.
  • CLI suites pass: 75 Tweaks tests and 76 Network tests.
  • Earlier startup measurement: three warm launches per version, from process launch to the first emulator frame. The median fell from 740 ms to 491 ms. We have not repeated this measurement after the test changes. Cold-machine startup remains unmeasured.
  • Full CI still needs to pass. Recent runs passed the build but stopped reporting progress in the unit-test step. The cause remains unconfirmed; the added diagnostics will help identify it.
  • Actual macOS URL delivery, manual crop/drag, and tool-pane checks remain before merge.

Bind device work to connection lifetimes and give captures, previews,
input, and exports explicit cleanup owners. Coordinate startup, recording
finalization, and shutdown without dropping pending work.

Expand regression coverage for device replacement, cancellation, shared
previews, and media exports.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T19:58:10.225625Z d83b0d7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@rz-openai rz-openai changed the title Clarify capture, preview, and device resource ownership Simplify capture and preview code and restore fast startup Oct 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35eb6aed8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-O/Capture/CapturePaneSession.swift Outdated
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39b1545f61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-O/App/SnapOApp.swift Outdated
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 543e60c05b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6bed7ac0eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-O/Capture/CapturePaneSession.swift
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: fd7f34edfc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1e3aac42d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-O/App/AppRuntime.swift Outdated
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8dafb48566

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-OIntegrationTests/Capture/CaptureReviewEscapeTests.swift Outdated
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: e0569b92d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5fbbfdf063

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app-macos/Snap-O/Capture/CapturePaneSession.swift
Replace unnecessary native and CLI integration work with controlled inputs. Move independent suites into the headless target and remove duplicate runners. Keep busy-window command handling on one content replacement rule.
@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: fd8cbd149f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rz-openai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: d83b0d7d37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rz-openai
rz-openai merged commit 9bc4b83 into main Oct 6, 2026
15 checks passed
@rz-openai
rz-openai deleted the dev/rz/architecture-simplification branch October 6, 2026 21:01
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