feat(capture): choose what to capture — area, window, browser page or screen
Capture is now a decision, not a hidden setting. The popover shows a four-way scope control with the target named under it (800 x 600 on Display 1, the frontmost window, the front browser window, the whole display), and the window header carries the same choice beside the verbs. Picking Window or Browser hides Redline, dims the screen, names the app under the pointer and highlights its window; a click captures exactly that window, Escape cancels, and the desktop highlights the whole screen. New Session is one click: the current captures stay in their own folder, a fresh session opens, and the area picker comes straight up with the saved area pre-selected — Return keeps it, a drag replaces it. Settings is consolidated into one door (the popover gear, plus Cmd-,): what to capture, saved area, shortcut, ask-on-new-session, sending, session age limit, and a new Updates group with automatic install (on by default; installs only when nothing is unsent). The footer filler and the extra-actions menu are gone.
This commit is contained in:
+130
-19
@@ -44,6 +44,13 @@ public final class AppModel {
|
||||
/// The user's age limit for kept sessions (Settings > Sessions). `.never` until
|
||||
/// the user chooses otherwise, so every session is saved by default.
|
||||
public private(set) var retention: SessionRetention = .never
|
||||
/// What Capture takes: the saved area, the front window, a browser window, or a
|
||||
/// whole display. Kept across sessions; changing it never clears the saved area.
|
||||
public private(set) var captureScope: CaptureScope = .area
|
||||
/// Whether "New Session…" asks what to capture before starting.
|
||||
public private(set) var askWhatToCaptureOnNewSession = true
|
||||
/// Whether a downloaded update installs itself the next time nothing is unsent.
|
||||
public private(set) var autoInstallUpdates = true
|
||||
/// How many archived sessions the current age limit would delete right now.
|
||||
/// Recomputed on launch, on a policy change and after every cleanup.
|
||||
public private(set) var expiredSessionCount: Int = 0
|
||||
@@ -84,6 +91,7 @@ public final class AppModel {
|
||||
let capturer: ScreenCapturer
|
||||
let hotkeys: HotkeyCenter
|
||||
let picker: RegionPickerController
|
||||
let windowPicker = WindowPickerController()
|
||||
let ledger: ReturnLedger
|
||||
let watcher: ReturnWatcher
|
||||
let updateChecker: UpdateChecker
|
||||
@@ -136,6 +144,7 @@ public final class AppModel {
|
||||
guard let self else { return }
|
||||
self.updateAvailable = self.updateChecker.availableUpdate
|
||||
self.setUpdateStatus(self.updateChecker.statusMessage)
|
||||
self.installStagedUpdateIfIdle()
|
||||
}
|
||||
self.updateChecker.onCheckingChanged = { [weak self] checking in
|
||||
self?.isCheckingForUpdates = checking
|
||||
@@ -171,6 +180,7 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
func setSelectedSessionID(_ value: UUID?) { selectedSessionID = value }
|
||||
func setCaptureScope(_ scope: CaptureScope) { captureScope = scope }
|
||||
func requestLaneFocus() { laneFocusRequest += 1 }
|
||||
func setFolderDisplayNames(outbox: String, watch: String) {
|
||||
outboxDisplayName = outbox
|
||||
@@ -502,6 +512,9 @@ public final class AppModel {
|
||||
|
||||
public func bootstrap() async {
|
||||
retention = RetentionSettings.load(defaults: retentionDefaults)
|
||||
captureScope = CaptureSettings.scope(defaults: retentionDefaults)
|
||||
askWhatToCaptureOnNewSession = CaptureSettings.askOnNewSession(defaults: retentionDefaults)
|
||||
autoInstallUpdates = UpdateSettings.autoInstall(defaults: retentionDefaults)
|
||||
await spool.setRetention(retention)
|
||||
|
||||
if let data = UserDefaults.standard.data(forKey: CaptureRegion.defaultsKey),
|
||||
@@ -605,6 +618,28 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// Turning automatic updates on/off. On is the default: a staged update installs as
|
||||
/// soon as the app has nothing unsent.
|
||||
public func setAutoInstallUpdates(_ value: Bool) {
|
||||
autoInstallUpdates = value
|
||||
UpdateSettings.setAutoInstall(value, defaults: retentionDefaults)
|
||||
installStagedUpdateIfIdle()
|
||||
}
|
||||
|
||||
/// Installs a staged update when it is safe to restart: nothing captured in the open
|
||||
/// session is waiting to be sent, and no capture or send is in flight. Called after
|
||||
/// every update check, after a send, and after a new session starts — the moments
|
||||
/// the app becomes idle.
|
||||
func installStagedUpdateIfIdle() {
|
||||
guard autoInstallUpdates,
|
||||
updateAvailable != nil,
|
||||
session.isEmpty,
|
||||
!isSending,
|
||||
!isCapturing
|
||||
else { return }
|
||||
updateChecker.installStaged()
|
||||
}
|
||||
|
||||
/// Installs the staged update over `/Applications/Redline.app` and relaunches.
|
||||
/// Does nothing unless the user clicked the menu row.
|
||||
public func installUpdate() {
|
||||
@@ -652,26 +687,44 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// The line shown under the capture control: what the next capture will take.
|
||||
public var captureTargetDescription: String {
|
||||
captureScope.targetDescription(savedArea: region)
|
||||
}
|
||||
|
||||
/// Picks the scope for the session being captured into and persists it. Choosing a
|
||||
/// scope other than Area keeps the saved area untouched.
|
||||
public func chooseCaptureScope(_ scope: CaptureScope) async {
|
||||
captureScope = scope
|
||||
CaptureSettings.setScope(scope, defaults: retentionDefaults)
|
||||
setStatus(nil)
|
||||
if scope == .area, region == nil {
|
||||
await rePickRegion()
|
||||
}
|
||||
}
|
||||
|
||||
public func setAskWhatToCaptureOnNewSession(_ value: Bool) {
|
||||
askWhatToCaptureOnNewSession = value
|
||||
CaptureSettings.setAskOnNewSession(value, defaults: retentionDefaults)
|
||||
}
|
||||
|
||||
public func captureNow() async {
|
||||
await capture(scope: captureScope)
|
||||
}
|
||||
|
||||
/// Captures whatever the chosen scope points at.
|
||||
///
|
||||
/// Any picker runs with Redline's own windows hidden, so the panel never covers —
|
||||
/// or ends up inside — the thing being captured.
|
||||
public func capture(scope: CaptureScope) async {
|
||||
guard !isCapturing else { return }
|
||||
setCapturing(true)
|
||||
defer { setCapturing(false) }
|
||||
|
||||
var target = region
|
||||
if target == nil {
|
||||
target = await withCheckedContinuation { (cont: CheckedContinuation<CaptureRegion?, Never>) in
|
||||
picker.pick { picked in cont.resume(returning: picked) }
|
||||
}
|
||||
guard let picked = target else {
|
||||
setStatus("No region selected.")
|
||||
return
|
||||
}
|
||||
persistRegion(picked)
|
||||
}
|
||||
guard let region = target else { return }
|
||||
|
||||
do {
|
||||
let image = try await capturer.capture(region)
|
||||
let target = try await resolveTarget(for: scope)
|
||||
guard let target else { return }
|
||||
let image = try await capturer.capture(target)
|
||||
let capture = try await spool.append(
|
||||
pngData: image.pngData,
|
||||
pixelWidth: image.pixelWidth,
|
||||
@@ -687,13 +740,71 @@ public final class AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
public func rePickRegion() async {
|
||||
let picked = await withCheckedContinuation { (cont: CheckedContinuation<CaptureRegion?, Never>) in
|
||||
picker.pick { cont.resume(returning: $0) }
|
||||
/// Works out what to capture, presenting the area or window picker when the scope
|
||||
/// needs one. nil means the user backed out — nothing to say about it.
|
||||
private func resolveTarget(for scope: CaptureScope) async throws -> CaptureTarget? {
|
||||
switch scope {
|
||||
case .area:
|
||||
var area = region
|
||||
if area == nil {
|
||||
area = await pickArea(confirming: nil)
|
||||
guard let picked = area else { return nil }
|
||||
persistRegion(picked)
|
||||
}
|
||||
guard let area else { return nil }
|
||||
return .region(area)
|
||||
|
||||
case .window, .browser:
|
||||
return await pickWindow(onlyBrowsers: scope == .browser)
|
||||
|
||||
case .screen:
|
||||
if let area = region {
|
||||
return .display(displayID: area.displayID)
|
||||
}
|
||||
return .display(displayID: CGMainDisplayID())
|
||||
}
|
||||
guard let picked else { return }
|
||||
}
|
||||
|
||||
/// Hides Redline, runs the area picker, then restores Redline's windows.
|
||||
private func pickArea(confirming saved: CaptureRegion?) async -> CaptureRegion? {
|
||||
RedlineWindows.hideForPicking()
|
||||
defer { RedlineWindows.restoreAfterPicking() }
|
||||
return await withCheckedContinuation { (continuation: CheckedContinuation<CaptureRegion?, Never>) in
|
||||
picker.pick(confirming: saved) { picked in
|
||||
continuation.resume(returning: picked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Hides Redline, runs the window picker (hover highlights, click chooses), then
|
||||
/// restores Redline's windows.
|
||||
private func pickWindow(onlyBrowsers: Bool) async -> CaptureTarget? {
|
||||
RedlineWindows.hideForPicking()
|
||||
defer { RedlineWindows.restoreAfterPicking() }
|
||||
return await withCheckedContinuation { (continuation: CheckedContinuation<CaptureTarget?, Never>) in
|
||||
windowPicker.pick(onlyBrowsers: onlyBrowsers) { picked in
|
||||
continuation.resume(returning: picked)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Picks a new area and remembers it (the "Choose Area…" action).
|
||||
public func rePickRegion() async {
|
||||
guard let picked = await pickArea(confirming: region) else { return }
|
||||
persistRegion(picked)
|
||||
setStatus("Region set: \(Int(picked.rect.width)) × \(Int(picked.rect.height)).")
|
||||
setStatus("\(picked.summary) saved.")
|
||||
}
|
||||
|
||||
/// One-click "New Session": the current session is kept as a past session (its
|
||||
/// screenshots stay in their own folder and its PDF keeps its name), a fresh one
|
||||
/// opens, and — when the user asked to be asked — the area picker comes straight up
|
||||
/// so the next capture starts with the right area. Return keeps the saved area.
|
||||
public func newSession() async {
|
||||
await startNewSession()
|
||||
guard askWhatToCaptureOnNewSession, captureScope == .area else { return }
|
||||
if let picked = await pickArea(confirming: region) {
|
||||
persistRegion(picked)
|
||||
}
|
||||
}
|
||||
|
||||
public func removeCapture(id: UUID) async {
|
||||
|
||||
Reference in New Issue
Block a user