33 lines
931 B
Swift
33 lines
931 B
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
final class SettingsWindowController: NSObject, NSWindowDelegate {
|
|
private var window: NSWindow?
|
|
|
|
func windowWillClose(_ notification: Notification) {
|
|
window?.contentView = nil
|
|
window = nil
|
|
}
|
|
|
|
func show() {
|
|
if window == nil {
|
|
let window = NSWindow(
|
|
contentRect: NSRect(x: 0, y: 0, width: 540, height: 430),
|
|
styleMask: [.titled, .closable, .miniaturizable],
|
|
backing: .buffered,
|
|
defer: false
|
|
)
|
|
window.delegate = self
|
|
window.title = "TinySTT 设置"
|
|
window.isReleasedWhenClosed = false
|
|
window.contentView = NSHostingView(rootView: SettingsView())
|
|
window.center()
|
|
self.window = window
|
|
}
|
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
window?.makeKeyAndOrderFront(nil)
|
|
}
|
|
}
|