78 lines
2.2 KiB
Swift
78 lines
2.2 KiB
Swift
//
|
|
// oAIApp.swift
|
|
// oAI
|
|
//
|
|
// Main app entry point
|
|
//
|
|
|
|
import SwiftUI
|
|
#if os(macOS)
|
|
import AppKit
|
|
#endif
|
|
|
|
@main
|
|
struct oAIApp: App {
|
|
@State private var chatViewModel = ChatViewModel()
|
|
@State private var showAbout = false
|
|
|
|
init() {
|
|
// Start email handler on app launch
|
|
EmailHandlerService.shared.start()
|
|
|
|
// Sync Git changes on app launch (pull + import)
|
|
Task {
|
|
await GitSyncService.shared.syncOnStartup()
|
|
}
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
ContentView()
|
|
.environment(chatViewModel)
|
|
.preferredColorScheme(.dark)
|
|
.sheet(isPresented: $showAbout) {
|
|
AboutView()
|
|
}
|
|
#if os(macOS)
|
|
.onReceive(NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification)) { _ in
|
|
// Trigger auto-save on app quit
|
|
Task {
|
|
await chatViewModel.onAppWillTerminate()
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
#if os(macOS)
|
|
.windowStyle(.hiddenTitleBar)
|
|
.windowToolbarStyle(.unified)
|
|
.defaultSize(width: 1024, height: 800)
|
|
.windowResizability(.contentMinSize)
|
|
.commands {
|
|
CommandGroup(replacing: .appInfo) {
|
|
Button("About oAI") {
|
|
showAbout = true
|
|
}
|
|
}
|
|
|
|
CommandGroup(replacing: .help) {
|
|
Button("oAI Help") {
|
|
openHelp()
|
|
}
|
|
.keyboardShortcut("?", modifiers: .command)
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#if os(macOS)
|
|
private func openHelp() {
|
|
if let helpBookURL = Bundle.main.url(forResource: "oAI.help", withExtension: nil) {
|
|
NSWorkspace.shared.open(helpBookURL.appendingPathComponent("Contents/Resources/en.lproj/index.html"))
|
|
} else {
|
|
// Fallback to Apple Help if help book not found
|
|
NSHelpManager.shared.openHelpAnchor("", inBook: Bundle.main.object(forInfoDictionaryKey: "CFBundleHelpBookName") as? String)
|
|
}
|
|
}
|
|
#endif
|
|
}
|