Improve share intake diagnostics
This commit is contained in:
@@ -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