Capture clipboard context and screen context at the beginning of the recording.
This commit is contained in:
parent
4b0da10ed5
commit
cba11cdc55
@ -69,6 +69,8 @@ class AIEnhancementService: ObservableObject {
|
||||
private let rateLimitInterval: TimeInterval = 1.0
|
||||
private var lastRequestTime: Date?
|
||||
private let modelContext: ModelContext
|
||||
|
||||
@Published var lastCapturedClipboard: String?
|
||||
|
||||
init(aiService: AIService = AIService(), modelContext: ModelContext) {
|
||||
self.aiService = aiService
|
||||
@ -137,7 +139,6 @@ class AIEnhancementService: ObservableObject {
|
||||
}
|
||||
|
||||
private func getSystemMessage(for mode: EnhancementPrompt) -> String {
|
||||
let clipboardSnapshot = NSPasteboard.general.string(forType: .string)
|
||||
let selectedText = SelectedTextService.fetchSelectedText()
|
||||
|
||||
if let selectedText = selectedText, !selectedText.isEmpty {
|
||||
@ -158,7 +159,7 @@ class AIEnhancementService: ObservableObject {
|
||||
}
|
||||
|
||||
let clipboardContext = if useClipboardContext,
|
||||
let clipboardText = clipboardSnapshot ?? NSPasteboard.general.string(forType: .string),
|
||||
let clipboardText = lastCapturedClipboard,
|
||||
!clipboardText.isEmpty {
|
||||
"\n\n<CLIPBOARD_CONTEXT>\n\(clipboardText)\n</CLIPBOARD_CONTEXT>"
|
||||
} else {
|
||||
@ -418,6 +419,15 @@ class AIEnhancementService: ObservableObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func captureClipboardContext() {
|
||||
lastCapturedClipboard = NSPasteboard.general.string(forType: .string)
|
||||
}
|
||||
|
||||
func clearCapturedContexts() {
|
||||
lastCapturedClipboard = nil
|
||||
screenCaptureService.lastCapturedText = nil
|
||||
}
|
||||
|
||||
func addPrompt(title: String, promptText: String, icon: PromptIcon = .documentFill, description: String? = nil, triggerWords: [String] = [], useSystemInstructions: Bool = true) {
|
||||
let newPrompt = CustomPrompt(title: title, promptText: promptText, icon: icon, description: description, isPredefined: false, triggerWords: triggerWords, useSystemInstructions: useSystemInstructions)
|
||||
|
||||
@ -134,10 +134,6 @@ class ScreenCaptureService: ObservableObject {
|
||||
}
|
||||
|
||||
logger.notice("🎬 Starting screen capture")
|
||||
|
||||
await MainActor.run {
|
||||
self.lastCapturedText = nil
|
||||
}
|
||||
|
||||
guard let windowInfo = getActiveWindowInfo() else {
|
||||
logger.notice("❌ Failed to get window info")
|
||||
|
||||
@ -67,6 +67,13 @@ extension WhisperState {
|
||||
|
||||
hideRecorderPanel()
|
||||
|
||||
// Clear captured context when the recorder is dismissed
|
||||
if let enhancementService = enhancementService {
|
||||
await MainActor.run {
|
||||
enhancementService.clearCapturedContexts()
|
||||
}
|
||||
}
|
||||
|
||||
await MainActor.run {
|
||||
isMiniRecorderVisible = false
|
||||
}
|
||||
|
||||
@ -205,6 +205,7 @@ class WhisperState: NSObject, ObservableObject {
|
||||
}
|
||||
|
||||
if let enhancementService = self.enhancementService {
|
||||
enhancementService.captureClipboardContext()
|
||||
await enhancementService.captureScreenContext()
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user