49 lines
1.5 KiB
Swift
49 lines
1.5 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
private final class AppDelegate: NSObject, NSApplicationDelegate {
|
|
func applicationWillFinishLaunching(_ notification: Notification) {
|
|
applyApplicationIcon()
|
|
}
|
|
|
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
applyApplicationIcon()
|
|
}
|
|
|
|
private func applyApplicationIcon() {
|
|
guard let iconURL = Bundle.main.url(forResource: "mactaskmanager", withExtension: "icns"),
|
|
let icon = NSImage(contentsOf: iconURL) else { return }
|
|
NSApplication.shared.applicationIconImage = icon
|
|
}
|
|
}
|
|
|
|
@main
|
|
struct MacTaskManagerApp: App {
|
|
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
|
@State private var monitor = SystemMonitor()
|
|
|
|
var body: some Scene {
|
|
WindowGroup("Task Manager") {
|
|
ContentView()
|
|
.environment(monitor)
|
|
.frame(minWidth: 980, minHeight: 640)
|
|
.task { monitor.start() }
|
|
}
|
|
.defaultSize(width: 1180, height: 760)
|
|
.windowStyle(.hiddenTitleBar)
|
|
.commands {
|
|
CommandGroup(replacing: .newItem) { }
|
|
CommandMenu("Options") {
|
|
Button("Refresh now") { monitor.refresh() }
|
|
.keyboardShortcut("r", modifiers: .command)
|
|
Divider()
|
|
Button(monitor.isPaused ? "Resume updates" : "Pause updates") {
|
|
monitor.isPaused.toggle()
|
|
}
|
|
.keyboardShortcut("p", modifiers: .command)
|
|
}
|
|
}
|
|
}
|
|
}
|