mirror of
https://github.com/pboulch/luto.git
synced 2025-12-19 12:52:47 +00:00
60 lines
1.6 KiB
Swift
60 lines
1.6 KiB
Swift
//
|
|
// LutoApp.swift
|
|
// Luto
|
|
//
|
|
// Created by Pierre Boulc'h on 04/07/2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
@main
|
|
struct LutoApp: App {
|
|
|
|
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
|
|
|
var body: some Scene {
|
|
WindowGroup(id: "MainWindow") {
|
|
MainView()
|
|
}
|
|
}
|
|
}
|
|
|
|
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: "A brain")
|
|
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()
|
|
)
|
|
}
|
|
|
|
@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)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|