style: Apply SwiftFormat formatting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Peter Steinberger 2025-06-08 07:29:37 +01:00
parent 141502d668
commit 9837e7bea8
4 changed files with 32 additions and 30 deletions

View file

@ -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
}

View file

@ -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
}
}

View file

@ -25,11 +25,11 @@ class PermissionsChecker {
}
semaphore.wait()
if let error = capturedError {
Logger.shared.debug("Screen recording permission check failed: \(error)")
}
return hasPermission
}

View file

@ -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"))