Skip to content

Commit

Permalink
Fix blockng ui issue
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Sep 11, 2024
1 parent 461d207 commit affdf87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
48 changes: 20 additions & 28 deletions flutter/lib/src/integrations/native_app_start_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,26 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {

@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<void> _callThrowing(
SentryOptions options, Future<void> Function() callback) async {
try {
await callback();
} catch (exception, stackTrace) {
options.logger(
SentryLevel.error,
'Error while capturing native app start',
exception: exception,
stackTrace: stackTrace,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -64,7 +66,7 @@ void main() {

await Future<void>.delayed(Duration(milliseconds: 10));

expect(fixture.frameCallbackHandler.postFrameCallback, isNull);
expect(fixture.frameCallbackHandler.postFrameCallback, isNotNull);
expect(fixture.nativeAppStartHandler.calls, 1);
expect(fixture.nativeAppStartHandler.appStartEnd, appStartEnd);
});
Expand All @@ -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<void>.delayed(Duration(seconds: 11));

expect(fixture.frameCallbackHandler.postFrameCallback, isNull);
expect(fixture.frameCallbackHandler.postFrameCallback, isNotNull);
expect(fixture.nativeAppStartHandler.calls, 0);
expect(fixture.nativeAppStartHandler.appStartEnd, null);
});
Expand Down

0 comments on commit affdf87

Please sign in to comment.