- Pass WhisperState to HistoryWindowController for transcription services - Update MenuBarManager to store and pass WhisperState reference - Ensure all transcription providers work in separate history window
78 lines
2.8 KiB
Swift
78 lines
2.8 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
import AppKit
|
|
|
|
class HistoryWindowController: NSObject, NSWindowDelegate {
|
|
static let shared = HistoryWindowController()
|
|
|
|
private var historyWindow: NSWindow?
|
|
private let windowIdentifier = NSUserInterfaceItemIdentifier("com.prakashjoshipax.voiceink.historyWindow")
|
|
private let windowAutosaveName = NSWindow.FrameAutosaveName("VoiceInkHistoryWindowFrame")
|
|
|
|
private override init() {
|
|
super.init()
|
|
}
|
|
|
|
func showHistoryWindow(modelContainer: ModelContainer, whisperState: WhisperState) {
|
|
if let existingWindow = historyWindow, existingWindow.isVisible {
|
|
existingWindow.makeKeyAndOrderFront(nil)
|
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
|
return
|
|
}
|
|
|
|
let window = createHistoryWindow(modelContainer: modelContainer, whisperState: whisperState)
|
|
historyWindow = window
|
|
window.makeKeyAndOrderFront(nil)
|
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
|
}
|
|
|
|
private func createHistoryWindow(modelContainer: ModelContainer, whisperState: WhisperState) -> NSWindow {
|
|
let historyView = TranscriptionHistoryView()
|
|
.modelContainer(modelContainer)
|
|
.environmentObject(whisperState)
|
|
.frame(minWidth: 800, minHeight: 600)
|
|
|
|
let hostingController = NSHostingController(rootView: historyView)
|
|
|
|
let window = NSWindow(
|
|
contentRect: NSRect(x: 0, y: 0, width: 900, height: 700),
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
|
backing: .buffered,
|
|
defer: false
|
|
)
|
|
|
|
window.contentViewController = hostingController
|
|
window.title = "VoiceInk — Transcription History"
|
|
window.identifier = windowIdentifier
|
|
window.delegate = self
|
|
window.titlebarAppearsTransparent = true
|
|
window.titleVisibility = .visible
|
|
window.backgroundColor = NSColor.windowBackgroundColor
|
|
window.isReleasedWhenClosed = false
|
|
window.collectionBehavior = [.fullScreenPrimary]
|
|
window.minSize = NSSize(width: 700, height: 500)
|
|
|
|
window.setFrameAutosaveName(windowAutosaveName)
|
|
if !window.setFrameUsingName(windowAutosaveName) {
|
|
window.center()
|
|
}
|
|
|
|
return window
|
|
}
|
|
|
|
// MARK: - NSWindowDelegate
|
|
|
|
func windowWillClose(_ notification: Notification) {
|
|
guard let window = notification.object as? NSWindow,
|
|
window.identifier == windowIdentifier else { return }
|
|
|
|
historyWindow = nil
|
|
}
|
|
|
|
func windowDidBecomeKey(_ notification: Notification) {
|
|
guard let window = notification.object as? NSWindow,
|
|
window.identifier == windowIdentifier else { return }
|
|
NSApplication.shared.activate(ignoringOtherApps: true)
|
|
}
|
|
}
|