Apply SwiftFormat changes for v1.0.0 release

🤖 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 20:35:27 +01:00
parent 1a2a817822
commit 0bec93e364
14 changed files with 95 additions and 77 deletions

View file

@ -338,13 +338,13 @@ final class ApplicationFinder: Sendable {
// Exclude obvious helper processes // Exclude obvious helper processes
let isHelper = appName.contains("helper") || let isHelper = appName.contains("helper") ||
appName.contains("renderer") || appName.contains("renderer") ||
appName.contains("utility") || appName.contains("utility") ||
appName.contains("plugin") || appName.contains("plugin") ||
appName.contains("service") || appName.contains("service") ||
appName.contains("crashpad") || appName.contains("crashpad") ||
appName.contains("gpu") || appName.contains("gpu") ||
appName.contains("background") appName.contains("background")
if isHelper { if isHelper {
// Logger.shared.debug("Filtering out helper process: \(appName)") // Logger.shared.debug("Filtering out helper process: \(appName)")
@ -357,7 +357,8 @@ final class ApplicationFinder: Sendable {
// If we filtered out all matches, return the original matches to avoid "not found" errors // If we filtered out all matches, return the original matches to avoid "not found" errors
// But log a warning about this case // But log a warning about this case
if filteredMatches.isEmpty && !matches.isEmpty { if filteredMatches.isEmpty && !matches.isEmpty {
// Logger.shared.debug("All matches were filtered as helpers, returning original matches to avoid 'not found' error") // Logger.shared.debug("All matches were filtered as helpers, returning original matches to avoid 'not
// found' error")
return matches return matches
} }

View file

@ -164,10 +164,15 @@ struct ImageCommand: AsyncParsableCommand {
return savedFiles return savedFiles
} }
private func captureAllScreensWithFallback(displays: [CGDirectDisplayID]) async throws(CaptureError) -> [SavedFile] { private func captureAllScreensWithFallback(displays: [CGDirectDisplayID]) async throws(CaptureError)
-> [SavedFile] {
var savedFiles: [SavedFile] = [] var savedFiles: [SavedFile] = []
for (index, displayID) in displays.enumerated() { for (index, displayID) in displays.enumerated() {
let savedFile = try await captureSingleDisplayWithFallback(displayID: displayID, index: index, labelSuffix: "") let savedFile = try await captureSingleDisplayWithFallback(
displayID: displayID,
index: index,
labelSuffix: ""
)
savedFiles.append(savedFile) savedFiles.append(savedFile)
} }
return savedFiles return savedFiles
@ -246,7 +251,7 @@ struct ImageCommand: AsyncParsableCommand {
Logger.shared.debug( Logger.shared.debug(
"Window not found. Searched for '\(searchTerm)' in \(appName). " + "Window not found. Searched for '\(searchTerm)' in \(appName). " +
"Available windows: \(availableTitles)" "Available windows: \(availableTitles)"
) )
throw CaptureError.windowTitleNotFound(searchTerm, appName, availableTitles) throw CaptureError.windowTitleNotFound(searchTerm, appName, availableTitles)

View file

@ -1,7 +1,7 @@
import Foundation
import AppKit import AppKit
import Foundation
struct ImageErrorHandler { enum ImageErrorHandler {
static func handleError(_ error: Error, jsonOutput: Bool) { static func handleError(_ error: Error, jsonOutput: Bool) {
let captureError: CaptureError = if let err = error as? CaptureError { let captureError: CaptureError = if let err = error as? CaptureError {
err err

View file

@ -1,5 +1,5 @@
import Foundation
import CoreGraphics import CoreGraphics
import Foundation
import ImageIO import ImageIO
import UniformTypeIdentifiers import UniformTypeIdentifiers

View file

@ -7,11 +7,17 @@ struct JSONResponse: Codable {
let debug_logs: [String] let debug_logs: [String]
let error: ErrorInfo? let error: ErrorInfo?
init(success: Bool, data: Any? = nil, messages: [String]? = nil, debugLogs: [String] = [], error: ErrorInfo? = nil) { init(
success: Bool,
data: Any? = nil,
messages: [String]? = nil,
debugLogs: [String] = [],
error: ErrorInfo? = nil
) {
self.success = success self.success = success
self.data = data.map(AnyCodable.init) self.data = data.map(AnyCodable.init)
self.messages = messages self.messages = messages
self.debug_logs = debugLogs debug_logs = debugLogs
self.error = error self.error = error
} }
} }

View file

@ -63,8 +63,8 @@ struct WindowBounds: Codable, Sendable {
let height: Int let height: Int
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case x_coordinate = "x_coordinate" case x_coordinate
case y_coordinate = "y_coordinate" case y_coordinate
case width case width
case height case height
} }
@ -149,7 +149,8 @@ enum CaptureError: Error, LocalizedError, Sendable {
if !availableTitles.isEmpty { if !availableTitles.isEmpty {
message += " Available windows: \(availableTitles)." message += " Available windows: \(availableTitles)."
} }
message += " Note: For URLs, try without the protocol (e.g., 'example.com:8080' instead of 'http://example.com:8080')." message +=
" Note: For URLs, try without the protocol (e.g., 'example.com:8080' instead of 'http://example.com:8080')."
return message return message
case let .windowCaptureFailed(underlyingError): case let .windowCaptureFailed(underlyingError):
var message = "Failed to capture the specified window." var message = "Failed to capture the specified window."

View file

@ -2,7 +2,7 @@ import Foundation
struct OutputPathResolver: Sendable { struct OutputPathResolver: Sendable {
static func getOutputPath(basePath: String?, fileName: String, screenIndex: Int? = nil) -> String { static func getOutputPath(basePath: String?, fileName: String, screenIndex: Int? = nil) -> String {
if let basePath = basePath { if let basePath {
validatePath(basePath) validatePath(basePath)
return determineOutputPath(basePath: basePath, fileName: fileName, screenIndex: screenIndex) return determineOutputPath(basePath: basePath, fileName: fileName, screenIndex: screenIndex)
} else { } else {
@ -11,7 +11,7 @@ struct OutputPathResolver: Sendable {
} }
static func getOutputPathWithFallback(basePath: String?, fileName: String) -> String { static func getOutputPathWithFallback(basePath: String?, fileName: String) -> String {
if let basePath = basePath { if let basePath {
validatePath(basePath) validatePath(basePath)
return determineOutputPathWithFallback(basePath: basePath, fileName: fileName) return determineOutputPathWithFallback(basePath: basePath, fileName: fileName)
} else { } else {

View file

@ -1,5 +1,5 @@
import Foundation
import CoreGraphics import CoreGraphics
import Foundation
@preconcurrency import ScreenCaptureKit @preconcurrency import ScreenCaptureKit
struct ScreenCapture: Sendable { struct ScreenCapture: Sendable {

View file

@ -263,7 +263,6 @@ struct ImageCommandTests {
#expect(command.screenIndex == index) #expect(command.screenIndex == index)
} }
@Test( @Test(
"Window index boundary values", "Window index boundary values",
arguments: [0, 1, 10, 9999] arguments: [0, 1, 10, 9999]
@ -273,7 +272,6 @@ struct ImageCommandTests {
#expect(command.windowIndex == index) #expect(command.windowIndex == index)
} }
@Test("Error handling for invalid combinations", .tags(.fast)) @Test("Error handling for invalid combinations", .tags(.fast))
func invalidCombinations() { func invalidCombinations() {
// Window capture without app should fail in execution // Window capture without app should fail in execution
@ -340,7 +338,11 @@ struct ImageCommandPathHandlingTests {
func singleScreenFilePath() { func singleScreenFilePath() {
// For single screen, should use exact path // For single screen, should use exact path
let fileName = "screen_1_20250608_120000.png" let fileName = "screen_1_20250608_120000.png"
let result = OutputPathResolver.determineOutputPath(basePath: "/tmp/my-screenshot.png", fileName: fileName, screenIndex: 0) let result = OutputPathResolver.determineOutputPath(
basePath: "/tmp/my-screenshot.png",
fileName: fileName,
screenIndex: 0
)
#expect(result == "/tmp/my-screenshot.png") #expect(result == "/tmp/my-screenshot.png")
} }
@ -575,7 +577,10 @@ struct ImageCommandErrorHandlingTests {
// This test validates the logic without actually creating directories // This test validates the logic without actually creating directories
let fileName = "screen_1_20250608_120001.png" let fileName = "screen_1_20250608_120001.png"
let result = OutputPathResolver.determineOutputPath(basePath: "/tmp/test-path-creation/file.png", fileName: fileName) let result = OutputPathResolver.determineOutputPath(
basePath: "/tmp/test-path-creation/file.png",
fileName: fileName
)
// Should return the intended path even if directory creation might fail // Should return the intended path even if directory creation might fail
#expect(result == "/tmp/test-path-creation/file_1_20250608_120001.png") #expect(result == "/tmp/test-path-creation/file_1_20250608_120001.png")