🎉 first commit

This commit is contained in:
2023-07-13 11:56:17 +02:00
parent 92e03bc310
commit 3ad6ee9134
8 changed files with 328 additions and 32 deletions

View File

@ -9,9 +9,51 @@ import SwiftUI
@main
struct LutoApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
WindowGroup(id: "MainWindow") {
MainView(taskTitle: "", taskDescription: "", listTask: [])
}
}
}
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
private var statusItem: NSStatusItem!
private var popover: NSPopover!
@MainActor func applicationDidFinishLaunching(_ notification: Notification) {
if let window = NSApplication.shared.windows.first {
window.close()
}
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
if let statusButton = statusItem.button {
statusButton.image = NSImage(systemSymbolName: "brain", accessibilityDescription: "Chart Line")
statusButton.action = #selector(togglePopover)
}
self.popover = NSPopover()
self.popover.contentSize = NSSize(width: 500, height: 500)
self.popover.behavior = .transient
self.popover.contentViewController = NSHostingController(rootView: MainView(taskTitle: "", taskDescription: "", listTask: [])
)
}
@objc func togglePopover() {
if let button = statusItem.button {
if popover.isShown {
self.popover.performClose(nil)
} else {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
}
}
}
}