Sessions Integration Feature
Nucleic-Session: FC94353F-9F0D-4BCC-AD7C-0FB14E38C2E5 Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -255,75 +255,6 @@ final class RemoteStore: ObservableObject {
|
||||
/// In-flight simulated-run tasks (canned streaming), cancelled on `exitDemo()`.
|
||||
private var demoTasks: [Task<Void, Never>] = []
|
||||
|
||||
// MARK: - Multi-host switching (mesh P3)
|
||||
|
||||
/// One selectable Mac for the host switcher — the paired Macs (live) or the mock hosts (demo).
|
||||
struct HostChoice: Identifiable, Equatable {
|
||||
let id: String // HostID (fingerprint), or a demo id
|
||||
let name: String
|
||||
let isActive: Bool
|
||||
}
|
||||
|
||||
/// The Macs this phone can switch between. Live: the paired-host registry. Demo: the mock hosts.
|
||||
/// One entry ⇒ the switcher hides itself and the app reads single-host. Today the phone holds one
|
||||
/// *live* connection at a time (switching reconnects); simultaneous connections are the deferred
|
||||
/// multiplexer step.
|
||||
var hostChoices: [HostChoice] {
|
||||
if demoMode {
|
||||
return demoHosts.map { HostChoice(id: $0.id, name: $0.name, isActive: $0.id == activeHostID) }
|
||||
}
|
||||
return IdentityStore.pairedHosts().map {
|
||||
HostChoice(id: $0.fingerprint, name: $0.hostName, isActive: $0.fingerprint == activeHostID)
|
||||
}
|
||||
}
|
||||
|
||||
/// Switch which paired Mac is active. Live: every Mac is already connected, so this is instant —
|
||||
/// close the current transcript, re-point at the target connection, and mirror its state. Demo:
|
||||
/// swap the mock host's projection, preserving in-demo edits.
|
||||
func switchHost(to id: String) {
|
||||
guard id != activeHostID else { return }
|
||||
if demoMode {
|
||||
if let i = demoHosts.firstIndex(where: { $0.id == activeHostID }) {
|
||||
demoHosts[i].sessions = sessions // keep any in-demo mutations
|
||||
demoHosts[i].dashboard = dashboard
|
||||
}
|
||||
guard let next = demoHosts.first(where: { $0.id == id }) else { return }
|
||||
applyDemoHost(next)
|
||||
} else {
|
||||
// Close the transcript open on the old host.
|
||||
activeConnection?.openSessionID = nil
|
||||
openSessionID = nil; openEvents = []; openApprovals = []; openDiff = nil; diffLoading = false
|
||||
activeHostID = id
|
||||
// The target should already be connected; (re)dial only if it isn't.
|
||||
if let host = IdentityStore.pairedHost(id: id) {
|
||||
let conn = connection(for: host)
|
||||
if !conn.connectivity.isLive { conn.reconnect(to: host) }
|
||||
}
|
||||
mirrorActive()
|
||||
}
|
||||
}
|
||||
|
||||
/// Mock hosts for the multi-host demo. Each carries its own name + sessions + dashboard;
|
||||
/// switching swaps the flat active-host projection. Empty outside demo.
|
||||
private struct DemoHost {
|
||||
let id: String
|
||||
let name: String
|
||||
var sessions: [WireSessionSummary]
|
||||
var dashboard: DashboardSnapshot
|
||||
}
|
||||
private var demoHosts: [DemoHost] = []
|
||||
|
||||
/// Project a mock host onto the flat active-host state (demo host switch).
|
||||
private func applyDemoHost(_ host: DemoHost) {
|
||||
activeHostID = host.id
|
||||
hostName = host.name
|
||||
sessions = host.sessions
|
||||
dashboard = host.dashboard
|
||||
openSessionID = nil; openEvents = []; openApprovals = []; openDiff = nil
|
||||
LiveActivityManager.shared.sync(hostName: hostName, sessions: sessions)
|
||||
NotificationRouter.shared.updateBadge(needsYouCount)
|
||||
}
|
||||
|
||||
var isPaired: Bool { demoMode || IdentityStore.loadPairedHost() != nil }
|
||||
var deviceFingerprint: String { identity.fingerprint }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user