Improve share intake diagnostics
This commit is contained in:
@@ -520,11 +520,12 @@ class _ShareDiagnosticsDialog extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: events
|
||||
.map(
|
||||
(ShareIntakeDebugEvent event) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: SelectableText(
|
||||
'${_debugTimeLabel(event.at)} ${event.stage}\n${event.message}',
|
||||
),
|
||||
(
|
||||
ShareIntakeDebugEvent event,
|
||||
) => _ShareDiagnosticsEventTile(
|
||||
event: event,
|
||||
label:
|
||||
'${_debugTimeLabel(event.at)} ${event.stage}\n${event.message}',
|
||||
),
|
||||
)
|
||||
.toList(growable: false),
|
||||
@@ -545,6 +546,51 @@ class _ShareDiagnosticsDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _ShareDiagnosticsEventTile extends StatelessWidget {
|
||||
const _ShareDiagnosticsEventTile({required this.event, required this.label});
|
||||
|
||||
final ShareIntakeDebugEvent event;
|
||||
final String label;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String? details = event.details;
|
||||
if (details == null || details.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: SelectableText(label),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
childrenPadding: const EdgeInsets.only(top: 6, bottom: 8),
|
||||
title: SelectableText(label),
|
||||
subtitle: Text(
|
||||
'Tap to show raw shared text (${details.length} chars).',
|
||||
),
|
||||
children: <Widget>[
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Theme.of(context).dividerColor),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: SelectableText(details),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _debugTimeLabel(DateTime value) {
|
||||
return '${value.hour.toString().padLeft(2, '0')}:${value.minute.toString().padLeft(2, '0')}:${value.second.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const String _shareIntakeDebugLogKey = 'share_intake_debug_log_v1';
|
||||
const int _maxShareIntakeDebugEvents = 40;
|
||||
const int _maxShareIntakeDebugDetailChars = 6000;
|
||||
|
||||
class ShareIntakeDebugEvent {
|
||||
const ShareIntakeDebugEvent({
|
||||
required this.at,
|
||||
required this.stage,
|
||||
required this.message,
|
||||
this.details,
|
||||
});
|
||||
|
||||
factory ShareIntakeDebugEvent.fromJson(Map<String, dynamic> json) {
|
||||
@@ -19,18 +21,21 @@ class ShareIntakeDebugEvent {
|
||||
).toLocal(),
|
||||
stage: json['stage'] as String? ?? 'unknown',
|
||||
message: json['message'] as String? ?? '',
|
||||
details: json['details'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
final DateTime at;
|
||||
final String stage;
|
||||
final String message;
|
||||
final String? details;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'at': at.toUtc().toIso8601String(),
|
||||
'stage': stage,
|
||||
'message': message,
|
||||
if (details != null) 'details': details,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -55,11 +60,16 @@ class ShareIntakeDebugLog {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> record(String stage, String message) async {
|
||||
Future<void> record(String stage, String message, {String? details}) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final List<ShareIntakeDebugEvent> current = await read();
|
||||
final List<ShareIntakeDebugEvent> next = <ShareIntakeDebugEvent>[
|
||||
ShareIntakeDebugEvent(at: DateTime.now(), stage: stage, message: message),
|
||||
ShareIntakeDebugEvent(
|
||||
at: DateTime.now(),
|
||||
stage: stage,
|
||||
message: message,
|
||||
details: _compactDetails(details),
|
||||
),
|
||||
...current,
|
||||
].take(_maxShareIntakeDebugEvents).toList(growable: false);
|
||||
await prefs.setString(
|
||||
@@ -77,3 +87,14 @@ class ShareIntakeDebugLog {
|
||||
await prefs.remove(_shareIntakeDebugLogKey);
|
||||
}
|
||||
}
|
||||
|
||||
String? _compactDetails(String? value) {
|
||||
final String? trimmed = value?.trim();
|
||||
if (trimmed == null || trimmed.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
if (trimmed.length <= _maxShareIntakeDebugDetailChars) {
|
||||
return trimmed;
|
||||
}
|
||||
return '${trimmed.substring(0, _maxShareIntakeDebugDetailChars)}\n[truncated]';
|
||||
}
|
||||
|
||||
@@ -159,6 +159,12 @@ class _IncomingShareListenerState extends ConsumerState<IncomingShareListener> {
|
||||
return;
|
||||
}
|
||||
|
||||
await _debugLog.record(
|
||||
'raw_share_text',
|
||||
'Captured raw share text (${trimmed.length} chars).',
|
||||
details: trimmed,
|
||||
);
|
||||
|
||||
final SharedPayload? payload = buildSharedPayloadFromRawText(
|
||||
rawText: trimmed,
|
||||
platform: defaultTargetPlatform.name,
|
||||
|
||||
Reference in New Issue
Block a user