-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
flutter/lib/src/integrations/connectivity/connectivity_integration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:meta/meta.dart'; | ||
import '../../../sentry_flutter.dart'; | ||
import 'connectivity_provider.dart'; | ||
|
||
class ConnectivityIntegration extends Integration<SentryFlutterOptions> { | ||
Hub? _hub; | ||
ConnectivityProvider? _connectivityProvider; | ||
|
||
@override | ||
void call(Hub hub, SentryFlutterOptions options) { | ||
_hub = hub; | ||
_connectivityProvider = ConnectivityProvider(); | ||
_connectivityProvider?.listen((connectivity) { | ||
addBreadcrumb(connectivity); | ||
}); | ||
options.sdk.addIntegration('connectivityIntegration'); | ||
} | ||
|
||
@override | ||
void close() { | ||
_hub = null; | ||
_connectivityProvider?.cancel(); | ||
} | ||
|
||
@internal | ||
@visibleForTesting | ||
void addBreadcrumb(String connectivity) { | ||
_hub?.addBreadcrumb( | ||
Breadcrumb( | ||
category: 'device.connectivity', | ||
level: SentryLevel.info, | ||
type: 'connectivity', | ||
data: {'connectivity': connectivity}), | ||
); | ||
} | ||
} | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
flutter/lib/src/integrations/connectivity/connectivity_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
import 'noop_connectivity_provider.dart' | ||
if (dart.library.html) 'web_connectivity_provider.dart'; | ||
|
||
abstract class ConnectivityProvider { | ||
factory ConnectivityProvider() => connectivityProvider(); | ||
|
||
void listen(void Function(String connectivity) onChange); | ||
void cancel(); | ||
} |
19 changes: 19 additions & 0 deletions
19
flutter/lib/src/integrations/connectivity/noop_connectivity_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import 'connectivity_provider.dart'; | ||
|
||
ConnectivityProvider connectivityProvider() { | ||
return NoOpConnectivityProvider(); | ||
} | ||
|
||
class NoOpConnectivityProvider implements ConnectivityProvider { | ||
|
||
@override | ||
void listen(void Function(String connectivity) onChange) { | ||
// NoOp | ||
} | ||
|
||
@override | ||
void cancel() { | ||
// NoOp | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters