diff --git a/flutter/lib/src/integrations/native_app_start_integration.dart b/flutter/lib/src/integrations/native_app_start_integration.dart index a1112dd4a..a82c1cff8 100644 --- a/flutter/lib/src/integrations/native_app_start_integration.dart +++ b/flutter/lib/src/integrations/native_app_start_integration.dart @@ -32,34 +32,26 @@ class NativeAppStartIntegration extends Integration { @override void call(Hub hub, SentryFlutterOptions options) async { - if (!options.autoAppStart && _appStartEnd == null) { - await _callThrowing(options, () async { - await _appStartEndCompleter.future.timeout(const Duration(seconds: 10)); - await _nativeAppStartHandler.call(hub, options, - appStartEnd: _appStartEnd); - }); - } else { - _frameCallbackHandler.addPostFrameCallback((timeStamp) async { - await _callThrowing(options, () async { - await _nativeAppStartHandler.call(hub, options, - appStartEnd: _appStartEnd); - }); - }); - } + _frameCallbackHandler.addPostFrameCallback((timeStamp) async { + try { + if (!options.autoAppStart && _appStartEnd == null) { + await _appStartEndCompleter.future + .timeout(const Duration(seconds: 10)); + } + await _nativeAppStartHandler.call( + hub, + options, + appStartEnd: _appStartEnd, + ); + } catch (exception, stackTrace) { + options.logger( + SentryLevel.error, + 'Error while capturing native app start', + exception: exception, + stackTrace: stackTrace, + ); + } + }); options.sdk.addIntegration('nativeAppStartIntegration'); } - - Future _callThrowing( - SentryOptions options, Future Function() callback) async { - try { - await callback(); - } catch (exception, stackTrace) { - options.logger( - SentryLevel.error, - 'Error while capturing native app start', - exception: exception, - stackTrace: stackTrace, - ); - } - } } diff --git a/flutter/test/integrations/native_app_start_integration_test.dart b/flutter/test/integrations/native_app_start_integration_test.dart index 00cee0e5b..02dbee711 100644 --- a/flutter/test/integrations/native_app_start_integration_test.dart +++ b/flutter/test/integrations/native_app_start_integration_test.dart @@ -56,6 +56,8 @@ void main() { fixture.options.autoAppStart = false; fixture.callIntegration(); + final postFrameCallback = fixture.frameCallbackHandler.postFrameCallback!; + postFrameCallback(Duration(seconds: 0)); expect(fixture.nativeAppStartHandler.calls, 0); @@ -64,7 +66,7 @@ void main() { await Future.delayed(Duration(milliseconds: 10)); - expect(fixture.frameCallbackHandler.postFrameCallback, isNull); + expect(fixture.frameCallbackHandler.postFrameCallback, isNotNull); expect(fixture.nativeAppStartHandler.calls, 1); expect(fixture.nativeAppStartHandler.appStartEnd, appStartEnd); }); @@ -75,12 +77,14 @@ void main() { fixture.options.autoAppStart = false; fixture.callIntegration(); + final postFrameCallback = fixture.frameCallbackHandler.postFrameCallback!; + postFrameCallback(Duration(seconds: 0)); expect(fixture.nativeAppStartHandler.calls, 0); await Future.delayed(Duration(seconds: 11)); - expect(fixture.frameCallbackHandler.postFrameCallback, isNull); + expect(fixture.frameCallbackHandler.postFrameCallback, isNotNull); expect(fixture.nativeAppStartHandler.calls, 0); expect(fixture.nativeAppStartHandler.appStartEnd, null); });