Skip to content

Commit

Permalink
In the case where the user is stuck with the message "Saving a local …
Browse files Browse the repository at this point in the history
…version…", we will now send the error to the server
  • Loading branch information
g123k committed Jul 14, 2023
1 parent 1cd22a6 commit 8ed7a1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ class AnalyticsHelper {
}
}

static void sendException(dynamic throwable, {dynamic stackTrace}) {
Sentry.captureException(throwable, stackTrace: stackTrace);
}

static String? get matomoVisitorId => MatomoTracker.instance.visitor.id;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@
"@crop_page_action_local": {
"description": "Action being performed on the crop page"
},
"crop_page_action_local_failed": "An error occurred while saving the image. Please try again later.",
"@crop_page_action_local_failed": {
"description": "The save of the picture locally failed"
},
"crop_page_too_small_image_title": "The image is too small!",
"@crop_page_too_small_image_title": {
"description": "Title of a dialog warning the user that the image is too small for upload"
Expand Down
21 changes: 18 additions & 3 deletions packages/smooth_app/lib/pages/crop_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/database_helper.dart';
import 'package:smooth_app/helpers/image_compute_container.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
Expand Down Expand Up @@ -227,7 +228,7 @@ class _CropPageState extends State<CropPage> {
/// Returns a small file with the cropped image, for the transient image.
///
/// Here we use BMP format as it's faster to encode.
Future<File> _getCroppedImageFile(
Future<File?> _getCroppedImageFile(
final Directory directory,
final int sequenceNumber,
) async {
Expand All @@ -239,7 +240,17 @@ class _CropPageState extends State<CropPage> {
maxSize: _screenSize.longestSide,
);
setState(() => _progress = appLocalizations.crop_page_action_local);
await saveBmp(file: result, source: cropped);

try {
await saveBmp(file: result, source: cropped)
.timeout(const Duration(seconds: 10));
} catch (e, trace) {
setState(
() => _progress = appLocalizations.crop_page_action_local_failed);
AnalyticsHelper.sendException(e, stackTrace: trace);
return null;
}

return result;
}

Expand Down Expand Up @@ -305,11 +316,15 @@ class _CropPageState extends State<CropPage> {
await getNextSequenceNumber(daoInt, _CROP_PAGE_SEQUENCE_KEY);
final Directory directory = await getApplicationSupportDirectory();

final File croppedFile = await _getCroppedImageFile(
final File? croppedFile = await _getCroppedImageFile(
directory,
sequenceNumber,
);

if (croppedFile == null) {
return null;
}

setState(
() => _progress = appLocalizations.crop_page_action_server,
);
Expand Down

0 comments on commit 8ed7a1b

Please sign in to comment.