-
Notifications
You must be signed in to change notification settings - Fork 25
Feat: Share and Save logs files #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
3e5fc21
feat: add logger service with memory buffer and Riverpod provider
BraCR10 96bf7b1
fix : update config with logger constants
BraCR10 f31cdb6
feat : connect logs screen to logger service with real-time display
BraCR10 6b59aee
feat: sync logging toggle with MemoryLogOutput
BraCR10 062eef6
refactor: migrate files to use logger singleton
BraCR10 f5ed78b
docs: updating docs
BraCR10 e75a6d3
Merge branch 'feat/logging-phase-1' into feat/logging-phase-2
BraCR10 ae88c0c
Merge branch 'feat/logging-phase-1' into feat/logging-phase-2
BraCR10 c204c95
Merge remote-tracking branch 'origin/main' into feat/logging-phase-2
BraCR10 d040ffe
Migrate NostrService to use logger singleton
BraCR10 64fc240
Migrate mostro_storage to use logger singleton
BraCR10 c16c74a
Update docs for Phase 3 completion
BraCR10 5b7dd99
Enable isolate log receiver for background services
BraCR10 389b4be
Update docs for Phase 4 completion
BraCR10 cfd4fe7
Add bottom padding to logs list to prevent overlap with system buttons
BraCR10 80c6415
Localize relative time strings using timeAgoWithLocale extension
BraCR10 04c4482
Increase bottom padding in logs list to prevent overlap with system n…
BraCR10 6b8f801
Merge branch 'feat/logging-phase-2' into feat/logging-phases-3&4
BraCR10 d36ff88
Merge branch 'main' into feat/logging-phases-3&4
BraCR10 8382b55
Fix typo in LOGGING_IMPLEMENTATION.md
BraCR10 2e03a1e
Configure logger with IsolateLogOutput in mobile background isolate
BraCR10 8e2e557
Print background isolate logs to console only in debug mode
BraCR10 3ea02f5
Merge remote-tracking branch 'origin/feat/logging-phases-3&4' into fe…
BraCR10 30546b7
Add fallback logging for errors before logger initialization
BraCR10 cce5541
Add logger export service for logs save and share
BraCR10 13fd6b2
Add hamburger menu widget for logs screen
BraCR10 5331c4b
Integrate hamburger menu into logs screen
BraCR10 5ae1fdf
Remove unused logExportPath from Settings model
BraCR10 2e1cc9a
Add translations for logs export functionality
BraCR10 eab5ec3
Update documentation for Phase 5 completion
BraCR10 d3e6376
Merge remote-tracking branch 'origin/main' into feat/logging-phase-5
BraCR10 7c70560
Fix: code rabbit suggestions
BraCR10 282304a
Merge branch 'main' into feat/logging-phase-5
BraCR10 5e9b508
Merge branch 'main' into feat/logging-phase-5
BraCR10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:heroicons/heroicons.dart'; | ||
| import 'package:logger/logger.dart'; | ||
| import 'package:mostro_mobile/core/app_theme.dart'; | ||
| import 'package:mostro_mobile/features/logs/logs_provider.dart'; | ||
| import 'package:mostro_mobile/generated/l10n.dart'; | ||
| import 'package:mostro_mobile/services/logger_export_service.dart'; | ||
| import 'package:mostro_mobile/services/logger_service.dart'; | ||
|
|
||
| class LogsActionsMenu extends ConsumerWidget { | ||
| final _logger = Logger(); | ||
|
|
||
| LogsActionsMenu({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final logs = ref.watch(logsProvider); | ||
| final hasLogs = logs.isNotEmpty; | ||
|
|
||
| return PopupMenuButton<String>( | ||
| icon: const HeroIcon( | ||
| HeroIcons.ellipsisVertical, | ||
| style: HeroIconStyle.outline, | ||
| color: AppTheme.cream1, | ||
| size: 24, | ||
| ), | ||
| color: AppTheme.backgroundDark, | ||
| onSelected: (value) => _handleMenuAction(context, ref, value, logs), | ||
| itemBuilder: (context) => [ | ||
| _buildMenuItem( | ||
| 'save', | ||
| HeroIcons.arrowDownTray, | ||
| S.of(context)!.saveLogs, | ||
| hasLogs ? AppTheme.cream1 : AppTheme.textSecondary, | ||
| enabled: hasLogs, | ||
| ), | ||
| _buildMenuItem( | ||
| 'share', | ||
| HeroIcons.share, | ||
| S.of(context)!.shareLogs, | ||
| hasLogs ? AppTheme.cream1 : AppTheme.textSecondary, | ||
| enabled: hasLogs, | ||
| ), | ||
| _buildMenuItem( | ||
| 'clear', | ||
| HeroIcons.trash, | ||
| S.of(context)!.clearLogs, | ||
| hasLogs ? AppTheme.statusError : AppTheme.textSecondary, | ||
| enabled: hasLogs, | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
|
|
||
| PopupMenuItem<String> _buildMenuItem( | ||
| String value, | ||
| HeroIcons icon, | ||
| String label, | ||
| Color color, { | ||
| bool enabled = true, | ||
| }) { | ||
| return PopupMenuItem( | ||
| value: value, | ||
| enabled: enabled, | ||
| child: Row( | ||
| children: [ | ||
| HeroIcon( | ||
| icon, | ||
| style: HeroIconStyle.outline, | ||
| size: 20, | ||
| color: color, | ||
| ), | ||
| const SizedBox(width: 12), | ||
| Text( | ||
| label, | ||
| style: TextStyle( | ||
| color: enabled ? AppTheme.textPrimary : AppTheme.textSecondary, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| Future<void> _handleMenuAction( | ||
| BuildContext context, | ||
| WidgetRef ref, | ||
| String action, | ||
| List<LogEntry> logs, | ||
| ) async { | ||
| switch (action) { | ||
| case 'save': | ||
| await _saveLogsToFolder(context, ref, logs); | ||
| break; | ||
| case 'share': | ||
| await _shareLogsFile(context, logs); | ||
| break; | ||
| case 'clear': | ||
| await _showClearConfirmation(context, ref); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| Future<void> _saveLogsToFolder( | ||
| BuildContext context, | ||
| WidgetRef ref, | ||
| List<LogEntry> logs, | ||
| ) async { | ||
| final localizations = S.of(context)!; | ||
| final strings = LogExportStrings( | ||
| headerTitle: localizations.logsHeaderTitle, | ||
| generatedLabel: localizations.logsGeneratedLabel, | ||
| totalLabel: localizations.logsTotalLabel, | ||
| emptyMessage: localizations.noLogsAvailable, | ||
| ); | ||
|
|
||
| try { | ||
| final filePath = await LoggerExportService.exportLogsToFolder(logs, strings); | ||
|
|
||
| if (filePath != null && context.mounted) { | ||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| SnackBar( | ||
| content: Text(localizations.logsExportSuccess), | ||
| backgroundColor: AppTheme.statusSuccess, | ||
| ), | ||
| ); | ||
| } | ||
| } catch (e, stackTrace) { | ||
| _logger.e('Error exporting logs', error: e, stackTrace: stackTrace); | ||
| if (context.mounted) { | ||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| SnackBar( | ||
| content: Text(localizations.logsExportError), | ||
| backgroundColor: AppTheme.statusError, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Future<void> _shareLogsFile(BuildContext context, List<LogEntry> logs) async { | ||
| final localizations = S.of(context)!; | ||
| final strings = LogExportStrings( | ||
| headerTitle: localizations.logsHeaderTitle, | ||
| generatedLabel: localizations.logsGeneratedLabel, | ||
| totalLabel: localizations.logsTotalLabel, | ||
| emptyMessage: localizations.noLogsAvailable, | ||
| ); | ||
|
|
||
| try { | ||
| final file = await LoggerExportService.exportLogsForSharing(logs, strings); | ||
| await LoggerExportService.shareLogs( | ||
| file, | ||
| subject: localizations.logsShareSubject, | ||
| text: localizations.logsShareText, | ||
| ); | ||
| } catch (e, stackTrace) { | ||
| _logger.e('Error sharing logs', error: e, stackTrace: stackTrace); | ||
| if (context.mounted) { | ||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| SnackBar( | ||
| content: Text(localizations.shareLogsError), | ||
| backgroundColor: AppTheme.statusError, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Future<void> _showClearConfirmation(BuildContext context, WidgetRef ref) async { | ||
| final confirmed = await showDialog<bool>( | ||
| context: context, | ||
| builder: (context) => AlertDialog( | ||
| backgroundColor: AppTheme.backgroundDark, | ||
| title: Text( | ||
| S.of(context)!.clearLogs, | ||
| style: const TextStyle(color: AppTheme.textPrimary), | ||
| ), | ||
| content: Text( | ||
| S.of(context)!.clearLogsConfirmation, | ||
| style: const TextStyle(color: AppTheme.textSecondary), | ||
| ), | ||
| actions: [ | ||
| TextButton( | ||
| onPressed: () => Navigator.of(context).pop(false), | ||
| child: Text( | ||
| S.of(context)!.cancel, | ||
| style: const TextStyle(color: AppTheme.textSecondary), | ||
| ), | ||
| ), | ||
| TextButton( | ||
| onPressed: () => Navigator.of(context).pop(true), | ||
| child: Text( | ||
| S.of(context)!.clear, | ||
| style: const TextStyle(color: AppTheme.statusError), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
|
|
||
| if (confirmed == true) { | ||
| ref.read(logsProvider.notifier).clearLogs(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.