Add Swift 6.0 version to SwiftFormat config and apply formatting

- Specify Swift 6.0 in .swiftformat to enable all formatting features
- Apply Swift 6 formatting improvements:
  - Use shorthand optional unwrapping syntax
  - Use implicit returns in computed properties
  - Use modern Swift 6 syntax throughout

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Peter Steinberger 2025-05-25 18:45:20 +02:00
parent d07bb0fd37
commit 7895e1765f
7 changed files with 33 additions and 30 deletions

View file

@ -1,5 +1,8 @@
# SwiftFormat configuration for Peekaboo CLI # SwiftFormat configuration for Peekaboo CLI
# Swift version
--swiftversion 6.0
# Format options # Format options
--indent 4 --indent 4
--indentcase false --indentcase false

View file

@ -93,7 +93,7 @@ class ApplicationFinder {
message: "No running applications found matching identifier: \(identifier)", message: "No running applications found matching identifier: \(identifier)",
code: .APP_NOT_FOUND, code: .APP_NOT_FOUND,
details: "Available applications: " + details: "Available applications: " +
"\(runningApps.compactMap { $0.localizedName }.joined(separator: ", "))" "\(runningApps.compactMap(\.localizedName).joined(separator: ", "))"
) )
throw ApplicationError.notFound(identifier) throw ApplicationError.notFound(identifier)
} }
@ -104,7 +104,7 @@ class ApplicationFinder {
if topMatches.count > 1 { if topMatches.count > 1 {
handleAmbiguousMatches(topMatches, identifier: identifier) handleAmbiguousMatches(topMatches, identifier: identifier)
throw ApplicationError.ambiguous(identifier, topMatches.map { $0.app }) throw ApplicationError.ambiguous(identifier, topMatches.map(\.app))
} }
let bestMatch = matches[0] let bestMatch = matches[0]

View file

@ -71,12 +71,12 @@ struct ImageCommand: ParsableCommand {
case .screen: case .screen:
return try captureScreens() return try captureScreens()
case .window: case .window:
guard let app = app else { guard let app else {
throw CaptureError.appNotFound("No application specified for window capture") throw CaptureError.appNotFound("No application specified for window capture")
} }
return try captureApplicationWindow(app) return try captureApplicationWindow(app)
case .multi: case .multi:
if let app = app { if let app {
return try captureAllApplicationWindows(app) return try captureAllApplicationWindows(app)
} else { } else {
return try captureScreens() return try captureScreens()
@ -112,7 +112,7 @@ struct ImageCommand: ParsableCommand {
} }
private func determineMode() -> CaptureMode { private func determineMode() -> CaptureMode {
if let mode = mode { if let mode {
return mode return mode
} }
return app != nil ? .window : .screen return app != nil ? .window : .screen
@ -134,7 +134,7 @@ struct ImageCommand: ParsableCommand {
} }
// If screenIndex is specified, capture only that screen // If screenIndex is specified, capture only that screen
if let screenIndex = screenIndex { if let screenIndex {
if screenIndex >= 0 && screenIndex < displays.count { if screenIndex >= 0 && screenIndex < displays.count {
let displayID = displays[screenIndex] let displayID = displays[screenIndex]
let fileName = generateFileName(displayIndex: screenIndex) let fileName = generateFileName(displayIndex: screenIndex)
@ -209,12 +209,12 @@ struct ImageCommand: ParsableCommand {
} }
let targetWindow: WindowData let targetWindow: WindowData
if let windowTitle = windowTitle { if let windowTitle {
guard let window = windows.first(where: { $0.title.contains(windowTitle) }) else { guard let window = windows.first(where: { $0.title.contains(windowTitle) }) else {
throw CaptureError.windowNotFound throw CaptureError.windowNotFound
} }
targetWindow = window targetWindow = window
} else if let windowIndex = windowIndex { } else if let windowIndex {
guard windowIndex >= 0 && windowIndex < windows.count else { guard windowIndex >= 0 && windowIndex < windows.count else {
throw CaptureError.invalidWindowIndex(windowIndex) throw CaptureError.invalidWindowIndex(windowIndex)
} }
@ -329,13 +329,13 @@ struct ImageCommand: ParsableCommand {
let timestamp = DateFormatter.timestamp.string(from: Date()) let timestamp = DateFormatter.timestamp.string(from: Date())
let ext = format.rawValue let ext = format.rawValue
if let displayIndex = displayIndex { if let displayIndex {
return "screen_\(displayIndex + 1)_\(timestamp).\(ext)" return "screen_\(displayIndex + 1)_\(timestamp).\(ext)"
} else if let appName = appName { } else if let appName {
let cleanAppName = appName.replacingOccurrences(of: " ", with: "_") let cleanAppName = appName.replacingOccurrences(of: " ", with: "_")
if let windowIndex = windowIndex { if let windowIndex {
return "\(cleanAppName)_window_\(windowIndex)_\(timestamp).\(ext)" return "\(cleanAppName)_window_\(windowIndex)_\(timestamp).\(ext)"
} else if let windowTitle = windowTitle { } else if let windowTitle {
let cleanTitle = windowTitle.replacingOccurrences(of: " ", with: "_").prefix(20) let cleanTitle = windowTitle.replacingOccurrences(of: " ", with: "_").prefix(20)
return "\(cleanAppName)_\(cleanTitle)_\(timestamp).\(ext)" return "\(cleanAppName)_\(cleanTitle)_\(timestamp).\(ext)"
} else { } else {
@ -348,9 +348,9 @@ struct ImageCommand: ParsableCommand {
private func getOutputPath(_ fileName: String) -> String { private func getOutputPath(_ fileName: String) -> String {
if let basePath = path { if let basePath = path {
return "\(basePath)/\(fileName)" "\(basePath)/\(fileName)"
} else { } else {
return "/tmp/\(fileName)" "/tmp/\(fileName)"
} }
} }
} }

View file

@ -91,7 +91,7 @@ struct AnyCodable: Codable {
} else if let string = try? container.decode(String.self) { } else if let string = try? container.decode(String.self) {
value = string value = string
} else if let array = try? container.decode([AnyCodable].self) { } else if let array = try? container.decode([AnyCodable].self) {
value = array.map { $0.value } value = array.map(\.value)
} else if let dict = try? container.decode([String: AnyCodable].self) { } else if let dict = try? container.decode([String: AnyCodable].self) {
value = dict.mapValues { $0.value } value = dict.mapValues { $0.value }
} else { } else {
@ -148,14 +148,14 @@ func outputSuccess(data: Any? = nil, messages: [String]? = nil) {
} }
} }
func outputSuccessCodable<T: Codable>(data: T, messages: [String]? = nil) { func outputSuccessCodable(data: some Codable, messages: [String]? = nil) {
let response = CodableJSONResponse( let response = CodableJSONResponse(
success: true, data: data, messages: messages, debug_logs: Logger.shared.getDebugLogs() success: true, data: data, messages: messages, debug_logs: Logger.shared.getDebugLogs()
) )
outputJSONCodable(response) outputJSONCodable(response)
} }
func outputJSONCodable<T: Codable>(_ response: T) { func outputJSONCodable(_ response: some Codable) {
do { do {
let encoder = JSONEncoder() let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted encoder.outputFormatting = .prettyPrinted

View file

@ -45,7 +45,7 @@ class Logger {
} }
func getDebugLogs() -> [String] { func getDebugLogs() -> [String] {
return debugLogs debugLogs
} }
func clearDebugLogs() { func clearDebugLogs() {

View file

@ -113,24 +113,24 @@ enum CaptureError: Error, LocalizedError {
var errorDescription: String? { var errorDescription: String? {
switch self { switch self {
case .noDisplaysAvailable: case .noDisplaysAvailable:
return "No displays available for capture" "No displays available for capture"
case .capturePermissionDenied: case .capturePermissionDenied:
return "Screen recording permission denied. Please grant permission in " + "Screen recording permission denied. Please grant permission in " +
"System Preferences > Security & Privacy > Privacy > Screen Recording" "System Preferences > Security & Privacy > Privacy > Screen Recording"
case .invalidDisplayID: case .invalidDisplayID:
return "Invalid display ID" "Invalid display ID"
case .captureCreationFailed: case .captureCreationFailed:
return "Failed to create screen capture" "Failed to create screen capture"
case .windowNotFound: case .windowNotFound:
return "Window not found" "Window not found"
case .windowCaptureFailed: case .windowCaptureFailed:
return "Failed to capture window" "Failed to capture window"
case let .fileWriteError(path): case let .fileWriteError(path):
return "Failed to write file to: \(path)" "Failed to write file to: \(path)"
case let .appNotFound(identifier): case let .appNotFound(identifier):
return "Application not found: \(identifier)" "Application not found: \(identifier)"
case let .invalidWindowIndex(index): case let .invalidWindowIndex(index):
return "Invalid window index: \(index)" "Invalid window index: \(index)"
} }
} }
} }

View file

@ -100,7 +100,7 @@ class WindowManager {
// Extension to add the getWindowsForApp function to ImageCommand // Extension to add the getWindowsForApp function to ImageCommand
extension ImageCommand { extension ImageCommand {
func getWindowsForApp(pid: pid_t) throws(WindowError) -> [WindowData] { func getWindowsForApp(pid: pid_t) throws(WindowError) -> [WindowData] {
return try WindowManager.getWindowsForApp(pid: pid) try WindowManager.getWindowsForApp(pid: pid)
} }
} }
@ -111,9 +111,9 @@ enum WindowError: Error, LocalizedError {
var errorDescription: String? { var errorDescription: String? {
switch self { switch self {
case .windowListFailed: case .windowListFailed:
return "Failed to get window list from system" "Failed to get window list from system"
case .noWindowsFound: case .noWindowsFound:
return "No windows found for the specified application" "No windows found for the specified application"
} }
} }
} }