fix: 自动开启机巢图传并修复日志崩溃与订阅重连

This commit is contained in:
2026-11-03 10:18:23 +08:00
parent 203799b2f4
commit 5d48e37cd7
12 changed files with 301 additions and 36 deletions
@@ -1,7 +1,7 @@
import SnapKit
import UIKit
/// 拍摄任务页:前台优先订阅快照、异常时 HTTP 兜底;图传与控制仍须用户手动操作。
/// 拍摄任务页:前台优先订阅快照、异常时 HTTP 兜底;自动开启图传,飞控仍由用户操作。
@MainActor
final class DroneDockShootingTaskViewController: BaseViewController {
/// 入口传入的固定任务身份及只读状态,供导航协调和页面测试检查。
@@ -14,7 +14,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
private let summaryView = UIView()
private let taskTitleLabel = DroneDockStyle.label(size: 17, weight: .semibold)
private let subtitleLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
private let feedPlaceholder = DroneDockTaskLiveView()
private let feedPlaceholder: DroneDockTaskLiveView
private let telemetryView = DroneShootingTaskTelemetryView()
private let statusView = DroneDockTaskStatusView()
private let safetyView = DroneDockTaskSafetyView()
@@ -45,11 +45,13 @@ final class DroneDockShootingTaskViewController: BaseViewController {
/// 构造时只保存依赖,首次 GET 必须等页面完整出现后才发送。
init(viewModel: DroneDockShootingTaskViewModel,
liveViewModel: DroneDockLiveViewModel? = nil,
livePlayer: (any DroneDockLivePlaying)? = nil,
realtimeSession: DroneDockShootingRealtimeSession? = nil,
materialsControllerFactory: (@MainActor (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController)? = nil,
simulationRecordsProvider: (@MainActor () -> String)? = nil,
shootingPollDelay: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) }) {
self.viewModel = viewModel
self.feedPlaceholder = livePlayer.map { DroneDockTaskLiveView(rtcPlayer: $0) } ?? DroneDockTaskLiveView()
self.realtimeSession = realtimeSession
self.liveViewModel = liveViewModel ?? DroneDockLiveViewModel(
context: viewModel.context, taskID: viewModel.taskID,
@@ -453,7 +455,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
}
}
/// 图传请求不轮询;正式入口仅响应用户点击,本地样片允许随页面加载。
/// 可见且活跃时自动开启一次;失败可手动重试,不随 shooting/Socket 刷新重复请求。
private func refreshLiveIfVisible(automatically: Bool = false) {
guard !automatically || liveViewModel.loadsAutomatically else { return }
guard isPageVisible, isApplicationActive, liveTask == nil, liveViewModel.canLoad else { return }