Skip to content
Source
Sign inSign up
samwillis/jerry
Open History to see the last commit

JerryApp.swift

68 lines3.6 KB

1import AppKit
2import CoreGraphics
3​
4@main
5@MainActor
6enum JerryApp {
7 static func main() {
8 let application = NSApplication.shared
9 if ProcessInfo.processInfo.arguments.contains("--terrain-report") {
10 guard let screen = NSScreen.screens.first, let terrain = WindowProvider().snapshot(on: screen) else {
11 print("Window geometry unavailable")
12 return
13 }
14 print("Geometry readable: \(terrain.windows.count) windows; \(terrain.windows.filter(\.canClimb).count) climbable; \(terrain.surfaces.count) exposed segments (including screen boundaries)")
15 print("Screen capture permission already granted: \(CGPreflightScreenCaptureAccess()). No permission requested.")
16 return
17 }
18 #if DEBUG
19 if ProcessInfo.processInfo.arguments.contains("--jol-preview") || ProcessInfo.processInfo.arguments.contains("--journal-preview") || ProcessInfo.processInfo.arguments.contains("--live-photo-preview") {
20 application.setActivationPolicy(.regular); application.finishLaunching()
21 let menu = NSMenu(); let item = NSMenuItem(); let appMenu = NSMenu()
22 appMenu.addItem(withTitle: "Quit Jerry", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
23 item.submenu = appMenu; menu.addItem(item); application.mainMenu = menu
24 Task { do {
25 if ProcessInfo.processInfo.arguments.contains("--jol-preview") { AgentPrototypeChecks.showJOLPreview() }
26 else if ProcessInfo.processInfo.arguments.contains("--live-photo-preview") { try await AgentPrototypeChecks.showLivePhotoPreview() }
27 else { try await AgentPrototypeChecks.showJournalPreview() }
28 } catch { print(error); exit(1) } }
29 application.run(); return
30 }
31 if ProcessInfo.processInfo.arguments.contains("--agent-checks") {
32 application.setActivationPolicy(.accessory); application.finishLaunching()
33 Task { let passed = await AgentPrototypeChecks.run(); exit(passed ? 0 : 1) }
34 application.run(); return
35 }
36 if ProcessInfo.processInfo.arguments.contains("--feature-checks") {
37 application.setActivationPolicy(.accessory)
38 application.finishLaunching()
39 Task {
40 let standard = await WindowFeatureCapture.runNativeChecks()
41 let large = await WindowFeatureCapture.runNativeChecks(size: .init(width: 1372, height: 920))
42 exit(standard && large ? 0 : 1)
43 }
44 application.run()
45 return
46 }
47 if ProcessInfo.processInfo.arguments.contains("--native-checks") {
48 application.setActivationPolicy(.accessory)
49 application.finishLaunching()
50 let overlay = OverlayController()
51 let passed = overlay.runNativeChecks()
52 let menusPassed = AppDelegate().runActivityMenuChecks()
53 exit(passed && menusPassed ? 0 : 1)
54 }
55 #endif
56 if let bundleID = Bundle.main.bundleIdentifier,
57 NSRunningApplication.runningApplications(withBundleIdentifier: bundleID).contains(where: { $0.processIdentifier != ProcessInfo.processInfo.processIdentifier && !$0.isTerminated }) {
58 print("Jerry is already running. Use its hiking menu to quit before launching another build.")
59 return
60 }
61 let delegate = AppDelegate()
62 application.delegate = delegate
63 application.setActivationPolicy(.accessory)
64 withExtendedLifetime(delegate) {
65 application.run()
66 }
67 }