Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to usage of PlatformView #2249

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b8bd099
add fvm to gitignore for simpler switch between flutter versions
martinhaintz Aug 26, 2024
f416919
removed deprecated window.devicePixelRatio from screenshot_event_proc…
martinhaintz Aug 26, 2024
caf888c
migrate from SingleFlutterWindows to FlutterView
martinhaintz Aug 27, 2024
e449941
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Aug 27, 2024
1396dfb
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Aug 28, 2024
80bbe0e
update feedback package
martinhaintz Sep 2, 2024
eea494e
allow list of navigatorKeys in sentryOptions
martinhaintz Sep 2, 2024
98bc647
adapt example app to handle multiple navigatorKeys
martinhaintz Sep 2, 2024
2886956
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Sep 2, 2024
7d14655
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Sep 3, 2024
14da1a8
add multiple globalKeys for sentry widget and sentry screenshot widget
martinhaintz Sep 3, 2024
91b7161
revert back to sentryWidgetGlobalKey and remove sentryWidget and navi…
martinhaintz Sep 4, 2024
7f9b83f
fix some errors with non existing variables.
martinhaintz Sep 4, 2024
de86dd0
fix unitTests
martinhaintz Sep 6, 2024
4e69486
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Sep 6, 2024
1b75753
remove `web: any` dependency
martinhaintz Sep 9, 2024
00bff23
fix dio mock for sentryDevice
martinhaintz Sep 9, 2024
aaa812b
fix sentryDevice dart tests
martinhaintz Sep 9, 2024
221dadd
fix sentryDevice in dart example app
martinhaintz Sep 9, 2024
cb75ff1
fix null check error
martinhaintz Sep 9, 2024
6883e29
Merge branch 'main' into fix/flutter-multiview-support
martinhaintz Sep 9, 2024
1d82e56
remove unused files and remove unnecessary elements in index.html
martinhaintz Sep 10, 2024
3fb08ac
Merge branch 'fix/flutter-multiview-support' of https://github.com/ge…
martinhaintz Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dart/example/bin/event_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ final event = SentryEvent(
modelId: 'LRX22G',
arch: 'armeabi-v7a',
batteryLevel: 99,
orientation: SentryOrientation.landscape,
manufacturer: 'samsung',
brand: 'samsung',
screenDensity: 2.1,
screenDpi: 320,
views: [
SentryView(
0,
screenDensity: 2.1,
screenDpi: 320,
orientation: SentryOrientation.landscape,
)
],
online: true,
charging: true,
lowMemory: true,
Expand Down
11 changes: 8 additions & 3 deletions dart/example_web/web/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ final event = SentryEvent(
modelId: 'LRX22G',
arch: 'armeabi-v7a',
batteryLevel: 99,
orientation: SentryOrientation.landscape,
manufacturer: 'samsung',
brand: 'samsung',
screenDensity: 2.1,
screenDpi: 320,
views: [
SentryView(
0,
orientation: SentryOrientation.landscape,
screenDensity: 2.1,
screenDpi: 320,
)
],
online: true,
charging: true,
lowMemory: true,
Expand Down
11 changes: 8 additions & 3 deletions dart/example_web_legacy/web/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ final event = SentryEvent(
modelId: 'LRX22G',
arch: 'armeabi-v7a',
batteryLevel: 99,
orientation: SentryOrientation.landscape,
manufacturer: 'samsung',
brand: 'samsung',
screenDensity: 2.1,
screenDpi: 320,
views: [
SentryView(
0,
orientation: SentryOrientation.landscape,
screenDensity: 2.1,
screenDpi: 320,
)
],
online: true,
charging: true,
lowMemory: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,25 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
}

SentryDevice _getDevice(SentryDevice? device) {
return (device ?? SentryDevice()).copyWith(
final currentDevice = device ?? SentryDevice();
final currentView = currentDevice.views.isNotEmpty
? currentDevice.views.first
: SentryView(0);
return currentDevice.copyWith(
online: device?.online ?? _window.navigator.onLine,
memorySize: device?.memorySize ?? _getMemorySize(),
orientation: device?.orientation ?? _getScreenOrientation(),
screenHeightPixels: device?.screenHeightPixels ??
_window.screen?.available.height.toInt(),
screenWidthPixels:
device?.screenWidthPixels ?? _window.screen?.available.width.toInt(),
screenDensity:
device?.screenDensity ?? _window.devicePixelRatio.toDouble(),
views: [
currentView.copyWith(
orientation:
device?.views.first.orientation ?? _getScreenOrientation(),
screenHeightPixels: device?.views.first.screenHeightPixels ??
_window.screen?.available.height.toInt(),
screenWidthPixels: device?.views.first.screenWidthPixels ??
_window.screen?.available.width.toInt(),
screenDensity: device?.views.first.screenDensity ??
_window.devicePixelRatio.toDouble(),
)
],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,25 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
}

SentryDevice _getDevice(SentryDevice? device) {
return (device ?? SentryDevice()).copyWith(
final currentDevice = device ?? SentryDevice();
final currentView = currentDevice.views.isNotEmpty
? currentDevice.views.first
: SentryView(0);
return currentDevice.copyWith(
online: device?.online ?? _window.navigator.onLine,
memorySize: device?.memorySize ?? _getMemorySize(),
orientation: device?.orientation ?? _getScreenOrientation(),
screenHeightPixels:
device?.screenHeightPixels ?? _window.screen.availHeight,
screenWidthPixels: device?.screenWidthPixels ?? _window.screen.availWidth,
screenDensity:
device?.screenDensity ?? _window.devicePixelRatio.toDouble(),
views: [
currentView.copyWith(
orientation:
device?.views.first.orientation ?? _getScreenOrientation(),
screenHeightPixels: device?.views.first.screenHeightPixels ??
_window.screen.availHeight,
screenWidthPixels: device?.views.first.screenWidthPixels ??
_window.screen.availWidth,
screenDensity: device?.views.first.screenDensity ??
_window.devicePixelRatio.toDouble(),
)
],
);
}

Expand Down
154 changes: 105 additions & 49 deletions dart/lib/src/protocol/sentry_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,98 @@
/// If a device is on portrait or landscape mode
enum SentryOrientation { portrait, landscape }

class SentryView {
/// The id of this view. For single view application it is always 1.
final int viewId;

/// Defines the orientation of a device.
final SentryOrientation? orientation;

/// The screen height in pixels. (e.g.: `600`, `1080`).
final int? screenHeightPixels;

/// The screen width in pixels. (e.g.: `800`, `1920`).
final int? screenWidthPixels;

/// A floating point denoting the screen density.
final double? screenDensity;

/// A decimal value reflecting the DPI (dots-per-inch) density.
final int? screenDpi;

@internal
final Map<String, dynamic>? unknown;

SentryView(
this.viewId, {
this.orientation,
this.screenHeightPixels,
this.screenWidthPixels,
this.screenDensity,
this.screenDpi,
this.unknown,
});

SentryView clone() => SentryView(
viewId,
orientation: orientation,
screenHeightPixels: screenHeightPixels,
screenWidthPixels: screenWidthPixels,
screenDensity: screenDensity,
screenDpi: screenDpi,
unknown: unknown,

Check warning on line 47 in dart/lib/src/protocol/sentry_device.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/protocol/sentry_device.dart#L40-L47

Added lines #L40 - L47 were not covered by tests
);

SentryView copyWith({
int? viewId,
SentryOrientation? orientation,
int? screenHeightPixels,
int? screenWidthPixels,
double? screenDensity,
int? screenDpi,
}) =>
SentryView(
viewId ?? this.viewId,
orientation: orientation ?? this.orientation,
screenHeightPixels: screenHeightPixels ?? this.screenHeightPixels,
screenWidthPixels: screenWidthPixels ?? this.screenWidthPixels,
screenDensity: screenDensity ?? this.screenDensity,
screenDpi: screenDpi ?? this.screenDpi,

Check warning on line 64 in dart/lib/src/protocol/sentry_device.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/protocol/sentry_device.dart#L60-L64

Added lines #L60 - L64 were not covered by tests
unknown: unknown,
);

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
...?unknown,
'view_id': viewId,
if (orientation != null) 'orientation': orientation!.name,
if (screenWidthPixels != null) 'screen_width_pixels': screenWidthPixels,
if (screenHeightPixels != null)
'screen_height_pixels': screenHeightPixels,
if (screenDensity != null) 'screen_density': screenDensity,
if (screenDpi != null) 'screen_dpi': screenDpi,
};
}

factory SentryView.fromJson(Map<String, dynamic> data) {
final json = AccessAwareMap(data);
return SentryView(
json['view_id'],
orientation: json['orientation'] == 'portrait'
? SentryOrientation.portrait
: json['orientation'] == 'landscape'
? SentryOrientation.landscape
: null,
screenHeightPixels: json['screen_height_pixels']?.toInt(),
screenWidthPixels: json['screen_width_pixels']?.toInt(),
screenDensity: json['screen_density'],
screenDpi: json['screen_dpi'],
unknown: json.notAccessed(),
);
}
}

/// This describes the device that caused the event.
@immutable
class SentryDevice {
Expand All @@ -17,13 +109,9 @@
this.modelId,
this.arch,
this.batteryLevel,
this.orientation,
this.manufacturer,
this.brand,
this.screenHeightPixels,
this.screenWidthPixels,
this.screenDensity,
this.screenDpi,
this.views = const [],
this.online,
this.charging,
this.lowMemory,
Expand Down Expand Up @@ -75,26 +163,14 @@
/// defining the battery level (in the range 0-100).
final double? batteryLevel;

/// Defines the orientation of a device.
final SentryOrientation? orientation;

/// The manufacturer of the device.
final String? manufacturer;

/// The brand of the device.
final String? brand;

/// The screen height in pixels. (e.g.: `600`, `1080`).
final int? screenHeightPixels;

/// The screen width in pixels. (e.g.: `800`, `1920`).
final int? screenWidthPixels;

/// A floating point denoting the screen density.
final double? screenDensity;

/// A decimal value reflecting the DPI (dots-per-inch) density.
final int? screenDpi;
/// The collection of views, which are rendered and shown to the user
final List<SentryView> views;

/// Whether the device was online or not.
final bool? online;
Expand Down Expand Up @@ -188,17 +264,13 @@
batteryLevel:
(json['battery_level'] is num ? json['battery_level'] as num : null)
?.toDouble(),
orientation: json['orientation'] == 'portrait'
? SentryOrientation.portrait
: json['orientation'] == 'landscape'
? SentryOrientation.landscape
: null,
manufacturer: json['manufacturer'],
brand: json['brand'],
screenHeightPixels: json['screen_height_pixels']?.toInt(),
screenWidthPixels: json['screen_width_pixels']?.toInt(),
screenDensity: json['screen_density'],
screenDpi: json['screen_dpi'],
views: json['views'] == null
? []
: (json['views'] as List)
.map((view) => SentryView.fromJson(view))
.toList(),
online: json['online'],
charging: json['charging'],
lowMemory: json['low_memory'],
Expand Down Expand Up @@ -238,14 +310,10 @@
if (modelId != null) 'model_id': modelId,
if (arch != null) 'arch': arch,
if (batteryLevel != null) 'battery_level': batteryLevel,
if (orientation != null) 'orientation': orientation!.name,
if (manufacturer != null) 'manufacturer': manufacturer,
if (brand != null) 'brand': brand,
if (screenWidthPixels != null) 'screen_width_pixels': screenWidthPixels,
if (screenHeightPixels != null)
'screen_height_pixels': screenHeightPixels,
if (screenDensity != null) 'screen_density': screenDensity,
if (screenDpi != null) 'screen_dpi': screenDpi,
if (views.isNotEmpty)
'views': views.map((view) => view.toJson()).toList(),
if (online != null) 'online': online,
if (charging != null) 'charging': charging,
if (lowMemory != null) 'low_memory': lowMemory,
Expand Down Expand Up @@ -284,13 +352,9 @@
modelId: modelId,
arch: arch,
batteryLevel: batteryLevel,
orientation: orientation,
manufacturer: manufacturer,
brand: brand,
screenHeightPixels: screenHeightPixels,
screenWidthPixels: screenWidthPixels,
screenDensity: screenDensity,
screenDpi: screenDpi,
views: views,
online: online,
charging: charging,
lowMemory: lowMemory,
Expand Down Expand Up @@ -324,13 +388,9 @@
String? modelId,
String? arch,
double? batteryLevel,
SentryOrientation? orientation,
String? manufacturer,
String? brand,
int? screenHeightPixels,
int? screenWidthPixels,
double? screenDensity,
int? screenDpi,
List<SentryView>? views,
bool? online,
bool? charging,
bool? lowMemory,
Expand Down Expand Up @@ -362,13 +422,9 @@
modelId: modelId ?? this.modelId,
arch: arch ?? this.arch,
batteryLevel: batteryLevel ?? this.batteryLevel,
orientation: orientation ?? this.orientation,
manufacturer: manufacturer ?? this.manufacturer,
brand: brand ?? this.brand,
screenHeightPixels: screenHeightPixels ?? this.screenHeightPixels,
screenWidthPixels: screenWidthPixels ?? this.screenWidthPixels,
screenDensity: screenDensity ?? this.screenDensity,
screenDpi: screenDpi ?? this.screenDpi,
views: views ?? this.views,
online: online ?? this.online,
charging: charging ?? this.charging,
lowMemory: lowMemory ?? this.lowMemory,
Expand Down
20 changes: 14 additions & 6 deletions dart/test/contexts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ void main() {
modelId: 'testModelId',
arch: 'testArch',
batteryLevel: 23,
orientation: SentryOrientation.landscape,
manufacturer: 'testOEM',
brand: 'testBrand',
screenDensity: 99.1,
screenDpi: 100,
views: [
SentryView(0,
orientation: SentryOrientation.landscape,
screenDensity: 99.1,
screenDpi: 100),
],
online: false,
charging: true,
lowMemory: false,
Expand Down Expand Up @@ -66,11 +69,16 @@ void main() {
'model_id': 'testModelId',
'arch': 'testArch',
'battery_level': 23.0,
'orientation': 'landscape',
'manufacturer': 'testOEM',
'brand': 'testBrand',
'screen_density': 99.1,
'screen_dpi': 100,
'views': [
{
'view_id': 0,
'orientation': 'landscape',
'screen_density': 99.1,
'screen_dpi': 100,
},
],
'online': false,
'charging': true,
'low_memory': false,
Expand Down
Loading
Loading