import LChatCore import SwiftUI import WebKit // 🤖 A GROUP chat's shared app surface: the selected added app's interface, // rendered by the shared embed page (FeedWebCache) — seeded with this thread's // key plus the app to show (app != nil). ONE cached page serves // all the group's apps; switching apps is a JS call into it // (WebBridge.setGroupApp), never a reload. NativeChatScreen swaps this in for // the native feed when the header's view picker chooses an app. struct GroupAppPane: View { @ObservedObject private var bridge: WebBridge let instance: SavedInstance let thread: ChatThread let myUserId: String let instanceKeyB64: String? let app: String @MainActor init(instance: SavedInstance, thread: ChatThread, myUserId: String, instanceKeyB64: String?, app: String) { self.instance = instance self.thread = thread self.myUserId = myUserId self.instanceKeyB64 = instanceKeyB64 self.app = app bridge = FeedWebCache.shared.bridge(for: instance, thread: thread, myUserId: myUserId, instanceKeyB64: instanceKeyB64, app: app) } var body: some View { VStack(spacing: 0) { AppUpdateBar(bridge: bridge) ZStack { GroupAppWebView(instance: instance, thread: thread, myUserId: myUserId, instanceKeyB64: instanceKeyB64, app: app) if !bridge.pageReady { WebLoadingVeil().transition(.opacity) } } } .animation(.easeOut(duration: 0.25), value: bridge.pageReady) // Re-assert the selection on every appearance/switch. The boot seed // carries the app chosen at page-creation time; a still-booting page // ignores the JS no-op, so the ready flip re-asserts once more. .onAppear { bridge.setGroupApp(app) } .onChange(of: app) { _, newApp in bridge.setGroupApp(newApp) } .onChange(of: bridge.pageReady) { _, ready in if ready { bridge.setGroupApp(app) } } } } private struct GroupAppWebView: UIViewRepresentable { let instance: SavedInstance let thread: ChatThread let myUserId: String let instanceKeyB64: String? let app: String func makeUIView(context: Context) -> WKWebView { FeedWebCache.shared.webView(for: instance, thread: thread, myUserId: myUserId, instanceKeyB64: instanceKeyB64, app: app) } func updateUIView(_ web: WKWebView, context: Context) {} }