-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
sentry_app.dart
136 lines (119 loc) · 4.16 KB
/
sentry_app.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:meta/meta.dart';
/// App context describes the application.
///
/// As opposed to the runtime, this is the actual application that was
/// running and carries metadata about the current session.
@immutable
class SentryApp {
static const type = 'app';
const SentryApp({
this.name,
this.version,
this.identifier,
this.build,
this.buildType,
this.startTime,
this.deviceAppHash,
this.appMemory,
this.inForeground,
this.viewNames,
this.textScale,
});
/// Human readable application name, as it appears on the platform.
final String? name;
/// Human readable application version, as it appears on the platform.
final String? version;
/// Version-independent application identifier, often a dotted bundle ID.
final String? identifier;
/// Internal build identifier, as it appears on the platform.
final String? build;
/// String identifying the kind of build, e.g. `testflight`.
final String? buildType;
/// When the application was started by the user.
final DateTime? startTime;
/// Application specific device identifier.
final String? deviceAppHash;
/// Amount of memory used by the application in bytes.
final int? appMemory;
/// A flag indicating whether the app is in foreground or not.
/// An app is in foreground when it's visible to the user.
final bool? inForeground;
/// The names of the currently visible views.
final List<String>? viewNames;
/// The text scale of the [SentryWidget] using fontSize == 1
final double? textScale;
/// Deserializes a [SentryApp] from JSON [Map].
factory SentryApp.fromJson(Map<String, dynamic> data) {
final viewNamesJson = data['view_names'] as List<dynamic>?;
return SentryApp(
name: data['app_name'],
version: data['app_version'],
identifier: data['app_identifier'],
build: data['app_build'],
buildType: data['build_type'],
startTime: data['app_start_time'] != null
? DateTime.tryParse(data['app_start_time'])
: null,
deviceAppHash: data['device_app_hash'],
appMemory: data['app_memory'],
inForeground: data['in_foreground'],
viewNames: viewNamesJson?.map((e) => e as String).toList(),
textScale: data['text_scale'],
);
}
/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
if (name != null) 'app_name': name!,
if (version != null) 'app_version': version!,
if (identifier != null) 'app_identifier': identifier!,
if (build != null) 'app_build': build!,
if (buildType != null) 'build_type': buildType!,
if (startTime != null) 'app_start_time': startTime!.toIso8601String(),
if (deviceAppHash != null) 'device_app_hash': deviceAppHash!,
if (appMemory != null) 'app_memory': appMemory!,
if (inForeground != null) 'in_foreground': inForeground!,
if (viewNames != null && viewNames!.isNotEmpty) 'view_names': viewNames!,
if (textScale != null) 'text_scale': textScale!,
};
}
SentryApp clone() => SentryApp(
name: name,
version: version,
identifier: identifier,
build: build,
buildType: buildType,
startTime: startTime,
deviceAppHash: deviceAppHash,
appMemory: appMemory,
inForeground: inForeground,
viewNames: viewNames,
textScale: textScale,
);
SentryApp copyWith({
String? name,
String? version,
String? identifier,
String? build,
String? buildType,
DateTime? startTime,
String? deviceAppHash,
int? appMemory,
bool? inForeground,
List<String>? viewNames,
double? textScale,
}) =>
SentryApp(
name: name ?? this.name,
version: version ?? this.version,
identifier: identifier ?? this.identifier,
build: build ?? this.build,
buildType: buildType ?? this.buildType,
startTime: startTime ?? this.startTime,
deviceAppHash: deviceAppHash ?? this.deviceAppHash,
appMemory: appMemory ?? this.appMemory,
inForeground: inForeground ?? this.inForeground,
viewNames: viewNames ?? this.viewNames,
textScale: textScale ?? this.textScale,
);
}