Skip to content

Commit dc9dd3f

Browse files
committed
You can now upload the most recent log file
1 parent 034111f commit dc9dd3f

File tree

1 file changed

+68
-32
lines changed

1 file changed

+68
-32
lines changed

lib/screens/settings_screen.dart

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ class _SettingsScreenState extends State<SettingsScreen> {
9393
}
9494
}
9595

96+
/// Upload the current (active) log file by rotating it first
97+
Future<void> _uploadCurrentLogFile(AppStateProvider appState, File currentFile) async {
98+
final originalPath = currentFile.path;
99+
100+
setState(() {
101+
_uploadingFilePath = originalPath;
102+
});
103+
104+
try {
105+
// Rotate the log: closes current file, starts a new one
106+
// The original file is now closed and safe to upload
107+
await appState.prepareDebugLogsForUpload();
108+
109+
if (!mounted) return;
110+
111+
// The original file still exists at the same path, now closed
112+
final closedFile = File(originalPath);
113+
if (!closedFile.existsSync()) {
114+
throw Exception('Log file not found after rotation');
115+
}
116+
117+
// Now upload the closed file
118+
await _uploadSingleLogFile(appState, closedFile);
119+
} catch (e) {
120+
debugError('[SETTINGS] Current log upload error: $e');
121+
if (mounted) {
122+
setState(() {
123+
_uploadingFilePath = null;
124+
});
125+
AppToast.error(context, 'Upload error: $e');
126+
}
127+
}
128+
}
129+
96130
void _onVersionTap(AppStateProvider appState) {
97131
final now = DateTime.now();
98132

@@ -587,39 +621,41 @@ class _SettingsScreenState extends State<SettingsScreen> {
587621
trailing: Row(
588622
mainAxisSize: MainAxisSize.min,
589623
children: [
590-
// Upload button - hidden for current log file
591-
if (!isCurrentLog) ...[
592-
if (wasUploaded)
593-
Container(
594-
width: 40,
595-
height: 40,
596-
alignment: Alignment.center,
597-
child: const Icon(
598-
Icons.check_circle,
599-
size: 20,
600-
color: Colors.green,
601-
),
602-
)
603-
else if (isUploading)
604-
Container(
605-
width: 40,
606-
height: 40,
607-
alignment: Alignment.center,
608-
child: const SizedBox(
609-
width: 20,
610-
height: 20,
611-
child: CircularProgressIndicator(strokeWidth: 2),
612-
),
613-
)
614-
else
615-
IconButton(
616-
icon: const Icon(Icons.cloud_upload, size: 20),
617-
onPressed: _uploadingFilePath != null
618-
? null
619-
: () => _uploadSingleLogFile(appState, file),
620-
tooltip: 'Upload to developer',
624+
// Upload button
625+
if (wasUploaded)
626+
Container(
627+
width: 40,
628+
height: 40,
629+
alignment: Alignment.center,
630+
child: const Icon(
631+
Icons.check_circle,
632+
size: 20,
633+
color: Colors.green,
621634
),
622-
],
635+
)
636+
else if (isUploading)
637+
Container(
638+
width: 40,
639+
height: 40,
640+
alignment: Alignment.center,
641+
child: const SizedBox(
642+
width: 20,
643+
height: 20,
644+
child: CircularProgressIndicator(strokeWidth: 2),
645+
),
646+
)
647+
else
648+
IconButton(
649+
icon: const Icon(Icons.cloud_upload, size: 20),
650+
onPressed: _uploadingFilePath != null
651+
? null
652+
: () => isCurrentLog
653+
? _uploadCurrentLogFile(appState, file)
654+
: _uploadSingleLogFile(appState, file),
655+
tooltip: isCurrentLog
656+
? 'Close log and upload'
657+
: 'Upload to developer',
658+
),
623659
// View button
624660
IconButton(
625661
icon: const Icon(Icons.visibility, size: 20),

0 commit comments

Comments
 (0)