完善机巢任务实时同步并开放双构建真实操作
订阅明确无缓存时使用新发起的有效 HTTP 全量响应衔接首包,保留任务、批次和版本校验。 移除 Debug/Release 的设备指令、图传和 RTC 构建拦截,保留后端权限、身份、防重复提交及结果未知保护。 更新开发约定并补充隔离传输、飞控状态和页面回归测试。 验证:iPhone 真机 500 项相关测试通过;iOS Release 无签名编译通过。
This commit is contained in:
@@ -95,6 +95,9 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
realtimeSession?.onConnectionState = { [weak self] state in
|
||||
self?.connectionStateChanged(state)
|
||||
}
|
||||
realtimeSession?.onHTTPSeedRequired = { [weak self] in
|
||||
self?.refreshTaskIfVisible(isPolling: true)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@@ -439,18 +442,30 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
cancelScheduledPoll()
|
||||
requestGeneration &+= 1
|
||||
let generation = requestGeneration
|
||||
let httpSeedRequest = realtimeSession?.pendingHTTPSeedRequest
|
||||
isRequesting = true
|
||||
applySnapshot()
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
await self.viewModel.refresh()
|
||||
let seedResult: DroneDockHTTPSnapshotResult?
|
||||
if httpSeedRequest != nil { seedResult = await self.viewModel.refreshForRealtimeSeed() }
|
||||
else { await self.viewModel.refresh(); seedResult = nil }
|
||||
guard self.isPageVisible, self.isApplicationActive,
|
||||
self.requestGeneration == generation, !Task.isCancelled else { return }
|
||||
self.refreshTask = nil
|
||||
self.isRequesting = false
|
||||
if let httpSeedRequest, let seedResult {
|
||||
self.realtimeSession?.acceptHTTPSeed(seedResult, requestID: httpSeedRequest)
|
||||
}
|
||||
self.applySnapshot()
|
||||
if self.viewModel.canContinuePolling { self.realtimeSession?.start() }
|
||||
else { self.realtimeSession?.stop() }
|
||||
// 无缓存提示可能在旧 HTTP 读取途中到达;旧请求不充当首包,结束后再串行补读。
|
||||
if let pendingSeed = self.realtimeSession?.pendingHTTPSeedRequest, pendingSeed != httpSeedRequest,
|
||||
self.viewModel.canContinuePolling {
|
||||
self.refreshTaskIfVisible(isPolling: true)
|
||||
return
|
||||
}
|
||||
self.scheduleNextPoll()
|
||||
if !isPolling, self.viewModel.response != nil, let error = self.viewModel.errorMessage {
|
||||
self.showToast("刷新失败,当前显示上次数据:\(error)")
|
||||
@@ -571,7 +586,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
/// 重召唤使用原任务 ID,回执后再查询状态,避免从受理结果推断设备已到达。
|
||||
private func resummonIfAllowed() {
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
!isResummoningAction, !isStartingAction, !isSendingSafetyAction,
|
||||
viewModel.canResummon else { return }
|
||||
cancelPendingReadForAction()
|
||||
@@ -655,10 +670,10 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
feedPlaceholder.apply(liveViewModel)
|
||||
}
|
||||
|
||||
/// 返航会中断任务,先明确展示其含义再提交一次;Debug 只开放隔离模拟入口。
|
||||
/// 返航会中断任务,先明确展示其含义再提交一次。
|
||||
private func safetyCommandTriggered(_ command: DroneDockSafetyCommand) {
|
||||
logEvent("action.safety", fields: ["command": command.rawValue, "enabled": viewModel.canSendCommand(command)])
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
presentedViewController == nil, !submittingCommands.contains(command), !isStartingAction,
|
||||
!isResummoningAction, viewModel.canSendCommand(command) else {
|
||||
logSafetyRejection(command, stage: "tap")
|
||||
@@ -686,7 +701,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
/// 同步锁只覆盖同一按钮;不同安全动作可各自等待,设备确认由 ViewModel 和快照处理。
|
||||
private func sendSafetyCommand(_ command: DroneDockSafetyCommand) {
|
||||
guard allowsControlActions, isPageVisible, isApplicationActive,
|
||||
guard isPageVisible, isApplicationActive,
|
||||
!submittingCommands.contains(command), !isStartingAction, !isResummoningAction,
|
||||
viewModel.canSendCommand(command) else {
|
||||
logSafetyRejection(command, stage: "submit")
|
||||
@@ -757,9 +772,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
fields["page_visible"] = isPageVisible
|
||||
fields["app_active"] = isApplicationActive
|
||||
fields["view_in_window"] = isViewLoaded && view.window != nil
|
||||
fields["debug_flight_blocked"] = DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
fields["debug_live_blocked"] = DeviceCommandDebugPolicy.blocksLiveRequests
|
||||
fields["allows_control_actions"] = allowsControlActions
|
||||
viewModel.recordTaskEvent(name, fields: fields)
|
||||
}
|
||||
|
||||
@@ -779,7 +791,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
"submitting_commands": submittingCommands.map(\.rawValue).sorted()])
|
||||
var liveFields = feedPlaceholder.diagnosticFields
|
||||
switch liveViewModel.state {
|
||||
case .restricted: liveFields["state"] = "restricted"
|
||||
case .idle: liveFields["state"] = "idle"
|
||||
case .loading: liveFields["state"] = "loading"
|
||||
case .connecting: liveFields["state"] = "connecting"
|
||||
@@ -823,7 +834,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
|
||||
private func logSafetyRejection(_ command: DroneDockSafetyCommand, stage: String) {
|
||||
var reasons: [String] = []
|
||||
if !allowsControlActions { reasons.append("debug_policy") }
|
||||
if !isPageVisible { reasons.append("page_hidden") }
|
||||
if !isApplicationActive { reasons.append("app_inactive") }
|
||||
if stage == "tap", presentedViewController != nil { reasons.append("modal_presented") }
|
||||
@@ -835,9 +845,6 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
"reasons": reasons, "safety": safetyView.diagnosticFields])
|
||||
}
|
||||
|
||||
private var allowsControlActions: Bool {
|
||||
simulationRecordsProvider != nil || !DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
}
|
||||
}
|
||||
|
||||
/// 以可选择的 JSON 文本展示本地模拟请求与回执,避免与真实接口联调混淆。
|
||||
@@ -940,7 +947,6 @@ private final class DroneDockTaskSafetyView: UIView {
|
||||
/// 两个按钮始终表示暂停与返航;已暂停、返航中和回巢使用本地文案,恢复入口位于中央。
|
||||
func apply(model: DroneDockShootingTaskViewModel, isSimulation: Bool, isInteractive: Bool,
|
||||
submittingCommands: Set<DroneDockSafetyCommand> = []) {
|
||||
let allowsControls = isSimulation || !DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
let phase = model.presentation.phase
|
||||
var controlState = model.flightControlState
|
||||
if model.response?.flightControl == nil {
|
||||
@@ -974,7 +980,7 @@ private final class DroneDockTaskSafetyView: UIView {
|
||||
subtitle = "结果待核对"
|
||||
}
|
||||
let loading = submittingCommands.contains(command) || model.isCommandLoading(command)
|
||||
let enabled = allowsControls && isInteractive && model.canSendCommand(command)
|
||||
let enabled = isInteractive && model.canSendCommand(command)
|
||||
button.apply(title: title, subtitle: subtitle, enabled: enabled, isLoading: loading)
|
||||
button.setControlSymbol(command == .pause ? "pause.circle" : "arrow.uturn.backward")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user