移除透明度调节功能,毛玻璃固定显示

This commit is contained in:
JOJO 2026-05-06 14:27:27 +08:00
parent f749771135
commit 6bc4971051
4 changed files with 7 additions and 39 deletions

View File

@ -1,7 +1,7 @@
import AppKit
import SwiftUI
/// + SwiftUI
/// + SwiftUI +
final class FloatingWindowController: NSWindowController {
private var hostingView: NSHostingView<ContentView>?
private var visualEffect: NSVisualEffectView!
@ -13,6 +13,8 @@ final class FloatingWindowController: NSWindowController {
setupVisualEffect()
}
// MARK: - alpha =1
private func setupVisualEffect() {
guard let window = window else { return }
@ -21,6 +23,7 @@ final class FloatingWindowController: NSWindowController {
ve.material = .hudWindow
ve.blendingMode = .behindWindow
ve.state = .active
ve.alphaValue = 1.0 //
ve.translatesAutoresizingMaskIntoConstraints = false
ve.layer?.cornerRadius = 16
@ -42,6 +45,8 @@ final class FloatingWindowController: NSWindowController {
])
}
// MARK: - SwiftUI
func embed(rootView: ContentView) {
guard let window = window, let contentView = window.contentView else { return }
@ -93,9 +98,7 @@ final class FloatingWindowController: NSWindowController {
window?.isVisible ?? false
}
func applyOpacity(_ value: Double) {
window?.alphaValue = value
}
// MARK: - &
func resize(width: CGFloat, height: CGFloat) {
guard let window = window else { return }

View File

@ -100,9 +100,6 @@ final class Configuration: ObservableObject {
@Published var refreshInterval: Double {
didSet { save("refreshInterval", refreshInterval) }
}
@Published var opacity: Double {
didSet { save("opacity", opacity) }
}
@Published var fontSize: Double {
didSet { save("fontSize", fontSize) }
}
@ -192,7 +189,6 @@ final class Configuration: ObservableObject {
processCount = defaults.object(forKey: "processCount") as? Int ?? 5
refreshInterval = defaults.object(forKey: "refreshInterval") as? Double ?? 1.5
opacity = defaults.object(forKey: "opacity") as? Double ?? 1.0
fontSize = defaults.object(forKey: "fontSize") as? Double ?? 12
windowWidth = defaults.object(forKey: "windowWidth") as? Double ?? 250
windowHeight = defaults.object(forKey: "windowHeight") as? Double ?? 300

View File

@ -36,14 +36,10 @@ struct ContentView: View {
.onAppear {
monitor.interval = config.refreshInterval
monitor.topN = config.processCount
applyOpacity()
}
.onChange(of: config.processCount) { _, new in
monitor.topN = new
}
.onChange(of: config.opacity) { _, _ in
applyOpacity()
}
.onReceive(NotificationCenter.default.publisher(for: .refreshIntervalChanged)) { notification in
if let interval = notification.object as? Double {
monitor.interval = interval
@ -269,9 +265,4 @@ struct ContentView: View {
}
}
private func applyOpacity() {
DispatchQueue.main.async {
windowController?.applyOpacity(config.opacity)
}
}
}

View File

@ -223,22 +223,6 @@ struct SettingsView: View {
.frame(width: 180)
}
HStack {
Text("透明度")
.font(.system(size: 12))
.frame(width: 52, alignment: .leading)
Slider(value: $config.opacity, in: 0.5...1.0, step: 0.05) {
Text("")
} onEditingChanged: { editing in
if !editing { updateWindowOpacity() }
}
.frame(width: 130)
Text(String(format: "%.0f%%", config.opacity * 100))
.font(.system(size: 11, design: .monospaced))
.foregroundColor(.secondary)
.frame(width: 38, alignment: .trailing)
}
HStack {
Text("字体大小")
.font(.system(size: 12))
@ -314,12 +298,6 @@ struct SettingsView: View {
)
}
private func updateWindowOpacity() {
if let window = NSApplication.shared.windows.first(where: { $0 is FloatingWindow }) {
window.alphaValue = config.opacity
}
}
private func closeWindow() {
NSApp.keyWindow?.close()
}