From 9837e7bea87af41cea3850179bafddf4963de80b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 8 Jun 2025 07:29:37 +0100 Subject: [PATCH] style: Apply SwiftFormat formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../Sources/peekaboo/ImageCommand.swift | 36 ++++++++++--------- .../Sources/peekaboo/ListCommand.swift | 10 +++--- .../Sources/peekaboo/PermissionsChecker.swift | 4 +-- .../peekabooTests/ListCommandTests.swift | 12 +++---- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift index d589a82..5de73b6 100644 --- a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift @@ -102,10 +102,10 @@ struct ImageCommand: ParsableCommand { } else { .unknownError(error.localizedDescription) } - + // Log the full error details for debugging Logger.shared.debug("Image capture error: \(error)") - + // If it's a CaptureError with an underlying error, log that too switch captureError { case let .captureCreationFailed(underlyingError): @@ -143,7 +143,7 @@ struct ImageCommand: ParsableCommand { default: .CAPTURE_FAILED } - + // Provide additional details for app not found errors var details: String? = nil if case .appNotFound = captureError { @@ -154,7 +154,7 @@ struct ImageCommand: ParsableCommand { .joined(separator: ", ") details = "Available applications: \(runningApps)" } - + outputError( message: captureError.localizedDescription, code: code, @@ -250,11 +250,12 @@ struct ImageCommand: ParsableCommand { let targetApp: NSRunningApplication do { targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier) - } catch ApplicationError.notFound(let identifier) { + } catch let ApplicationError.notFound(identifier) { throw CaptureError.appNotFound(identifier) - } catch ApplicationError.ambiguous(let identifier, let matches) { + } catch let ApplicationError.ambiguous(identifier, matches) { let appNames = matches.map { $0.localizedName ?? $0.bundleIdentifier ?? "Unknown" } - throw CaptureError.unknownError("Multiple applications match '\(identifier)': \(appNames.joined(separator: ", "))") + throw CaptureError + .unknownError("Multiple applications match '\(identifier)': \(appNames.joined(separator: ", "))") } if captureFocus == .foreground || (captureFocus == .auto && !targetApp.isActive) { @@ -304,11 +305,12 @@ struct ImageCommand: ParsableCommand { let targetApp: NSRunningApplication do { targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier) - } catch ApplicationError.notFound(let identifier) { + } catch let ApplicationError.notFound(identifier) { throw CaptureError.appNotFound(identifier) - } catch ApplicationError.ambiguous(let identifier, let matches) { + } catch let ApplicationError.ambiguous(identifier, matches) { let appNames = matches.map { $0.localizedName ?? $0.bundleIdentifier ?? "Unknown" } - throw CaptureError.unknownError("Multiple applications match '\(identifier)': \(appNames.joined(separator: ", "))") + throw CaptureError + .unknownError("Multiple applications match '\(identifier)': \(appNames.joined(separator: ", "))") } if captureFocus == .foreground || (captureFocus == .auto && !targetApp.isActive) { @@ -484,12 +486,12 @@ struct ImageCommand: ParsableCommand { private func isScreenRecordingPermissionError(_ error: Error) -> Bool { let errorString = error.localizedDescription.lowercased() - + // Check for specific screen recording related errors if errorString.contains("screen recording") { return true } - + // Check for NSError codes specific to screen capture permissions if let nsError = error as NSError? { // ScreenCaptureKit specific error codes @@ -497,20 +499,20 @@ struct ImageCommand: ParsableCommand { // SCStreamErrorUserDeclined = -3801 return true } - + // CoreGraphics error codes for screen capture if nsError.domain == "com.apple.coregraphics" && nsError.code == 1002 { // kCGErrorCannotComplete when permissions are denied return true } } - + // Only consider it a permission error if it mentions both "permission" and capture-related terms - if errorString.contains("permission") && - (errorString.contains("capture") || errorString.contains("recording") || errorString.contains("screen")) { + if errorString.contains("permission") && + (errorString.contains("capture") || errorString.contains("recording") || errorString.contains("screen")) { return true } - + return false } diff --git a/peekaboo-cli/Sources/peekaboo/ListCommand.swift b/peekaboo-cli/Sources/peekaboo/ListCommand.swift index dc98e2c..a63a3b8 100644 --- a/peekaboo-cli/Sources/peekaboo/ListCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ListCommand.swift @@ -74,14 +74,14 @@ struct AppsSubcommand: ParsableCommand { Foundation.exit(captureError.exitCode) } - internal func printApplicationList(_ applications: [ApplicationInfo]) { + func printApplicationList(_ applications: [ApplicationInfo]) { let output = formatApplicationList(applications) print(output) } - - internal func formatApplicationList(_ applications: [ApplicationInfo]) -> String { + + func formatApplicationList(_ applications: [ApplicationInfo]) -> String { var output = "Running Applications (\(applications.count)):\n\n" - + for (index, app) in applications.enumerated() { output += "\(index + 1). \(app.app_name)\n" output += " Bundle ID: \(app.bundle_id)\n" @@ -93,7 +93,7 @@ struct AppsSubcommand: ParsableCommand { } output += "\n" } - + return output } } diff --git a/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift b/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift index 66d816e..c04b581 100644 --- a/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift +++ b/peekaboo-cli/Sources/peekaboo/PermissionsChecker.swift @@ -25,11 +25,11 @@ class PermissionsChecker { } semaphore.wait() - + if let error = capturedError { Logger.shared.debug("Screen recording permission check failed: \(error)") } - + return hasPermission } diff --git a/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift b/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift index 7f220c5..2d3d2eb 100644 --- a/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift +++ b/peekaboo-cli/Tests/peekabooTests/ListCommandTests.swift @@ -307,13 +307,13 @@ struct ListCommandTests { // Verify that "Windows: 1" is NOT present for single window app #expect(!output.contains("Windows: 1")) - + // Verify that the single window app is listed but without window count #expect(output.contains("Single Window App")) - + // Verify that "Windows: 5" IS present for multi window app #expect(output.contains("Windows: 5")) - + // Verify that "Windows: 0" IS present for no windows app #expect(output.contains("Windows: 0")) } @@ -374,7 +374,7 @@ struct ListCommandTests { #expect(output.contains("Bundle ID: com.test.app")) #expect(output.contains("PID: 12345")) #expect(output.contains("Status: Active")) - + // Verify "Windows: 1" is NOT present #expect(!output.contains("Windows: 1")) } @@ -403,7 +403,7 @@ struct ListCommandTests { // Both apps have 1 window, so neither should show "Windows: 1" #expect(!output.contains("Windows: 1")) - + // But both apps should be listed #expect(output.contains("Edge Case 1")) #expect(output.contains("Edge Case 2")) @@ -428,7 +428,7 @@ struct ListCommandTests { #expect(!output.contains("Windows: 1")) #expect(output.contains("Windows: 2")) #expect(output.contains("Windows: 3")) - + // All apps should be listed #expect(output.contains("App A")) #expect(output.contains("App B"))