Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a9838a9
feat: migrates to package:web and js_interop
josh-burton May 20, 2024
9a156fb
fix: enhances comment
josh-burton Jun 4, 2024
4266881
chore: Adds changelog
josh-burton Jun 4, 2024
7dfc42e
chore: formatting
josh-burton Jun 4, 2024
2bf4b4f
fix: changes min flutter version to 3.13.0 and dart sdk 3.1.0 to be c…
josh-burton Jun 4, 2024
c4f9ba0
Merge branch 'main' into package-web
vaind Jun 20, 2024
3d07b8e
compat with dart:html & dart:web
vaind Jun 20, 2024
75014d1
fixups
vaind Jun 20, 2024
f945e9a
more fixups
vaind Jun 20, 2024
de46ce3
analyzer
vaind Jun 20, 2024
99391f4
chore: changelog entry
vaind Jun 20, 2024
31bac33
Merge branch 'main' into package-web
vaind Jun 20, 2024
80a0e2b
run dart test for all supported dart version
vaind Jun 20, 2024
e3e6c56
update web example tests
vaind Jun 20, 2024
fe1e91d
update ci
vaind Jun 20, 2024
f170986
update deps so that we can run test with old dart versions
vaind Jun 20, 2024
d05cf9d
fix ci
vaind Jun 20, 2024
78a78a2
fix web enricher test
vaind Jun 20, 2024
ac61607
fix ci
vaind Jun 20, 2024
8317804
ci fixes
vaind Jun 20, 2024
f5f9c7b
ignore pana error
vaind Jun 20, 2024
74e5f50
Merge branch 'main' into package-web
vaind Jun 20, 2024
f6e32d0
fix CI
vaind Jun 20, 2024
2c52eeb
fix ci
vaind Jun 20, 2024
f9d80f0
remove dart 2.17 build
vaind Jun 20, 2024
b19f0ad
fixes
vaind Jun 20, 2024
529e4f4
fix CI
vaind Jun 20, 2024
5750e5c
test dart2wasm
vaind Jun 20, 2024
5375cf2
cleanup
vaind Jun 20, 2024
a939163
disable dart2wasm on windows
vaind Jun 20, 2024
cec7756
fix tests for wasm
vaind Jun 20, 2024
3216f42
Merge branch 'main' into package-web
vaind Jun 25, 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
Prev Previous commit
Next Next commit
fixups
  • Loading branch information
vaind committed Jun 20, 2024
commit 75014d12bda163862ed60cbe6b8d2e4c905aef49
4 changes: 2 additions & 2 deletions dart/lib/src/environment/environment_variables.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '../platform_checker.dart';
import '_io_environment_variables.dart'
if (dart.library.js_interop) '_web_environment_variables.dart'
if (dart.library.html) '_web_environment_variables.dart' as env;
if (dart.library.html) '_web_environment_variables.dart'
if (dart.library.js_interop) '_web_environment_variables.dart' as env;

/// Reads environment variables from the system.
/// In an Flutter environment these can be set via
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../../event_processor.dart';
import '../../sentry_options.dart';
import 'io_enricher_event_processor.dart'
if (dart.library.js_interop) 'web_enricher_event_processor.dart'
if (dart.library.html) 'html_enricher_event_processor.dart';
if (dart.library.html) 'html_enricher_event_processor.dart'
if (dart.library.js_interop) 'web_enricher_event_processor.dart';

abstract class EnricherEventProcessor implements EventProcessor {
factory EnricherEventProcessor(SentryOptions options) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'dart:html' as html show window, Window;

import '../../../sentry.dart';
import 'enricher_event_processor.dart';

EnricherEventProcessor enricherEventProcessor(SentryOptions options) {
return WebEnricherEventProcessor(
html.window,
options,
);
}

class WebEnricherEventProcessor implements EnricherEventProcessor {
WebEnricherEventProcessor(
this._window,
this._options,
);

final html.Window _window;

final SentryOptions _options;

@override
SentryEvent? apply(SentryEvent event, Hint hint) {
// Web has no native integration, so no need to check for it

final contexts = event.contexts.copyWith(
device: _getDevice(event.contexts.device),
culture: _getSentryCulture(event.contexts.culture),
);

contexts['dart_context'] = _getDartContext();

return event.copyWith(
contexts: contexts,
request: _getRequest(event.request),
transaction: event.transaction ?? _window.location.pathname,
);
}

// As seen in
// https://github.com/getsentry/sentry-javascript/blob/a6f8dc26a4c7ae2146ae64995a2018c8578896a6/packages/browser/src/integrations/useragent.ts
SentryRequest _getRequest(SentryRequest? request) {
final requestHeader = request?.headers;
final header = requestHeader == null
? <String, String>{}
: Map<String, String>.from(requestHeader);

header.putIfAbsent('User-Agent', () => _window.navigator.userAgent);

final url = request?.url ?? _window.location.toString();
return (request ?? SentryRequest(url: url))
.copyWith(headers: header)
.sanitized();
}

SentryDevice _getDevice(SentryDevice? device) {
return (device ?? SentryDevice()).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(),
);
}

int? _getMemorySize() {
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory
final size = _window.navigator.deviceMemory?.toDouble();
final memoryByteSize = size != null ? size * 1024 * 1024 * 1024 : null;
return memoryByteSize?.toInt();
}

SentryOrientation? _getScreenOrientation() {
// https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation
final screenOrientation = _window.screen?.orientation;
if (screenOrientation != null) {
if (screenOrientation.type?.startsWith('portrait') ?? false) {
return SentryOrientation.portrait;
}
if (screenOrientation.type?.startsWith('landscape') ?? false) {
return SentryOrientation.landscape;
}
}
return null;
}

Map<String, dynamic> _getDartContext() {
return <String, dynamic>{
'compile_mode': _options.platformChecker.compileMode,
};
}

SentryCulture _getSentryCulture(SentryCulture? culture) {
return (culture ?? SentryCulture()).copyWith(
timezone: culture?.timezone ?? DateTime.now().timeZoneName,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'web_html.dart' if (dart.library.js_interop) 'web_web.dart' as web;
import 'package:web/web.dart' as web show window, Window, Navigator;

import '../../../sentry.dart';
import 'enricher_event_processor.dart';
Expand Down Expand Up @@ -59,10 +59,9 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
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(),
screenHeightPixels:
device?.screenHeightPixels ?? _window.screen.availHeight,
screenWidthPixels: device?.screenWidthPixels ?? _window.screen.availWidth,
screenDensity:
device?.screenDensity ?? _window.devicePixelRatio.toDouble(),
);
Expand All @@ -77,14 +76,12 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {

SentryOrientation? _getScreenOrientation() {
// https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation
final screenOrientation = _window.screen?.orientation;
if (screenOrientation != null) {
if (screenOrientation.type?.startsWith('portrait') ?? false) {
return SentryOrientation.portrait;
}
if (screenOrientation.type?.startsWith('landscape') ?? false) {
return SentryOrientation.landscape;
}
final screenOrientation = _window.screen.orientation;
if (screenOrientation.type.startsWith('portrait')) {
return SentryOrientation.portrait;
}
if (screenOrientation.type.startsWith('landscape')) {
return SentryOrientation.landscape;
}
return null;
}
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/event_processor/enricher/web_html.dart

This file was deleted.

1 change: 0 additions & 1 deletion dart/lib/src/event_processor/enricher/web_web.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../../event_processor.dart';
import '../../sentry_options.dart';
import 'io_exception_event_processor.dart'
if (dart.library.js_interop) 'web_exception_event_processor.dart'
if (dart.library.html) 'web_exception_event_processor.dart';
if (dart.library.html) 'web_exception_event_processor.dart'
if (dart.library.js_interop) 'web_exception_event_processor.dart';

abstract class ExceptionEventProcessor implements EventProcessor {
factory ExceptionEventProcessor(SentryOptions options) =>
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/origin.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'origin_io.dart'
if (dart.library.js_interop) 'origin_web.dart'
if (dart.library.html) 'origin_html.dart';
if (dart.library.html) 'origin_html.dart'
if (dart.library.js_interop) 'origin_web.dart';
4 changes: 2 additions & 2 deletions dart/lib/src/platform/platform.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '_io_platform.dart'
if (dart.library.js_interop) '_web_platform.dart'
if (dart.library.html) '_html_platform.dart' as platform;
if (dart.library.html) '_html_platform.dart'
if (dart.library.js_interop) '_web_platform.dart' as platform;

const Platform instance = platform.instance;

Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/utils/isolate_utils.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:meta/meta.dart';

import '_io_get_isolate_name.dart'
if (dart.library.js_interop) '_web_get_isolate_name.dart'
if (dart.library.html) '_web_get_isolate_name.dart' as isolate_getter;
if (dart.library.html) '_web_get_isolate_name.dart'
if (dart.library.js_interop) '_web_get_isolate_name.dart' as isolate_getter;

@internal
String? getIsolateName() => isolate_getter.getIsolateName();
4 changes: 2 additions & 2 deletions file/lib/src/sentry_file_extension.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore_for_file: invalid_use_of_internal_member

import 'dart:io'
if (dart.library.js_interop) 'dart:js_interop'
if (dart.library.html) 'dart:html';
if (dart.library.html) 'dart:html'
if (dart.library.js_interop) 'dart:js_interop';

import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'noop_connectivity_provider.dart'
if (dart.library.js_interop) 'web_connectivity_provider.dart'
if (dart.library.html) 'html_connectivity_provider.dart';
if (dart.library.html) 'html_connectivity_provider.dart'
if (dart.library.js_interop) 'web_connectivity_provider.dart';

abstract class ConnectivityProvider {
factory ConnectivityProvider() => connectivityProvider();
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/src/native/factory.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'factory_real.dart'
if (dart.library.js_interop) 'factory_web.dart'
if (dart.library.html) 'factory_web.dart';
if (dart.library.html) 'factory_web.dart'
if (dart.library.js_interop) 'factory_web.dart';
2 changes: 1 addition & 1 deletion flutter/lib/src/renderer/renderer.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:meta/meta.dart';

import 'unknown_renderer.dart'
if (dart.library.js_interop) 'web_renderer.dart'
if (dart.library.html) 'html_renderer.dart'
if (dart.library.js_interop) 'web_renderer.dart'
if (dart.library.io) 'io_renderer.dart' as implementation;

@internal
Expand Down
2 changes: 1 addition & 1 deletion hive/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:mockito/annotations.dart';
import 'package:sentry/sentry.dart';

import 'package:hive/src/box_collection/box_collection_stub.dart'
if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.html) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.io) 'package:hive/src/box_collection/box_collection.dart'
as impl;

Expand Down
2 changes: 1 addition & 1 deletion hive/test/mocks/mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import 'package:hive/src/box_collection/box_collection_stub.dart' as stub;

// ignore: implementation_imports
import 'package:hive/src/box_collection/box_collection_stub.dart'
if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.html) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart'
if (dart.library.io) 'package:hive/src/box_collection/box_collection.dart'
as impl;

Expand Down