import AppKit import ArgumentParser import Foundation extension phbar { struct start: ParsableCommand { static let configuration = CommandConfiguration( commandName: "start", abstract: "Start the status bar." ) @Flag(name: .long, help: "Display visual guides to help align elements.") var debug: Bool = false mutating func run() throws { let config = try PHConfig.load() // NOTE: Make sure NSApp.run() runs in the main thread dispatchPrecondition(condition: .onQueue(.main)) try MainActor.assumeIsolated { // Spawn a bar on every screen; per-monitor window and block-set // selection is driven by the config's `[monitor]` overrides. let screens = NSScreen.screens guard !screens.isEmpty else { throw CleanExit.message("No monitor found") } let delegate = try AppDelegate( config: config, screens: screens, debug: debug ) let app = NSApplication.shared app.setActivationPolicy(.accessory) app.delegate = delegate app.run() throw ExitCode.success } } } }