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
4 changes: 4 additions & 0 deletions ScreenScribe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
C1000002000000000000000A /* PromptManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1000002000000000000000B /* PromptManager.swift */; };
C1000003000000000000000A /* PromptEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1000003000000000000000B /* PromptEditorView.swift */; };
C1000004000000000000000A /* PromptListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1000004000000000000000B /* PromptListView.swift */; };
C1000006000000000000000A /* ScreenCaptureBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1000006000000000000000B /* ScreenCaptureBackend.swift */; };
F5B0C7647A784F30BB1B71D9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C128894D5D084D2FBAADA65C /* Assets.xcassets */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -81,6 +82,7 @@
C1000002000000000000000B /* PromptManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptManager.swift; sourceTree = "<group>"; };
C1000003000000000000000B /* PromptEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptEditorView.swift; sourceTree = "<group>"; };
C1000004000000000000000B /* PromptListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptListView.swift; sourceTree = "<group>"; };
C1000006000000000000000B /* ScreenCaptureBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenCaptureBackend.swift; sourceTree = "<group>"; };
C128894D5D084D2FBAADA65C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -130,6 +132,7 @@
children = (
B9583C8A2DBD8C8300F43550 /* GeminiService.swift */,
B9F54FE82F10866C0070D1C2 /* ScreenCapturePermissionManager.swift */,
C1000006000000000000000B /* ScreenCaptureBackend.swift */,
C1000002000000000000000B /* PromptManager.swift */,
);
path = Services;
Expand Down Expand Up @@ -302,6 +305,7 @@
C1000002000000000000000A /* PromptManager.swift in Sources */,
C1000003000000000000000A /* PromptEditorView.swift in Sources */,
C1000004000000000000000A /* PromptListView.swift in Sources */,
C1000006000000000000000A /* ScreenCaptureBackend.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
19 changes: 3 additions & 16 deletions ScreenScribe/Sources/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class App: NSObject, NSApplicationDelegate {
private let historyManager = HistoryManager.shared
private let promptManager = PromptManager.shared
private lazy var permissionManager = ScreenCapturePermissionManager.shared
private let screenCaptureService = ScreenCaptureService()

private var isExtracting = false
private var isRequestingPermission = false
Expand Down Expand Up @@ -445,8 +446,7 @@ final class App: NSObject, NSApplicationDelegate {
func initiateCaptureForText() {
ensurePermissionThenCapture { [weak self] in
guard let self else { return }
await self.captureViaSystemUI()
if let image = NSPasteboard.general.image {
if let image = await self.screenCaptureService.captureSelectionImage() {
self.performVisionExtraction(image: image)
}
}
Expand All @@ -456,25 +456,12 @@ final class App: NSObject, NSApplicationDelegate {
func initiateCapture(with prompt: Prompt) {
ensurePermissionThenCapture { [weak self] in
guard let self else { return }
await self.captureViaSystemUI()
if let image = NSPasteboard.general.image {
if let image = await self.screenCaptureService.captureSelectionImage() {
self.performAIExtraction(image: image, prompt: prompt)
}
}
}

private func captureViaSystemUI() async {
await withCheckedContinuation { continuation in
let task = Process()
task.launchPath = "/usr/sbin/screencapture"
task.arguments = ["-i", "-c", "-x"] // -i interactive, -c copy to clipboard, -x suppress sound
task.terminationHandler = { _ in
continuation.resume()
}
try? task.run()
}
}

private func startDetection() {
guard statusItem.menu != nil else {
return Logger.assertFail("Missing menu to proceed")
Expand Down
Loading
Loading