fix: 修根因——EventBus加buffer防事件丢失+恢复正确架构
根因:SharedFlow(replay=0,extraBufferCapacity=0)导致emit挂起, 多个collector竞争时事件丢失。之前的补丁越改越乱。 修复: 1. EventBus: extraBufferCapacity=64,emit不再阻塞 2. 恢复正确架构: - MainActivity: 监听MQTT type=1→NotificationManager→横幅 - NotificationManager: 处理后emit NewTaskArrived - HomeFragment: 监听NewTaskArrived→红点+统计 3. StatusBarView: 电池位置恢复原位,默认电量-1,主动查询系统电量 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,8 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class NotificationManager @Inject constructor(
|
||||
private val vibrationController: VibrationController,
|
||||
private val screenController: ScreenController
|
||||
private val screenController: ScreenController,
|
||||
private val eventBus: com.xiaoqu.watch.event.EventBus
|
||||
) {
|
||||
companion object {
|
||||
/** 去抖间隔(毫秒) */
|
||||
@@ -104,8 +105,12 @@ class NotificationManager @Inject constructor(
|
||||
for (json in jsons) {
|
||||
processMessageSilent(json) // 只加 ID,不重复震动
|
||||
}
|
||||
// 合并后通知 UI 更新数字
|
||||
onPendingCountChanged?.invoke(pendingCount)
|
||||
// 合并后通知 UI
|
||||
scope.launch {
|
||||
eventBus.emit(com.xiaoqu.watch.event.AppEvent.NewTaskArrived(
|
||||
_pendingTaskIds.toList(), _pendingTaskIds.size
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,7 +133,13 @@ class NotificationManager @Inject constructor(
|
||||
vibrationController.executePattern(pattern)
|
||||
}
|
||||
screenController.turnOn()
|
||||
// UI 更新(横幅+红点)由调用方处理,不再通过 EventBus
|
||||
|
||||
// 通知 HomeFragment 更新红点
|
||||
scope.launch {
|
||||
eventBus.emit(com.xiaoqu.watch.event.AppEvent.NewTaskArrived(
|
||||
_pendingTaskIds.toList(), _pendingTaskIds.size
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/** 静默处理(只加 ID,不震动不亮屏,用于合并暂存消息) */
|
||||
|
||||
Reference in New Issue
Block a user