// // CustomWindowControls.swift // punchnet // // Created by 安礼成 on 2026/3/25. // import SwiftUI struct CustomWindowControls: View { @State private var isHovering = false var body: some View { HStack(spacing: 8) { // 关闭按钮 (红色) CircleButton(color: .red, systemName: "xmark", isHovering: isHovering) { // 执行关闭当前窗口的操作 if let window = NSApp.keyWindow { window.close() } } // // 最小化按钮 (黄色) // CircleButton(color: .yellow, systemName: "minus", isHovering: isHovering) { // NSApp.keyWindow?.miniaturize(nil) // } // // // 全屏/放大按钮 (绿色) // CircleButton(color: .green, systemName: "arrow.up.left.and.arrow.down.right", isHovering: isHovering) { // NSApp.keyWindow?.toggleFullScreen(nil) // } } .onHover { hovering in withAnimation(.easeInOut(duration: 0.1)) { isHovering = hovering } } } } struct CircleButton: View { let color: Color let systemName: String let isHovering: Bool let action: () -> Void var body: some View { Button(action: action) { ZStack { Circle() .fill(color.opacity(0.8)) .frame(width: 12, height: 12) // 只有悬停时才显示里面的小图标,像原生一样 Image(systemName: systemName) .font(.system(size: 8, weight: .bold)) .foregroundColor(.black.opacity(0.5)) .opacity(isHovering ? 1 : 0) } } .buttonStyle(.plain) } }