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:
@@ -0,0 +1,165 @@
|
||||
import CoreGraphics
|
||||
import Foundation
|
||||
import ShotdeckCore
|
||||
import Testing
|
||||
|
||||
// Which window a capture takes, for each scope — pure logic over the window list the
|
||||
// window server reports, so it is testable without a display session.
|
||||
|
||||
private func window(
|
||||
id: UInt32,
|
||||
bundle: String?,
|
||||
pid: Int32 = 100,
|
||||
frame: CGRect = CGRect(x: 100, y: 100, width: 800, height: 600),
|
||||
layer: Int = 0
|
||||
) -> WindowCandidate {
|
||||
WindowCandidate(
|
||||
windowID: id, ownerBundleID: bundle, ownerPID: pid, frame: frame, layer: layer)
|
||||
}
|
||||
|
||||
@Test
|
||||
func windowScopeTakesTheFrontWindowOfTheFrontApp() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: "com.apple.Safari", pid: 10),
|
||||
window(id: 2, bundle: "com.apple.Terminal", pid: 20),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 20, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
func windowScopeFallsBackToTheFrontmostWindowOfAnyApp() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: "com.apple.Safari", pid: 10),
|
||||
window(id: 2, bundle: "com.apple.Terminal", pid: 20),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 99, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
func redlineNeverCapturesItself() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: CaptureTargetResolver.ownBundleID, pid: 5),
|
||||
window(id: 2, bundle: "com.apple.Safari", pid: 10),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 5, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
func chromeAndDesktopWindowsAreNotCandidates() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: "com.apple.dock", layer: 20),
|
||||
window(id: 2, bundle: "com.apple.WindowManager", layer: 8),
|
||||
window(id: 3, bundle: "com.apple.Safari"),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 0, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 3)
|
||||
}
|
||||
|
||||
@Test
|
||||
func tinyWindowsAreIgnored() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: "com.apple.Safari", frame: CGRect(x: 0, y: 0, width: 20, height: 20)),
|
||||
window(id: 2, bundle: "com.apple.Terminal"),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 0, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
func browserScopeTakesTheFrontBrowserWindow() throws {
|
||||
let candidates = [
|
||||
window(id: 1, bundle: "com.apple.Terminal", pid: 10),
|
||||
window(id: 2, bundle: "com.google.Chrome", pid: 11),
|
||||
window(id: 3, bundle: "com.apple.Safari", pid: 12),
|
||||
]
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .browser, savedArea: nil, frontmostPID: 10, candidates: candidates)
|
||||
guard case .window(let id, _, _) = target else {
|
||||
Issue.record("expected a window target, got \(target)")
|
||||
return
|
||||
}
|
||||
#expect(id == 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
func browserScopeSaysSoWhenNoBrowserIsOpen() {
|
||||
let candidates = [window(id: 1, bundle: "com.apple.Terminal")]
|
||||
#expect(throws: ShotdeckError.self) {
|
||||
_ = try CaptureTargetResolver.resolve(
|
||||
scope: .browser, savedArea: nil, frontmostPID: 10, candidates: candidates)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func windowScopeSaysSoWhenThereIsNoWindow() {
|
||||
#expect(throws: ShotdeckError.self) {
|
||||
_ = try CaptureTargetResolver.resolve(
|
||||
scope: .window, savedArea: nil, frontmostPID: 10,
|
||||
candidates: [window(id: 1, bundle: "com.apple.dock", layer: 20)])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func areaScopeUsesTheSavedAreaAndSaysWhenThereIsNone() throws {
|
||||
let area = CaptureRegion(
|
||||
displayID: CGMainDisplayID(), rect: CGRect(x: 10, y: 20, width: 300, height: 200),
|
||||
capturedScale: 2)
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .area, savedArea: area, frontmostPID: 0, candidates: [])
|
||||
#expect(target == .region(area))
|
||||
|
||||
#expect(throws: ShotdeckError.self) {
|
||||
_ = try CaptureTargetResolver.resolve(
|
||||
scope: .area, savedArea: nil, frontmostPID: 0, candidates: [])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func screenScopeUsesTheAreaDisplay() throws {
|
||||
let area = CaptureRegion(
|
||||
displayID: CGMainDisplayID(), rect: CGRect(x: 10, y: 20, width: 300, height: 200),
|
||||
capturedScale: 2)
|
||||
let target = try CaptureTargetResolver.resolve(
|
||||
scope: .screen, savedArea: area, frontmostPID: 0, candidates: [])
|
||||
#expect(target == .display(displayID: area.displayID))
|
||||
}
|
||||
|
||||
@Test
|
||||
func captureScopeDescriptionsNameWhatWillBeTaken() {
|
||||
let area = CaptureRegion(
|
||||
displayID: CGMainDisplayID(), rect: CGRect(x: 0, y: 0, width: 800, height: 600),
|
||||
capturedScale: 2)
|
||||
#expect(CaptureScope.area.targetDescription(savedArea: area).contains("800 × 600"))
|
||||
#expect(CaptureScope.area.targetDescription(savedArea: nil).contains("No area"))
|
||||
#expect(CaptureScope.window.targetDescription(savedArea: area).contains("frontmost window"))
|
||||
#expect(CaptureScope.browser.targetDescription(savedArea: area).contains("browser"))
|
||||
#expect(CaptureScope.screen.targetDescription(savedArea: area).contains("Display"))
|
||||
}
|
||||
Reference in New Issue
Block a user