Initial MacTaskManager release
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user