chore: adiciona .gitignore e commit.command
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
import Inject
|
||||
import SwiftUI
|
||||
|
||||
struct AutoDownloadBannerView: View {
|
||||
@ObserveInjection var inject
|
||||
enum Style {
|
||||
case info
|
||||
case error
|
||||
}
|
||||
|
||||
var title: String
|
||||
var subtitle: String?
|
||||
var progress: Double?
|
||||
var style: Style = .info
|
||||
|
||||
private var normalizedProgress: Double? {
|
||||
progress.map { min(max($0, 0), 1) }
|
||||
}
|
||||
|
||||
private var accentColor: Color {
|
||||
switch style {
|
||||
case .info:
|
||||
return .accentColor
|
||||
case .error:
|
||||
return .red
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
Image(systemName: iconName)
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.foregroundStyle(accentColor)
|
||||
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text(title)
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.foregroundColor(.primary)
|
||||
|
||||
if let subtitle {
|
||||
Text(subtitle)
|
||||
.font(.system(size: 11))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
if let normalizedProgress {
|
||||
ProgressView(value: normalizedProgress)
|
||||
.progressViewStyle(.linear)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(.thinMaterial)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(accentColor.opacity(style == .error ? 0.4 : 0.25), lineWidth: 1)
|
||||
)
|
||||
.shadow(color: .black.opacity(0.12), radius: 8, x: 0, y: 4)
|
||||
.enableInjection()
|
||||
}
|
||||
|
||||
private var iconName: String {
|
||||
switch style {
|
||||
case .info:
|
||||
return "arrow.down.circle.fill"
|
||||
case .error:
|
||||
return "exclamationmark.triangle.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
VStack(spacing: 12) {
|
||||
AutoDownloadBannerView(
|
||||
title: "Preparing Parakeet",
|
||||
subtitle: "42% downloaded",
|
||||
progress: 0.42
|
||||
)
|
||||
|
||||
AutoDownloadBannerView(
|
||||
title: "Model download failed",
|
||||
subtitle: "Check your connection and retry",
|
||||
progress: nil,
|
||||
style: .error
|
||||
)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// InvisibleWindow.swift
|
||||
// Hex
|
||||
//
|
||||
// Created by Kit Langton on 1/24/25.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// This allows us to render SwiftUI views anywhere on the screen, without dealing with the awkward
|
||||
/// rendering issues that come with normal MacOS windows. Essentially, we create one giant invisible
|
||||
/// window that covers the entire screen, and render our SwiftUI views into it.
|
||||
///
|
||||
/// I'm pretty sure this is what CleanShot X and other apps do to render their floating widgets.
|
||||
/// But if there's a better way to do this, I'd love to know!
|
||||
class InvisibleWindow: NSPanel {
|
||||
override var canBecomeKey: Bool { false }
|
||||
override var canBecomeMain: Bool { false }
|
||||
|
||||
private var currentScreen: NSScreen?
|
||||
private var mouseMonitor: Any?
|
||||
|
||||
init() {
|
||||
let screen = NSScreen.main ?? NSScreen.screens[0]
|
||||
let styleMask: NSWindow.StyleMask = [.fullSizeContentView, .borderless, .utilityWindow, .nonactivatingPanel]
|
||||
|
||||
super.init(contentRect: screen.frame,
|
||||
styleMask: styleMask,
|
||||
backing: .buffered,
|
||||
defer: false)
|
||||
|
||||
level = .statusBar
|
||||
backgroundColor = .clear
|
||||
isOpaque = false
|
||||
hasShadow = false
|
||||
ignoresMouseEvents = true
|
||||
hidesOnDeactivate = false // Prevent hiding when app loses focus
|
||||
canHide = false
|
||||
collectionBehavior = [.fullScreenAuxiliary, .canJoinAllSpaces, .stationary, .ignoresCycle]
|
||||
|
||||
// Set initial frame
|
||||
updateToScreenWithMouse()
|
||||
|
||||
// Start observing screen changes
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(screenDidChange),
|
||||
name: NSWindow.didChangeScreenNotification,
|
||||
object: nil
|
||||
)
|
||||
|
||||
// Also observe screen parameters for resolution changes
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
selector: #selector(screenDidChange),
|
||||
name: NSApplication.didChangeScreenParametersNotification,
|
||||
object: nil
|
||||
)
|
||||
|
||||
// Monitor mouse movements to detect screen boundary crossings
|
||||
mouseMonitor = NSEvent.addGlobalMonitorForEvents(matching: .mouseMoved) { [weak self] _ in
|
||||
self?.checkForScreenChange()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
if let monitor = mouseMonitor {
|
||||
NSEvent.removeMonitor(monitor)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateToScreenWithMouse() {
|
||||
let mouseLocation = NSEvent.mouseLocation
|
||||
guard let screenWithMouse = NSScreen.screens.first(where: { $0.frame.contains(mouseLocation) }) else { return }
|
||||
currentScreen = screenWithMouse
|
||||
setFrame(screenWithMouse.frame, display: true)
|
||||
}
|
||||
|
||||
private func checkForScreenChange() {
|
||||
let mouseLocation = NSEvent.mouseLocation
|
||||
guard let newScreen = NSScreen.screens.first(where: { $0.frame.contains(mouseLocation) }) else { return }
|
||||
|
||||
// Only update if screen actually changed
|
||||
if newScreen !== currentScreen {
|
||||
currentScreen = newScreen
|
||||
setFrame(newScreen.frame, display: true)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func screenDidChange(_: Notification) {
|
||||
updateToScreenWithMouse()
|
||||
}
|
||||
}
|
||||
|
||||
extension InvisibleWindow: NSWindowDelegate {
|
||||
static func fromView<V: View>(_ view: V) -> InvisibleWindow {
|
||||
let window = InvisibleWindow()
|
||||
window.contentView = NSHostingView(rootView: view)
|
||||
window.delegate = window
|
||||
return window
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user