style: Apply SwiftFormat formatting

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Peter Steinberger 2025-06-08 06:19:17 +01:00
parent a10cbb59d5
commit cef648fa8f

View file

@ -1,7 +1,7 @@
import AppKit import AppKit
import CoreGraphics import CoreGraphics
import ScreenCaptureKit
@testable import peekaboo @testable import peekaboo
import ScreenCaptureKit
import Testing import Testing
@Suite( @Suite(
@ -237,7 +237,7 @@ struct ScreenshotValidationTests {
) throws -> ImageCaptureData { ) throws -> ImageCaptureData {
// Use modern ScreenCaptureKit API instead of deprecated CGWindowListCreateImage // Use modern ScreenCaptureKit API instead of deprecated CGWindowListCreateImage
let image = try captureWindowWithScreenCaptureKit(windowID: windowID) let image = try captureWindowWithScreenCaptureKit(windowID: windowID)
// Save to file // Save to file
let nsImage = NSImage(cgImage: image, size: NSSize(width: image.width, height: image.height)) let nsImage = NSImage(cgImage: image, size: NSSize(width: image.width, height: image.height))
try saveImage(nsImage, to: path, format: format) try saveImage(nsImage, to: path, format: format)
@ -253,55 +253,55 @@ struct ScreenshotValidationTests {
) )
]) ])
} }
private func captureWindowWithScreenCaptureKit(windowID: CGWindowID) throws -> CGImage { private func captureWindowWithScreenCaptureKit(windowID: CGWindowID) throws -> CGImage {
// This needs to be async, so we'll use a semaphore to make it synchronous for the test // This needs to be async, so we'll use a semaphore to make it synchronous for the test
var capturedImage: CGImage? var capturedImage: CGImage?
var captureError: Error? var captureError: Error?
let semaphore = DispatchSemaphore(value: 0) let semaphore = DispatchSemaphore(value: 0)
Task { Task {
do { do {
// Get available content // Get available content
let availableContent = try await SCShareableContent.current let availableContent = try await SCShareableContent.current
// Find the window by ID // Find the window by ID
guard let scWindow = availableContent.windows.first(where: { $0.windowID == windowID }) else { guard let scWindow = availableContent.windows.first(where: { $0.windowID == windowID }) else {
throw CaptureError.windowNotFound throw CaptureError.windowNotFound
} }
// Create content filter for the specific window // Create content filter for the specific window
let filter = SCContentFilter(desktopIndependentWindow: scWindow) let filter = SCContentFilter(desktopIndependentWindow: scWindow)
// Configure capture settings // Configure capture settings
let configuration = SCStreamConfiguration() let configuration = SCStreamConfiguration()
configuration.backgroundColor = .clear configuration.backgroundColor = .clear
configuration.shouldBeOpaque = true configuration.shouldBeOpaque = true
configuration.showsCursor = false configuration.showsCursor = false
// Capture the image // Capture the image
let image = try await SCScreenshotManager.captureImage( let image = try await SCScreenshotManager.captureImage(
contentFilter: filter, contentFilter: filter,
configuration: configuration configuration: configuration
) )
capturedImage = image capturedImage = image
} catch { } catch {
captureError = error captureError = error
} }
semaphore.signal() semaphore.signal()
} }
semaphore.wait() semaphore.wait()
if let error = captureError { if let error = captureError {
throw error throw error
} }
guard let image = capturedImage else { guard let image = capturedImage else {
throw CaptureError.windowCaptureFailed throw CaptureError.windowCaptureFailed
} }
return image return image
} }