vOOice/VoiceInk/HistoryWindowController.swift
Beingpax 531da7b172 Redesign transcription history with three-pane layout and compact audio player
- Implement three-pane Xcode-style layout with toggleable sidebars
- Refactor into modular components for better maintainability
- Replace tabbed interface with iMessage-style message bubbles
- Redesign audio player for 70% height reduction with horizontal layout
- Update to native macOS colors and remove custom backgrounds
- Increase minimum window size to 1000x700 for better usability
2025-12-29 11:44:50 +05:45

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: 1000, minHeight: 700)
let hostingController = NSHostingController(rootView: historyView)
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 1100, height: 750),
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: 1000, height: 700)
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)
}
}