// // kordophone2App.swift // kordophone2 // // Created by James Magahern on 8/24/25. // import SwiftUI @main struct KordophoneApp: App { @State var conversationListModel = ConversationListView.ViewModel() @State var transcriptViewModel = TranscriptView.ViewModel() @State var entryViewModel = MessageEntryView.ViewModel() private let xpcClient = XPCClient() private var selectedConversation: Display.Conversation? { guard let id = conversationListModel.selectedConversations.first else { return nil } return conversationListModel.conversations.first { $0.id == id } } var body: some Scene { WindowGroup { NavigationSplitView { ConversationListView(model: $conversationListModel) .frame(minWidth: 330.0) .xpcClient(xpcClient) } detail: { ConversationView(transcriptModel: $transcriptViewModel, entryModel: $entryViewModel) .xpcClient(xpcClient) .selectedConversation(selectedConversation) .navigationTitle("Kordophone") .navigationSubtitle(selectedConversation?.displayName ?? "") .onChange(of: conversationListModel.selectedConversations) { oldValue, newValue in transcriptViewModel.displayedConversation = newValue.first } } } Settings { PreferencesView() } } private func reportError(_ e: Error) { // Just printing for now. print("Error: \(e.localizedDescription)") } } extension EnvironmentValues { @Entry var xpcClient: XPCClient = XPCClient() @Entry var selectedConversation: Display.Conversation? = nil } extension View { func xpcClient(_ client: XPCClient) -> some View { environment(\.xpcClient, client) } func selectedConversation(_ convo: Display.Conversation?) -> some View { environment(\.selectedConversation, convo) } }