Skip to content

Commit 6682413

Browse files
Camera dead-code sweep (UI modernization PR 5) (#126)
Deletes dead code from CameraViewController found by the legacy audit: - sendCameraCapabilities() — superseded by the retry-ladder capabilities push in CamStates.swift; no callers - getCurrentTorchMode(), hasTorch(), setFlashMode() — leftovers of a prior migration whose comment claimed they were already removed - willAnimateRotation(to:duration:) — deprecated UIKit callback never invoked on iOS 15+; viewWillTransition is the live rotation path - Stale migration comments Deletion only, no behavior change. 371/371 tests pass. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 924079d commit 6682413

2 files changed

Lines changed: 34 additions & 62 deletions

File tree

Docs/UI_MODERNIZATION.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ the refactor under them:
8787
replace 5 copies of the embed boilerplate and 4 copies of the help-sheet code
8888
- Dead `connectedPrompt`, `pinchGestureRecognizer`, `lastPinchScale` removed
8989

90-
### PR 4: Decouple MonitorActor from MonitorViewController — **this PR**
90+
### PR 4: Decouple MonitorActor from MonitorViewController — **shipped (#125)**
9191
- New `MonitorDisplay` protocol — everything the actor needs from the monitor screen
9292
(mode configuration, view-model updates, frame routing, exit navigation).
9393
- `MonitorActor` moved out of MonitorViewController.swift into `MonitorActor.swift` and
@@ -102,13 +102,30 @@ the refactor under them:
102102
- `RemoteCamSession`'s `ViewCtrlActor<DeviceScannerViewController>` binding is the
103103
remaining coupling — PR 5.
104104

105-
### PR 5: Decouple RemoteCamSession from DeviceScannerViewController
105+
### PR 5: Camera dead-code sweep — **this PR**
106+
An audit of CameraViewController (1,729 lines) found it ~65% capture-engine code in a
107+
UIViewController costume, ~25% real UI, ~10% dead/deprecated. This PR is the deletion
108+
slice only: `sendCameraCapabilities()` (superseded by the retry-ladder push in
109+
CamStates.swift), `getCurrentTorchMode()`, `hasTorch()`, `setFlashMode()` (leftovers a
110+
prior migration's own comment claimed were "removed"), the deprecated
111+
`willAnimateRotation` stub, and tombstone comments.
112+
113+
### PR 6: Decouple RemoteCamSession from DeviceScannerViewController
106114
Re-target the session's lobby binding at a protocol/coordinator (same recipe as PR 4).
107115
Unblocks shrinking the DeviceScanner shell.
108116

109-
### PR 6+: Camera surface
110-
SwiftUI chrome around a `UIViewRepresentable` preview layer for `CameraViewController`;
111-
`WatchRemoteCameraController` follows.
117+
### PR 7: Extract CaptureEngine from CameraViewController
118+
Move the ~1,100 engine lines (session setup, lens/zoom/capabilities, photo capture +
119+
crop math, AVAssetWriter recording, sample-buffer streaming) into a non-UI class with
120+
one owned serial queue — today session config runs on the actor thread, start/stop on
121+
`cameraConfigQueue`, and setup on main, unsynchronized. This is also where
122+
`AVCaptureVideoOrientation` (deprecated iOS 17) migrates to
123+
`AVCaptureDevice.RotationCoordinator`, and `isHighResolutionPhotoEnabled`
124+
(deprecated iOS 16) to `maxPhotoDimensions`.
125+
126+
### PR 8+: Camera SwiftUI chrome
127+
With the engine out, the VC is ~400 lines of real UI: SwiftUI chrome around a
128+
`UIViewRepresentable` preview layer. `WatchRemoteCameraController` follows.
112129

113130
## Worklog (blog raw material)
114131

@@ -175,3 +192,15 @@ SwiftUI chrome around a `UIViewRepresentable` preview layer for `CameraViewContr
175192
against a fake display object. Before this PR that required a live UIKit controller.
176193
- PR 3's wiring + loopback tests passed unchanged across the swap — the safety net
177194
did its job on the first PR it was built for.
195+
196+
### PR 5 — camera dead-code sweep
197+
- The audit's best find: four torch/flash/capabilities methods that a comment in
198+
*another file* claimed were already removed ("Legacy setFlashMode and setTorchMode
199+
functions removed"). The comment was aspirational; the code was still compiling.
200+
- `sendCameraCapabilities()` told the story of its own replacement: it fire-and-forgot
201+
capabilities through the session actor's root receive, while the live path in
202+
CamStates.swift pushes with a 4-attempt retry ladder because the capture device
203+
isn't ready right after setup. The old path lost the race and nobody buried it.
204+
- Also filed for later (not deletions): the unsynchronized three-thread capture-session
205+
mutation, six-boolean recording state machine, and the iOS 16/17 AVFoundation
206+
deprecations — all queued for the PR 7 CaptureEngine extraction.

RemoteCam/CameraViewController.swift

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,6 @@ public class CameraViewController: UIViewController,
404404
return !isRecording
405405
}
406406

407-
public override func willAnimateRotation(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
408-
// Deprecated and not called on modern iOS; kept for any OS version that
409-
// still invokes it. `viewWillTransition` below is the live rotation path —
410-
// both funnel into the same idempotent orientation update.
411-
orientation = getOrientation()
412-
self.rotateCameraToOrientation(orientation: toInterfaceOrientation)
413-
}
414-
415407
public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
416408
super.viewWillTransition(to: size, with: coordinator)
417409
coordinator.animate(alongsideTransition: { [weak self] _ in
@@ -489,9 +481,6 @@ public class CameraViewController: UIViewController,
489481
}
490482
self.currentZoomFactor = videoDevice.videoZoomFactor
491483

492-
// Camera capabilities are now sent through peer-to-peer communication in CamStates.swift
493-
// No need to send to session actor directly here
494-
495484
// Audio setup will be done only when starting video recording
496485
// This prevents requesting microphone permission upfront
497486
self.configSessionOutput()
@@ -629,29 +618,6 @@ public class CameraViewController: UIViewController,
629618
}
630619
}
631620

632-
func getCurrentTorchMode() -> AVCaptureDevice.TorchMode {
633-
return videoDeviceInput?.device.torchMode ?? .off
634-
}
635-
636-
func hasTorch() -> Bool {
637-
return videoDeviceInput?.device.hasTorch ?? false
638-
}
639-
640-
func setFlashMode(mode: AVCaptureDevice.FlashMode, device: AVCaptureDevice) -> Try<AVCaptureDevice.FlashMode> {
641-
if device.hasFlash {
642-
do {
643-
try device.lockForConfiguration()
644-
self.cameraSettings.flashMode = mode
645-
device.unlockForConfiguration()
646-
} catch let error as NSError {
647-
return Failure(error: error)
648-
} catch {
649-
return Failure(error: NSError(domain: "Unknown error", code: 0, userInfo: nil))
650-
}
651-
}
652-
return Success(mode)
653-
}
654-
655621
// MARK: - Virtual Device Preference
656622

657623
/// Returns the best camera device for the given position, preferring virtual devices.
@@ -856,25 +822,6 @@ public class CameraViewController: UIViewController,
856822
)
857823
}
858824

859-
func sendCameraCapabilities() {
860-
guard let currentDevice = self.videoDeviceInput?.device else { return }
861-
862-
let capabilities = RemoteCmd.CameraCapabilitiesResp(
863-
frontCamera: frontCameraInfo,
864-
backCamera: backCameraInfo,
865-
currentCamera: currentDevice.position,
866-
currentLens: currentLensType,
867-
currentZoom: currentZoomFactor,
868-
currentVideoResolution: currentVideoResolution,
869-
currentVideoFrameRate: currentVideoFrameRate,
870-
currentPhotoFormat: currentPhotoFormat,
871-
currentHDRMode: currentHDRMode,
872-
error: nil
873-
)
874-
875-
session ! capabilities
876-
}
877-
878825
// MARK: - Current Camera Capabilities for Toggle Response
879826
func gatherCurrentCameraCapabilities() -> RemoteCmd.CameraCapabilitiesResp? {
880827
debugLog("🔍 DEBUG: gatherCurrentCameraCapabilities called")
@@ -1540,10 +1487,6 @@ extension CameraViewController: AVCaptureVideoDataOutputSampleBufferDelegate, AV
15401487
print("📤 DEBUG: Sent SendVideoResource message to actor system")
15411488
}
15421489

1543-
// MARK: - Video Transfer Progress
1544-
// Video transfer progress is now handled directly in CameraVideoStates.swift
1545-
// via the direct ctrl reference passed to camera states
1546-
15471490
func setupAssetWriterVideoInput(_ formatDescription: CMVideoFormatDescription,
15481491
assetWriter: AVAssetWriter) -> Bool {
15491492
var videoSettings = self.videoDataOutput.recommendedVideoSettingsForAssetWriter(writingTo: .mov)

0 commit comments

Comments
 (0)