mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +00:00
style: Apply SwiftFormat formatting
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
141502d668
commit
9837e7bea8
4 changed files with 32 additions and 30 deletions
|
|
@ -102,10 +102,10 @@ struct ImageCommand: ParsableCommand {
|
||||||
} else {
|
} else {
|
||||||
.unknownError(error.localizedDescription)
|
.unknownError(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the full error details for debugging
|
// Log the full error details for debugging
|
||||||
Logger.shared.debug("Image capture error: \(error)")
|
Logger.shared.debug("Image capture error: \(error)")
|
||||||
|
|
||||||
// If it's a CaptureError with an underlying error, log that too
|
// If it's a CaptureError with an underlying error, log that too
|
||||||
switch captureError {
|
switch captureError {
|
||||||
case let .captureCreationFailed(underlyingError):
|
case let .captureCreationFailed(underlyingError):
|
||||||
|
|
@ -143,7 +143,7 @@ struct ImageCommand: ParsableCommand {
|
||||||
default:
|
default:
|
||||||
.CAPTURE_FAILED
|
.CAPTURE_FAILED
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide additional details for app not found errors
|
// Provide additional details for app not found errors
|
||||||
var details: String? = nil
|
var details: String? = nil
|
||||||
if case .appNotFound = captureError {
|
if case .appNotFound = captureError {
|
||||||
|
|
@ -154,7 +154,7 @@ struct ImageCommand: ParsableCommand {
|
||||||
.joined(separator: ", ")
|
.joined(separator: ", ")
|
||||||
details = "Available applications: \(runningApps)"
|
details = "Available applications: \(runningApps)"
|
||||||
}
|
}
|
||||||
|
|
||||||
outputError(
|
outputError(
|
||||||
message: captureError.localizedDescription,
|
message: captureError.localizedDescription,
|
||||||
code: code,
|
code: code,
|
||||||
|
|
@ -250,11 +250,12 @@ struct ImageCommand: ParsableCommand {
|
||||||
let targetApp: NSRunningApplication
|
let targetApp: NSRunningApplication
|
||||||
do {
|
do {
|
||||||
targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier)
|
targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier)
|
||||||
} catch ApplicationError.notFound(let identifier) {
|
} catch let ApplicationError.notFound(identifier) {
|
||||||
throw CaptureError.appNotFound(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" }
|
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) {
|
if captureFocus == .foreground || (captureFocus == .auto && !targetApp.isActive) {
|
||||||
|
|
@ -304,11 +305,12 @@ struct ImageCommand: ParsableCommand {
|
||||||
let targetApp: NSRunningApplication
|
let targetApp: NSRunningApplication
|
||||||
do {
|
do {
|
||||||
targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier)
|
targetApp = try ApplicationFinder.findApplication(identifier: appIdentifier)
|
||||||
} catch ApplicationError.notFound(let identifier) {
|
} catch let ApplicationError.notFound(identifier) {
|
||||||
throw CaptureError.appNotFound(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" }
|
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) {
|
if captureFocus == .foreground || (captureFocus == .auto && !targetApp.isActive) {
|
||||||
|
|
@ -484,12 +486,12 @@ struct ImageCommand: ParsableCommand {
|
||||||
|
|
||||||
private func isScreenRecordingPermissionError(_ error: Error) -> Bool {
|
private func isScreenRecordingPermissionError(_ error: Error) -> Bool {
|
||||||
let errorString = error.localizedDescription.lowercased()
|
let errorString = error.localizedDescription.lowercased()
|
||||||
|
|
||||||
// Check for specific screen recording related errors
|
// Check for specific screen recording related errors
|
||||||
if errorString.contains("screen recording") {
|
if errorString.contains("screen recording") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for NSError codes specific to screen capture permissions
|
// Check for NSError codes specific to screen capture permissions
|
||||||
if let nsError = error as NSError? {
|
if let nsError = error as NSError? {
|
||||||
// ScreenCaptureKit specific error codes
|
// ScreenCaptureKit specific error codes
|
||||||
|
|
@ -497,20 +499,20 @@ struct ImageCommand: ParsableCommand {
|
||||||
// SCStreamErrorUserDeclined = -3801
|
// SCStreamErrorUserDeclined = -3801
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoreGraphics error codes for screen capture
|
// CoreGraphics error codes for screen capture
|
||||||
if nsError.domain == "com.apple.coregraphics" && nsError.code == 1002 {
|
if nsError.domain == "com.apple.coregraphics" && nsError.code == 1002 {
|
||||||
// kCGErrorCannotComplete when permissions are denied
|
// kCGErrorCannotComplete when permissions are denied
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only consider it a permission error if it mentions both "permission" and capture-related terms
|
// Only consider it a permission error if it mentions both "permission" and capture-related terms
|
||||||
if errorString.contains("permission") &&
|
if errorString.contains("permission") &&
|
||||||
(errorString.contains("capture") || errorString.contains("recording") || errorString.contains("screen")) {
|
(errorString.contains("capture") || errorString.contains("recording") || errorString.contains("screen")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,14 +74,14 @@ struct AppsSubcommand: ParsableCommand {
|
||||||
Foundation.exit(captureError.exitCode)
|
Foundation.exit(captureError.exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func printApplicationList(_ applications: [ApplicationInfo]) {
|
func printApplicationList(_ applications: [ApplicationInfo]) {
|
||||||
let output = formatApplicationList(applications)
|
let output = formatApplicationList(applications)
|
||||||
print(output)
|
print(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func formatApplicationList(_ applications: [ApplicationInfo]) -> String {
|
func formatApplicationList(_ applications: [ApplicationInfo]) -> String {
|
||||||
var output = "Running Applications (\(applications.count)):\n\n"
|
var output = "Running Applications (\(applications.count)):\n\n"
|
||||||
|
|
||||||
for (index, app) in applications.enumerated() {
|
for (index, app) in applications.enumerated() {
|
||||||
output += "\(index + 1). \(app.app_name)\n"
|
output += "\(index + 1). \(app.app_name)\n"
|
||||||
output += " Bundle ID: \(app.bundle_id)\n"
|
output += " Bundle ID: \(app.bundle_id)\n"
|
||||||
|
|
@ -93,7 +93,7 @@ struct AppsSubcommand: ParsableCommand {
|
||||||
}
|
}
|
||||||
output += "\n"
|
output += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@ class PermissionsChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore.wait()
|
semaphore.wait()
|
||||||
|
|
||||||
if let error = capturedError {
|
if let error = capturedError {
|
||||||
Logger.shared.debug("Screen recording permission check failed: \(error)")
|
Logger.shared.debug("Screen recording permission check failed: \(error)")
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasPermission
|
return hasPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -307,13 +307,13 @@ struct ListCommandTests {
|
||||||
|
|
||||||
// Verify that "Windows: 1" is NOT present for single window app
|
// Verify that "Windows: 1" is NOT present for single window app
|
||||||
#expect(!output.contains("Windows: 1"))
|
#expect(!output.contains("Windows: 1"))
|
||||||
|
|
||||||
// Verify that the single window app is listed but without window count
|
// Verify that the single window app is listed but without window count
|
||||||
#expect(output.contains("Single Window App"))
|
#expect(output.contains("Single Window App"))
|
||||||
|
|
||||||
// Verify that "Windows: 5" IS present for multi window app
|
// Verify that "Windows: 5" IS present for multi window app
|
||||||
#expect(output.contains("Windows: 5"))
|
#expect(output.contains("Windows: 5"))
|
||||||
|
|
||||||
// Verify that "Windows: 0" IS present for no windows app
|
// Verify that "Windows: 0" IS present for no windows app
|
||||||
#expect(output.contains("Windows: 0"))
|
#expect(output.contains("Windows: 0"))
|
||||||
}
|
}
|
||||||
|
|
@ -374,7 +374,7 @@ struct ListCommandTests {
|
||||||
#expect(output.contains("Bundle ID: com.test.app"))
|
#expect(output.contains("Bundle ID: com.test.app"))
|
||||||
#expect(output.contains("PID: 12345"))
|
#expect(output.contains("PID: 12345"))
|
||||||
#expect(output.contains("Status: Active"))
|
#expect(output.contains("Status: Active"))
|
||||||
|
|
||||||
// Verify "Windows: 1" is NOT present
|
// Verify "Windows: 1" is NOT present
|
||||||
#expect(!output.contains("Windows: 1"))
|
#expect(!output.contains("Windows: 1"))
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +403,7 @@ struct ListCommandTests {
|
||||||
|
|
||||||
// Both apps have 1 window, so neither should show "Windows: 1"
|
// Both apps have 1 window, so neither should show "Windows: 1"
|
||||||
#expect(!output.contains("Windows: 1"))
|
#expect(!output.contains("Windows: 1"))
|
||||||
|
|
||||||
// But both apps should be listed
|
// But both apps should be listed
|
||||||
#expect(output.contains("Edge Case 1"))
|
#expect(output.contains("Edge Case 1"))
|
||||||
#expect(output.contains("Edge Case 2"))
|
#expect(output.contains("Edge Case 2"))
|
||||||
|
|
@ -428,7 +428,7 @@ struct ListCommandTests {
|
||||||
#expect(!output.contains("Windows: 1"))
|
#expect(!output.contains("Windows: 1"))
|
||||||
#expect(output.contains("Windows: 2"))
|
#expect(output.contains("Windows: 2"))
|
||||||
#expect(output.contains("Windows: 3"))
|
#expect(output.contains("Windows: 3"))
|
||||||
|
|
||||||
// All apps should be listed
|
// All apps should be listed
|
||||||
#expect(output.contains("App A"))
|
#expect(output.contains("App A"))
|
||||||
#expect(output.contains("App B"))
|
#expect(output.contains("App B"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue