61 lines
1.8 KiB
Swift
61 lines
1.8 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
final class FloatingWidgetWindow: NSPanel {
|
|
init() {
|
|
super.init(
|
|
contentRect: NSRect(x: 0, y: 0, width: 80, height: 60),
|
|
styleMask: [.borderless, .nonactivatingPanel],
|
|
backing: .buffered,
|
|
defer: false
|
|
)
|
|
|
|
isFloatingPanel = true
|
|
level = .floating
|
|
collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
|
|
isOpaque = false
|
|
backgroundColor = .clear
|
|
hasShadow = true
|
|
isMovableByWindowBackground = true
|
|
hidesOnDeactivate = false
|
|
animationBehavior = .none
|
|
|
|
if let screen = NSScreen.main {
|
|
let screenFrame = screen.visibleFrame
|
|
setFrameOrigin(NSPoint(x: screenFrame.maxX - 100, y: screenFrame.minY + 200))
|
|
}
|
|
|
|
contentView = NSHostingView(rootView: FloatingWidgetView())
|
|
}
|
|
|
|
override var canBecomeKey: Bool { false }
|
|
override var canBecomeMain: Bool { false }
|
|
}
|
|
|
|
struct FloatingWidgetView: View {
|
|
@State private var bugStore = BugStore.shared
|
|
|
|
var body: some View {
|
|
Button {
|
|
AppDelegate.shared?.togglePopover()
|
|
} label: {
|
|
HStack(spacing: 6) {
|
|
Image(systemName: "ant.fill")
|
|
.font(.title3)
|
|
Text("\(bugStore.unseenActiveCount)")
|
|
.font(.title2)
|
|
.fontWeight(.bold)
|
|
.contentTransition(.numericText())
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 12)
|
|
.fill(.ultraThinMaterial)
|
|
.shadow(color: .black.opacity(0.15), radius: 8, x: 0, y: 4)
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|