1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// 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()
}