-
-
Notifications
You must be signed in to change notification settings - Fork 237
/
native_app_start_integration.dart
69 lines (62 loc) · 2.09 KB
/
native_app_start_integration.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'dart:async';
import 'package:meta/meta.dart';
import '../../sentry_flutter.dart';
import '../frame_callback_handler.dart';
import 'native_app_start_handler.dart';
/// Integration which calls [NativeAppStartHandler] after
/// [SchedulerBinding.instance.addPostFrameCallback] is called.
class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
NativeAppStartIntegration(
this._frameCallbackHandler, this._nativeAppStartHandler);
final FrameCallbackHandler _frameCallbackHandler;
final NativeAppStartHandler _nativeAppStartHandler;
DateTime? _appStartEnd;
/// This timestamp marks the end of app startup. Either set by calling
/// [SentryFlutter.setAppStartEnd]. The [SentryFlutterOptions.autoAppStart]
/// option needs to be false.
@internal
set appStartEnd(DateTime appStartEnd) {
_appStartEnd = appStartEnd;
if (!_appStartEndCompleter.isCompleted) {
_appStartEndCompleter.complete();
}
}
final Completer<void> _appStartEndCompleter = Completer<void>();
@override
void call(Hub hub, SentryFlutterOptions options) async {
_frameCallbackHandler.addPostFrameCallback((timeStamp) async {
try {
DateTime? appStartEnd;
if (options.autoAppStart) {
// ignore: invalid_use_of_internal_member
appStartEnd = options.clock();
} else if (_appStartEnd == null) {
await _appStartEndCompleter.future.timeout(
const Duration(seconds: 10),
);
appStartEnd = _appStartEnd;
} else {
appStartEnd = null;
}
if (appStartEnd != null) {
await _nativeAppStartHandler.call(
hub,
options,
appStartEnd: appStartEnd,
);
}
} catch (exception, stackTrace) {
options.logger(
SentryLevel.error,
'Error while capturing native app start',
exception: exception,
stackTrace: stackTrace,
);
if (options.automatedTestMode) {
rethrow;
}
}
});
options.sdk.addIntegration('nativeAppStartIntegration');
}
}