2025-08-24 16:24:21 -07:00
|
|
|
//
|
|
|
|
|
// kordophone2App.swift
|
|
|
|
|
// kordophone2
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 8/24/25.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
@main
|
|
|
|
|
struct KordophoneApp: App
|
|
|
|
|
{
|
|
|
|
|
@State var conversationListModel = ConversationListView.ViewModel()
|
2025-08-24 23:38:35 -07:00
|
|
|
@State var transcriptViewModel = TranscriptView.ViewModel()
|
2025-08-24 17:58:37 -07:00
|
|
|
@State var entryViewModel = MessageEntryView.ViewModel()
|
2025-08-24 16:24:21 -07:00
|
|
|
|
|
|
|
|
private let xpcClient = XPCClient()
|
2025-08-24 17:58:37 -07:00
|
|
|
private var selectedConversation: Display.Conversation? {
|
|
|
|
|
guard let id = conversationListModel.selectedConversations.first else { return nil }
|
|
|
|
|
return conversationListModel.conversations.first { $0.id == id }
|
|
|
|
|
}
|
2025-08-24 16:24:21 -07:00
|
|
|
|
|
|
|
|
var body: some Scene {
|
|
|
|
|
WindowGroup {
|
|
|
|
|
NavigationSplitView {
|
|
|
|
|
ConversationListView(model: $conversationListModel)
|
|
|
|
|
.frame(minWidth: 330.0)
|
2025-08-24 17:58:37 -07:00
|
|
|
.xpcClient(xpcClient)
|
2025-08-24 16:24:21 -07:00
|
|
|
} detail: {
|
2025-08-24 17:58:37 -07:00
|
|
|
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
|
|
|
|
|
}
|
2025-08-24 16:24:21 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func reportError(_ e: Error) {
|
|
|
|
|
// Just printing for now.
|
|
|
|
|
print("Error: \(e.localizedDescription)")
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-24 17:58:37 -07:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|