- 菜单栏:CPU/GPU/内存多样式、网速两行、温度、风扇 - 面板:概览仪表盘、进程、散热、防休眠,液态玻璃与浅色/深色主题 - 采集层:CPU/内存/网络/GPU/磁盘/电池/进程/SMC 温度与风扇,按界面分级采样 - root 辅助工具:风扇调速、合盖不睡眠,断开时自动恢复 - XcodeGen 工程、单元测试、截图模式
55 lines
1.8 KiB
Swift
55 lines
1.8 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
// 液态玻璃:macOS 26 起使用系统 Liquid Glass,更早的系统退回毛玻璃材质。
|
|
// 截图模式无法捕获窗口背后的模糊,统一改用实色。
|
|
|
|
extension View {
|
|
@ViewBuilder
|
|
func dsGlass<S: Shape>(in shape: S, interactive: Bool = false, tint: Color? = nil) -> some View {
|
|
if #available(macOS 26.0, *) {
|
|
glassEffect(interactive ? Glass.regular.tint(tint).interactive() : Glass.regular.tint(tint), in: shape)
|
|
} else {
|
|
background(.ultraThinMaterial, in: shape)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 面板窗口的玻璃底板,SwiftUI 内容放在其中
|
|
@MainActor
|
|
enum GlassBackdrop {
|
|
static func make(containing content: NSView, cornerRadius: CGFloat) -> NSView {
|
|
if #available(macOS 26.0, *) {
|
|
let glass = NSGlassEffectView()
|
|
glass.cornerRadius = cornerRadius
|
|
glass.style = .regular
|
|
glass.contentView = content
|
|
return glass
|
|
}
|
|
let effect = NSVisualEffectView()
|
|
effect.material = .popover
|
|
effect.blendingMode = .behindWindow
|
|
effect.state = .active
|
|
effect.wantsLayer = true
|
|
effect.layer?.cornerRadius = cornerRadius
|
|
effect.layer?.masksToBounds = true
|
|
content.frame = effect.bounds
|
|
content.autoresizingMask = [.width, .height]
|
|
effect.addSubview(content)
|
|
return effect
|
|
}
|
|
}
|
|
|
|
/// 设置窗口侧边栏的半透明背景
|
|
struct SidebarMaterial: NSViewRepresentable {
|
|
func makeNSView(context: Context) -> NSVisualEffectView {
|
|
let view = NSVisualEffectView()
|
|
view.material = .sidebar
|
|
view.blendingMode = .behindWindow
|
|
view.state = .followsWindowActiveState
|
|
return view
|
|
}
|
|
|
|
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {}
|
|
}
|