Files
luto/Luto/LutoApp.swift

59 lines
1.6 KiB
Swift
Raw Permalink Normal View History

2023-07-04 19:01:13 +02:00
//
// LutoApp.swift
// Luto
//
// Created by Pierre Boulc'h on 04/07/2023.
//
import SwiftUI
@main
struct LutoApp: App {
2023-07-13 11:56:17 +02:00
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
2023-07-04 19:01:13 +02:00
var body: some Scene {
2023-07-13 11:56:17 +02:00
WindowGroup(id: "MainWindow") {
2023-07-19 13:01:33 +02:00
MainView(viewModel: TaskViewModel())
2023-07-04 19:01:13 +02:00
}
}
}
2023-07-13 11:56:17 +02:00
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 {
2023-07-13 13:02:39 +02:00
statusButton.image = NSImage(systemSymbolName: "brain", accessibilityDescription: "A brain")
2023-07-13 11:56:17 +02:00
statusButton.action = #selector(togglePopover)
}
self.popover = NSPopover()
self.popover.contentSize = NSSize(width: 500, height: 500)
self.popover.behavior = .transient
2023-07-19 13:01:33 +02:00
self.popover.contentViewController = NSHostingController(rootView: MainView(viewModel: TaskViewModel()))
2023-07-13 11:56:17 +02:00
}
@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)
}
}
}
}