diff --git a/peekaboo-cli/.swiftformat b/peekaboo-cli/.swiftformat index 5a8b9d2..ff859a3 100644 --- a/peekaboo-cli/.swiftformat +++ b/peekaboo-cli/.swiftformat @@ -1,5 +1,8 @@ # SwiftFormat configuration for Peekaboo CLI +# Swift version +--swiftversion 6.0 + # Format options --indent 4 --indentcase false diff --git a/peekaboo-cli/Sources/peekaboo/ApplicationFinder.swift b/peekaboo-cli/Sources/peekaboo/ApplicationFinder.swift index 0b8c4f0..0ddcea0 100644 --- a/peekaboo-cli/Sources/peekaboo/ApplicationFinder.swift +++ b/peekaboo-cli/Sources/peekaboo/ApplicationFinder.swift @@ -93,7 +93,7 @@ class ApplicationFinder { message: "No running applications found matching identifier: \(identifier)", code: .APP_NOT_FOUND, details: "Available applications: " + - "\(runningApps.compactMap { $0.localizedName }.joined(separator: ", "))" + "\(runningApps.compactMap(\.localizedName).joined(separator: ", "))" ) throw ApplicationError.notFound(identifier) } @@ -104,7 +104,7 @@ class ApplicationFinder { if topMatches.count > 1 { handleAmbiguousMatches(topMatches, identifier: identifier) - throw ApplicationError.ambiguous(identifier, topMatches.map { $0.app }) + throw ApplicationError.ambiguous(identifier, topMatches.map(\.app)) } let bestMatch = matches[0] diff --git a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift index d87aa90..08be178 100644 --- a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift @@ -71,12 +71,12 @@ struct ImageCommand: ParsableCommand { case .screen: return try captureScreens() case .window: - guard let app = app else { + guard let app else { throw CaptureError.appNotFound("No application specified for window capture") } return try captureApplicationWindow(app) case .multi: - if let app = app { + if let app { return try captureAllApplicationWindows(app) } else { return try captureScreens() @@ -112,7 +112,7 @@ struct ImageCommand: ParsableCommand { } private func determineMode() -> CaptureMode { - if let mode = mode { + if let mode { return mode } return app != nil ? .window : .screen @@ -134,7 +134,7 @@ struct ImageCommand: ParsableCommand { } // If screenIndex is specified, capture only that screen - if let screenIndex = screenIndex { + if let screenIndex { if screenIndex >= 0 && screenIndex < displays.count { let displayID = displays[screenIndex] let fileName = generateFileName(displayIndex: screenIndex) @@ -209,12 +209,12 @@ struct ImageCommand: ParsableCommand { } let targetWindow: WindowData - if let windowTitle = windowTitle { + if let windowTitle { guard let window = windows.first(where: { $0.title.contains(windowTitle) }) else { throw CaptureError.windowNotFound } targetWindow = window - } else if let windowIndex = windowIndex { + } else if let windowIndex { guard windowIndex >= 0 && windowIndex < windows.count else { throw CaptureError.invalidWindowIndex(windowIndex) } @@ -329,13 +329,13 @@ struct ImageCommand: ParsableCommand { let timestamp = DateFormatter.timestamp.string(from: Date()) let ext = format.rawValue - if let displayIndex = displayIndex { + if let displayIndex { return "screen_\(displayIndex + 1)_\(timestamp).\(ext)" - } else if let appName = appName { + } else if let appName { let cleanAppName = appName.replacingOccurrences(of: " ", with: "_") - if let windowIndex = windowIndex { + if let windowIndex { return "\(cleanAppName)_window_\(windowIndex)_\(timestamp).\(ext)" - } else if let windowTitle = windowTitle { + } else if let windowTitle { let cleanTitle = windowTitle.replacingOccurrences(of: " ", with: "_").prefix(20) return "\(cleanAppName)_\(cleanTitle)_\(timestamp).\(ext)" } else { @@ -348,9 +348,9 @@ struct ImageCommand: ParsableCommand { private func getOutputPath(_ fileName: String) -> String { if let basePath = path { - return "\(basePath)/\(fileName)" + "\(basePath)/\(fileName)" } else { - return "/tmp/\(fileName)" + "/tmp/\(fileName)" } } } diff --git a/peekaboo-cli/Sources/peekaboo/JSONOutput.swift b/peekaboo-cli/Sources/peekaboo/JSONOutput.swift index ab3e5d9..994c640 100644 --- a/peekaboo-cli/Sources/peekaboo/JSONOutput.swift +++ b/peekaboo-cli/Sources/peekaboo/JSONOutput.swift @@ -91,7 +91,7 @@ struct AnyCodable: Codable { } else if let string = try? container.decode(String.self) { value = string } 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) { value = dict.mapValues { $0.value } } else { @@ -148,14 +148,14 @@ func outputSuccess(data: Any? = nil, messages: [String]? = nil) { } } -func outputSuccessCodable(data: T, messages: [String]? = nil) { +func outputSuccessCodable(data: some Codable, messages: [String]? = nil) { let response = CodableJSONResponse( success: true, data: data, messages: messages, debug_logs: Logger.shared.getDebugLogs() ) outputJSONCodable(response) } -func outputJSONCodable(_ response: T) { +func outputJSONCodable(_ response: some Codable) { do { let encoder = JSONEncoder() encoder.outputFormatting = .prettyPrinted diff --git a/peekaboo-cli/Sources/peekaboo/Logger.swift b/peekaboo-cli/Sources/peekaboo/Logger.swift index 489358e..0c8e38e 100644 --- a/peekaboo-cli/Sources/peekaboo/Logger.swift +++ b/peekaboo-cli/Sources/peekaboo/Logger.swift @@ -45,7 +45,7 @@ class Logger { } func getDebugLogs() -> [String] { - return debugLogs + debugLogs } func clearDebugLogs() { diff --git a/peekaboo-cli/Sources/peekaboo/Models.swift b/peekaboo-cli/Sources/peekaboo/Models.swift index a1019e7..1fedce0 100644 --- a/peekaboo-cli/Sources/peekaboo/Models.swift +++ b/peekaboo-cli/Sources/peekaboo/Models.swift @@ -113,24 +113,24 @@ enum CaptureError: Error, LocalizedError { var errorDescription: String? { switch self { case .noDisplaysAvailable: - return "No displays available for capture" + "No displays available for capture" 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" case .invalidDisplayID: - return "Invalid display ID" + "Invalid display ID" case .captureCreationFailed: - return "Failed to create screen capture" + "Failed to create screen capture" case .windowNotFound: - return "Window not found" + "Window not found" case .windowCaptureFailed: - return "Failed to capture window" + "Failed to capture window" case let .fileWriteError(path): - return "Failed to write file to: \(path)" + "Failed to write file to: \(path)" case let .appNotFound(identifier): - return "Application not found: \(identifier)" + "Application not found: \(identifier)" case let .invalidWindowIndex(index): - return "Invalid window index: \(index)" + "Invalid window index: \(index)" } } } diff --git a/peekaboo-cli/Sources/peekaboo/WindowManager.swift b/peekaboo-cli/Sources/peekaboo/WindowManager.swift index e6af3b0..2ccae2d 100644 --- a/peekaboo-cli/Sources/peekaboo/WindowManager.swift +++ b/peekaboo-cli/Sources/peekaboo/WindowManager.swift @@ -100,7 +100,7 @@ class WindowManager { // Extension to add the getWindowsForApp function to ImageCommand extension ImageCommand { 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? { switch self { case .windowListFailed: - return "Failed to get window list from system" + "Failed to get window list from system" case .noWindowsFound: - return "No windows found for the specified application" + "No windows found for the specified application" } } }