vOOice/VoiceInk/Views/Recorder/MiniRecorderPanel.swift

64 lines
1.8 KiB
Swift

import SwiftUI
import AppKit
class MiniRecorderPanel: NSPanel {
override var canBecomeKey: Bool { false }
override var canBecomeMain: Bool { false }
init(contentRect: NSRect) {
super.init(
contentRect: contentRect,
styleMask: [.nonactivatingPanel, .fullSizeContentView],
backing: .buffered,
defer: false
)
self.isFloatingPanel = true
self.level = .floating
self.backgroundColor = .clear
self.isOpaque = false
self.hasShadow = false
self.isMovableByWindowBackground = true
self.hidesOnDeactivate = false
self.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
self.titlebarAppearsTransparent = true
self.titleVisibility = .hidden
self.standardWindowButton(.closeButton)?.isHidden = true
self.isMovable = true
}
static func calculateWindowMetrics() -> NSRect {
guard let screen = NSScreen.main else {
return NSRect(x: 0, y: 0, width: 150, height: 34)
}
let width: CGFloat = 150 // Adjusted for new spacing and negative padding
let height: CGFloat = 34
let padding: CGFloat = 24
let visibleFrame = screen.visibleFrame
let xPosition = visibleFrame.midX - (width / 2)
let yPosition = visibleFrame.minY + padding
return NSRect(
x: xPosition,
y: yPosition,
width: width,
height: height
)
}
func show() {
let metrics = MiniRecorderPanel.calculateWindowMetrics()
setFrame(metrics, display: true)
orderFrontRegardless()
}
func hide(completion: @escaping () -> Void) {
completion()
}
}