fix(mining-app): 前台回来时也上传遥测队列(大厂标准做法)
- 进入后台(paused)时立即 flush:session_end + 设备信息不丢失 - 回到前台(resumed)时立即 flush:上传被强杀遗留事件 + 新 session_start Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
893513ad78
commit
5e6ab25199
|
|
@ -70,6 +70,8 @@ class SessionManager with WidgetsBindingObserver {
|
||||||
|
|
||||||
_state = SessionState.foreground;
|
_state = SessionState.foreground;
|
||||||
_startNewSession();
|
_startNewSession();
|
||||||
|
// 上传上次被强杀遗留的事件 + 本次 session_start(含设备信息)
|
||||||
|
_telemetryService?.flushOnBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleBackground() {
|
void _handleBackground() {
|
||||||
|
|
@ -77,6 +79,8 @@ class SessionManager with WidgetsBindingObserver {
|
||||||
|
|
||||||
_state = SessionState.background;
|
_state = SessionState.background;
|
||||||
_endCurrentSession();
|
_endCurrentSession();
|
||||||
|
// session_end 写入队列后立即上传,不等待阈值
|
||||||
|
_telemetryService?.flushOnBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startNewSession() {
|
void _startNewSession() {
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,11 @@ class TelemetryService {
|
||||||
debugPrint('[Telemetry] User ID cleared');
|
debugPrint('[Telemetry] User ID cleared');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> flushOnBackground() async {
|
||||||
|
await _uploader.uploadBatch(batchSize: 50);
|
||||||
|
debugPrint('[Telemetry] Flushed on background');
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> pauseForLogout() async {
|
Future<void> pauseForLogout() async {
|
||||||
_uploader.stopPeriodicUpload();
|
_uploader.stopPeriodicUpload();
|
||||||
await _storage.clearEventQueue();
|
await _storage.clearEventQueue();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue