Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions App/Sources/OCR/OCRCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ import SharedKit

private let logger = Logger(subsystem: "com.awesomemacapps.capso", category: "OCR")

private func logToFile(_ message: String) {
let url = FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent("Desktop/capso-ocr.log")
let timestamp = ISO8601DateFormatter().string(from: Date())
let line = "[\(timestamp)] \(message)\n"
if FileManager.default.fileExists(atPath: url.path) {
if let handle = try? FileHandle(forWritingTo: url) {
handle.seekToEndOfFile()
handle.write(line.data(using: .utf8)!)
handle.closeFile()
}
} else {
try? line.data(using: .utf8)?.write(to: url)
}
}

@MainActor
@Observable
final class OCRCoordinator {
Expand Down Expand Up @@ -84,22 +68,18 @@ final class OCRCoordinator {
height: rect.height
)
let displayID = screen.displayID
logToFile("performInstantOCR START")
logToFile(" selection rect (view-local): \(rect)")
logToFile(" screen.frame: \(screenFrame)")
logToFile(" screenRect (for SCKit): \(screenRect)")
logToFile(" displayID: \(displayID)")

let result = try await ScreenCaptureManager.captureArea(
rect: screenRect,
displayID: displayID
)
logToFile(" capture OK: \(result.image.width)x\(result.image.height)")


let text = try await TextRecognizer.recognizeText(
image: result.image,
keepLineBreaks: settings.ocrKeepLineBreaks
)
logToFile(" OCR result: \(text.count) chars")


if text.isEmpty {
showToast("No text detected", icon: "info.circle.fill", iconColor: .systemYellow, screen: screen)
Expand All @@ -110,8 +90,7 @@ final class OCRCoordinator {
showToast("Copied \(text.count) characters", screen: screen)
}
} catch {
logToFile(" FAILED: \(error)")
logToFile(" error.localizedDescription: \(error.localizedDescription)")

showToast("OCR: \(error.localizedDescription)", icon: "xmark.circle.fill", iconColor: .systemRed, screen: screen)
}
}
Expand Down
2 changes: 1 addition & 1 deletion App/Sources/OCR/ToastWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ToastWindow: NSPanel {
self.level = .floating
self.isOpaque = false
self.backgroundColor = .clear
self.hasShadow = true
self.hasShadow = false
self.collectionBehavior = [.canJoinAllSpaces, .transient]
self.isMovableByWindowBackground = false
self.animationBehavior = .utilityWindow
Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ settings:
CODE_SIGN_IDENTITY: "Developer ID Application"
DEVELOPMENT_TEAM: "T247WTJV77"
ENABLE_HARDENED_RUNTIME: YES
MARKETING_VERSION: "0.1.3"
CURRENT_PROJECT_VERSION: "5"
MARKETING_VERSION: "0.1.4"
CURRENT_PROJECT_VERSION: "6"

packages:
SharedKit:
Expand Down
Loading