diff --git a/peekaboo-cli/Tests/peekabooTests/ScreenshotValidationTests.swift b/peekaboo-cli/Tests/peekabooTests/ScreenshotValidationTests.swift index 841248d..72e98e2 100644 --- a/peekaboo-cli/Tests/peekabooTests/ScreenshotValidationTests.swift +++ b/peekaboo-cli/Tests/peekabooTests/ScreenshotValidationTests.swift @@ -1,7 +1,7 @@ import AppKit import CoreGraphics -import ScreenCaptureKit @testable import peekaboo +import ScreenCaptureKit import Testing @Suite( @@ -237,7 +237,7 @@ struct ScreenshotValidationTests { ) throws -> ImageCaptureData { // Use modern ScreenCaptureKit API instead of deprecated CGWindowListCreateImage let image = try captureWindowWithScreenCaptureKit(windowID: windowID) - + // Save to file let nsImage = NSImage(cgImage: image, size: NSSize(width: image.width, height: image.height)) try saveImage(nsImage, to: path, format: format) @@ -253,55 +253,55 @@ struct ScreenshotValidationTests { ) ]) } - + 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 var capturedImage: CGImage? var captureError: Error? let semaphore = DispatchSemaphore(value: 0) - + Task { do { // Get available content let availableContent = try await SCShareableContent.current - + // Find the window by ID guard let scWindow = availableContent.windows.first(where: { $0.windowID == windowID }) else { throw CaptureError.windowNotFound } - + // Create content filter for the specific window let filter = SCContentFilter(desktopIndependentWindow: scWindow) - + // Configure capture settings let configuration = SCStreamConfiguration() configuration.backgroundColor = .clear configuration.shouldBeOpaque = true configuration.showsCursor = false - + // Capture the image let image = try await SCScreenshotManager.captureImage( contentFilter: filter, configuration: configuration ) - + capturedImage = image } catch { captureError = error } semaphore.signal() } - + semaphore.wait() - + if let error = captureError { throw error } - + guard let image = capturedImage else { throw CaptureError.windowCaptureFailed } - + return image }