mirror of
https://github.com/pboulch/luto.git
synced 2025-12-19 12:52:47 +00:00
🎉 first commit
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user