Log H5 perf bridge events

This commit is contained in:
Developer
2026-06-12 14:06:29 +07:00
parent f232c4d10a
commit 8e9cbb0316

View File

@@ -126,6 +126,7 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
int _resumeRecoveryToken = 0; int _resumeRecoveryToken = 0;
DateTime? _backgroundedAt; DateTime? _backgroundedAt;
late ShellBranding _shellBranding; late ShellBranding _shellBranding;
final DateTime _shellStartedAt = DateTime.now();
_H5LineWebViewSlot get _currentSlot => _lineSlot; _H5LineWebViewSlot get _currentSlot => _lineSlot;
@@ -426,6 +427,22 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
debugPrint('[H5LineDebug] $message'); debugPrint('[H5LineDebug] $message');
} }
int get _elapsedSinceShellStartMs =>
DateTime.now().difference(_shellStartedAt).inMilliseconds;
void _logShellPerfBridge(Map<dynamic, dynamic> decoded) {
final label = decoded['label']?.toString() ?? 'unknown';
final status = decoded['status']?.toString() ?? 'info';
final duration = decoded['durationMs'];
final detail = decoded['detail'];
final durationText = duration == null ? '' : ' ${duration}ms';
final detailText = detail == null ? '' : ' detail=${jsonEncode(detail)}';
debugPrint(
'[H5PerfBridge] +${_elapsedSinceShellStartMs}ms '
'$label $status$durationText$detailText',
);
}
bool _isCurrentLineGeneration(int generation) { bool _isCurrentLineGeneration(int generation) {
return generation == _lineGeneration; return generation == _lineGeneration;
} }
@@ -475,6 +492,8 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
_hideShellCover(generation); _hideShellCover(generation);
} else if (decoded is Map && decoded['type'] == 'keyboard-bridge-ready') { } else if (decoded is Map && decoded['type'] == 'keyboard-bridge-ready') {
unawaited(_syncKeyboardState()); unawaited(_syncKeyboardState());
} else if (decoded is Map && decoded['type'] == 'perf-log') {
_logShellPerfBridge(decoded);
} else if (decoded is Map && decoded['type'] == 'openExternalUrl') { } else if (decoded is Map && decoded['type'] == 'openExternalUrl') {
unawaited(_openExternalUrl(decoded['url']?.toString())); unawaited(_openExternalUrl(decoded['url']?.toString()));
} }
@@ -514,6 +533,8 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
unawaited(openAppSettings()); unawaited(openAppSettings());
case 'keyboard-bridge-ready': case 'keyboard-bridge-ready':
unawaited(_syncKeyboardState()); unawaited(_syncKeyboardState());
case 'perf-log':
_logShellPerfBridge(decoded);
case 'openExternalUrl': case 'openExternalUrl':
unawaited(_openExternalUrl(decoded['url']?.toString())); unawaited(_openExternalUrl(decoded['url']?.toString()));
} }