Skip to content

Commit

Permalink
Add attachScreenshotOnlyWhenResumed to options (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Nov 7, 2023
1 parent 64af39c commit 9f05645
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Breadcrumbs for database operations ([#1656](https://github.com/getsentry/sentry-dart/pull/1656))
- Add `attachScreenshotOnlyWhenResumed` to options ([#1700](https://github.com/getsentry/sentry-dart/pull/1700))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../screenshot/sentry_screenshot_widget.dart';
import '../sentry_flutter_options.dart';
import 'package:flutter/rendering.dart';
import '../renderer/renderer.dart';
import 'package:flutter/widgets.dart' as widget;

class ScreenshotEventProcessor implements EventProcessor {
final SentryFlutterOptions _options;
Expand Down Expand Up @@ -38,6 +39,14 @@ class ScreenshotEventProcessor implements EventProcessor {
return event;
}

if (_options.attachScreenshotOnlyWhenResumed &&
widget.WidgetsBinding.instance.lifecycleState !=
AppLifecycleState.resumed) {
_options.logger(SentryLevel.debug,
'Only attaching screenshots when application state is resumed.');
return event;
}

final bytes = await _createScreenshot();
if (bytes != null) {
hint?.screenshot = SentryAttachment.fromScreenshotData(bytes);
Expand Down
3 changes: 3 additions & 0 deletions flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class SentryFlutterOptions extends SentryOptions {
/// The quality of the attached screenshot
SentryScreenshotQuality screenshotQuality = SentryScreenshotQuality.high;

/// Only attach a screenshot when the app is resumed.
bool attachScreenshotOnlyWhenResumed = false;

/// Enable or disable automatic breadcrumbs for User interactions Using [Listener]
///
/// Requires adding the [SentryUserInteractionWidget] to the widget tree.
Expand Down

0 comments on commit 9f05645

Please sign in to comment.