~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/atirc-ios-client

0
1
main
50 lines · 1.3 KB Raw History
//
//  ContentView.swift
//  AT-IRC
//

import SwiftUI
import UIKit

struct ContentView: View {
    @State private var store = ChatStore()
    @State private var kcp = KCPHost()
    @State private var ready = false

    var body: some View {
        Group {
            if store.isSignedIn {
                ChatView(store: store, kcp: kcp)
            } else {
                LoginView(store: store)
            }
        }
        .overlay {
            if !ready {
                ZStack {
                    Rectangle().fill(.background).ignoresSafeArea()
                    VStack(spacing: 12) {
                        ProgressView()
                        Text("Loading…")
                            .font(.callout)
                            .foregroundStyle(.secondary)
                    }
                }
            }
        }
        .onReceive(NotificationCenter.default.publisher(for: UIApplication.didReceiveMemoryWarningNotification)) { _ in
            // Chat stays usable whatever kcp does: drop the embedded control
            // plane on memory pressure instead of waiting for a jetsam kill.
            kcp.stop()
        }
        .task {
            store.restore()
            await store.start()
            ready = true
        }
    }
}

#Preview {
    ContentView()
}