Add menu bar copy last transcription
This commit is contained in:
parent
76dc78645e
commit
396daf0755
48
VoiceInk/Services/LastTranscriptionService.swift
Normal file
48
VoiceInk/Services/LastTranscriptionService.swift
Normal file
@ -0,0 +1,48 @@
|
||||
import Foundation
|
||||
import SwiftData
|
||||
|
||||
class LastTranscriptionService: ObservableObject {
|
||||
|
||||
static func getLastTranscription(from modelContext: ModelContext) -> Transcription? {
|
||||
var descriptor = FetchDescriptor<Transcription>(
|
||||
sortBy: [SortDescriptor(\.timestamp, order: .reverse)]
|
||||
)
|
||||
descriptor.fetchLimit = 1
|
||||
|
||||
do {
|
||||
let transcriptions = try modelContext.fetch(descriptor)
|
||||
return transcriptions.first
|
||||
} catch {
|
||||
print("Error fetching last transcription: \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
static func copyLastTranscription(from modelContext: ModelContext) {
|
||||
guard let lastTranscription = getLastTranscription(from: modelContext) else {
|
||||
Task { @MainActor in
|
||||
NotificationManager.shared.showNotification(
|
||||
title: "No transcription available",
|
||||
type: .error
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
let success = ClipboardManager.copyToClipboard(lastTranscription.text)
|
||||
|
||||
Task { @MainActor in
|
||||
if success {
|
||||
NotificationManager.shared.showNotification(
|
||||
title: "Last transcription copied",
|
||||
type: .success
|
||||
)
|
||||
} else {
|
||||
NotificationManager.shared.showNotification(
|
||||
title: "Failed to copy transcription",
|
||||
type: .error
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,6 +159,10 @@ struct MenuBarView: View {
|
||||
|
||||
Divider()
|
||||
|
||||
Button("Copy Last Transcription") {
|
||||
LastTranscriptionService.copyLastTranscription(from: whisperState.modelContext)
|
||||
}
|
||||
|
||||
Button("History") {
|
||||
menuBarManager.openMainWindowAndNavigate(to: "History")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user