Monitor/Sources/FloatingMonitor/App/SettingsWindowController.swift
JOJO 4ab9a7b28c Initial: FloatingMonitor — macOS 悬浮系统监控
- 实时 CPU/GPU/内存/Swap 监控 + Top 进程
- 5 种计量器样式(圆环/条状/纯文本/扇形/紧凑)
- 半透明悬浮窗 + 菜单栏图标控制
- 独立设置窗口,每模块可指定行号+列位布局
- 窗口宽高/透明度/字体全局可调
2026-05-05 21:26:44 +08:00

42 lines
1.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import AppKit
import SwiftUI
/// SettingsWindow
final class SettingsWindowController: NSWindowController {
private let monitor: SystemMonitor
init(monitor: SystemMonitor) {
self.monitor = monitor
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 340, height: 640),
styleMask: [.titled, .closable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false
)
window.title = "Monitor 设置"
window.titlebarAppearsTransparent = true
window.isReleasedWhenClosed = false
window.minSize = NSSize(width: 300, height: 480)
super.init(window: window)
// SwiftUI
let settingsView = SettingsView(monitor: monitor)
let hostingView = NSHostingView(rootView: settingsView)
hostingView.translatesAutoresizingMaskIntoConstraints = false
window.contentView = hostingView
window.center()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func show() {
window?.center()
window?.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: false)
}
}