fix(mobile-app): App进入后台时立即上传遥测队列
问题:TelemetryService.dispose()从未被调用,导致forceUploadAll() 永远不执行;uploadIfNeeded()有10条最小阈值,单次会话只有2-3条 事件无法触发上传,设备信息永远留在本地队列。 修复:进入后台(paused)结束session后,立即调用uploadBatch() 绕过10条阈值,确保每次App切换到后台时都能上报事件。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2c312a850b
commit
9e90294d0e
|
|
@ -95,6 +95,9 @@ class SessionManager with WidgetsBindingObserver {
|
|||
|
||||
_state = SessionState.background;
|
||||
_endCurrentSession();
|
||||
|
||||
// session_end 写入队列后立即上传,不等待10条阈值
|
||||
_telemetryService?.flushOnBackground();
|
||||
}
|
||||
|
||||
/// 开始新会话
|
||||
|
|
|
|||
|
|
@ -373,6 +373,12 @@ class TelemetryService {
|
|||
/// 获取设备上下文
|
||||
DeviceContext? get deviceContext => _deviceContext;
|
||||
|
||||
/// App进入后台时调用:忽略10条阈值,立即上传队列中的事件
|
||||
Future<void> flushOnBackground() async {
|
||||
await _uploader.uploadBatch(batchSize: 50);
|
||||
debugPrint('📊 [Telemetry] Flushed on background');
|
||||
}
|
||||
|
||||
/// App退出前调用
|
||||
Future<void> dispose() async {
|
||||
_configSyncTimer?.cancel();
|
||||
|
|
|
|||
Loading…
Reference in New Issue