vOOice/VoiceInk/HistoryWindowController.swift
Beingpax d2dd506a94 Move transcription history to separate window
- Add HistoryWindowController for native macOS window management
- Update MenuBarManager to support window opening
- Modify sidebar to open history in separate window instead of inline
- Update navigation handlers to use window controller
- Settings remains inline as before
2025-12-28 15:30:48 +05:45

77 lines
2.7 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) {
if let existingWindow = historyWindow, existingWindow.isVisible {
existingWindow.makeKeyAndOrderFront(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
return
}
let window = createHistoryWindow(modelContainer: modelContainer)
historyWindow = window
window.makeKeyAndOrderFront(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
}
private func createHistoryWindow(modelContainer: ModelContainer) -> NSWindow {
let historyView = TranscriptionHistoryView()
.modelContainer(modelContainer)
.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)
}
}