// // MacApp.swift // MacBackend // // Created by david-swift on 31.07.2024. // import AppKit @_exported import Meta @_exported import MetaSQLite /// The Meta app storage for the macOS backend. public class MacApp: AppStorage { /// The scene element type of the macOS backend. public typealias SceneElementType = MacSceneElement /// The app storage. public var storage: StandardAppStorage = .init() /// The application. let app = NSApplication.shared /// The menu bar. let mainMenu = NSMenu() /// The "" menu. let appItem = NSMenuItem(title: "", action: nil, keyEquivalent: "") /// The "Window" menu. let windowsItem = NSMenuItem(title: "Window", action: nil, keyEquivalent: "") /// The "Help" menu. let helpItem = NSMenuItem(title: "Help", action: nil, keyEquivalent: "") /// Initialize the app storage. /// - Parameter id: The identifier. public init(id: String) { app.mainMenu = mainMenu DatabaseInformation.setPath( URL.applicationSupportDirectory .appendingPathComponent(id) .appendingPathComponent("database.sqlite") .path ) } /// The app menu. func appMenu() { let appMenu = NSMenu() mainMenu.addItem(appItem) appItem.submenu = appMenu } /// The windows menu. func windowsMenu() { let windowsMenu = NSMenu() windowsItem.submenu = windowsMenu app.windowsMenu = windowsMenu } /// The help menu. func helpMenu() { let helpMenu = NSMenu() helpItem.submenu = helpMenu app.helpMenu = helpMenu } /// Add the windows and help menus. func addMenus() { mainMenu.addItem(windowsItem) mainMenu.addItem(helpItem) } /// Execute the app. /// - Parameter setup: Set the scene elements up. public func run(setup: @escaping () -> Void) { appMenu() windowsMenu() helpMenu() setup() addMenus() app.run() } /// Present the about window. public func showAboutWindow() { app.orderFrontStandardAboutPanel() } /// Quit the app. @objc public func quit() { app.terminate(nil) } /// Hide the app. public func hide() { app.hide(nil) } /// Hide other apps. public func hideOthers() { app.hideOtherApplications(nil) } /// Show all the apps. public func showAll() { app.unhideAllApplications(nil) } }