Skip to content

Feature: Initial support for Flutter on Desktop #389

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

Merged
merged 41 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
42a2b50
better platform checks compatibility
ueman Mar 28, 2021
62d5b63
MacOS
ueman Mar 28, 2021
7ee6121
always use release integration
ueman Mar 28, 2021
c27711c
macos foo
ueman Mar 28, 2021
feb030f
Build MacOS on CI
ueman Mar 29, 2021
d690eeb
CI foo
ueman Mar 29, 2021
250716b
set flag to enable desktop builds
ueman Mar 29, 2021
6e9879c
Merge remote-tracking branch 'origin/main' into feature/support-desktop
ueman Mar 30, 2021
1a76ef0
Small clean up
ueman Mar 30, 2021
0c39c89
Remove dummy implementation
ueman Mar 30, 2021
3df51f7
MacOS native integration
ueman Mar 30, 2021
3f01c94
More native integration
ueman Mar 30, 2021
92d5e91
remove platform dependency
ueman Mar 30, 2021
9927299
Merge branch 'main' into feature/support-desktop
ueman Apr 6, 2021
05bc59f
Code cleanup
ueman Apr 6, 2021
7f8b910
Symlink iOS and MacOS to share native code
ueman Apr 6, 2021
5ed6827
Merge remote-tracking branch 'origin/main' into feature/support-desktop
ueman Apr 6, 2021
3b85fc0
Add changelog entry
ueman Apr 6, 2021
06fa92f
Merge branch 'main' into feature/support-desktop
marandaneto Apr 7, 2021
e350e31
--release is the default
ueman Apr 12, 2021
639d15b
PlatformChecker instead of SentryOptions
ueman Apr 12, 2021
4d15b2c
improve macos example
ueman Apr 12, 2021
2be713f
Improve Cocoa app start notification handling
ueman Apr 12, 2021
40056e1
Make isWeb more testable
ueman Apr 12, 2021
6f88e4a
make swift lint happy
ueman Apr 12, 2021
07cc9c0
Add Fuchsia detection
ueman Apr 12, 2021
40beabc
used wrong linter comment, now it's fixed
ueman Apr 12, 2021
0df988c
remove note which is not needed anymore
ueman Apr 12, 2021
f988194
fixed test failure
ueman Apr 12, 2021
5751f9e
fix formatting
ueman Apr 12, 2021
e68dee1
Merge branch 'main' of github.com:getsentry/sentry-dart into feature/…
ueman Apr 13, 2021
52bfef4
Add better comment
ueman Apr 13, 2021
e0bc042
Improve 'isWeb' checks
ueman Apr 13, 2021
b08f4bb
fix syntax error
ueman Apr 13, 2021
b44278c
Update native plugin classes
ueman Apr 13, 2021
d5e1123
use isweb directly
ueman Apr 13, 2021
f4ba0fc
feat: Windows Support (#407)
bruno-garcia Apr 13, 2021
a26d403
Feat: Support Linux (#402)
ueman Apr 14, 2021
3f6455f
Add SentryFlutterPluginApple.swift
ueman Apr 19, 2021
a874f04
Merge remote-tracking branch 'origin/main' into feature/support-desktop
ueman Apr 19, 2021
50ab07a
Fix: Trim Unicode NULL character for Windows support (#420)
ueman Apr 20, 2021
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
38 changes: 35 additions & 3 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ jobs:
# max-parallel: 4
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
target: ['ios', 'android', 'web']
target: ['ios', 'android', 'web', 'macos', 'linux', 'windows']
channel: ['stable', 'beta']
exclude:
- os: ubuntu-latest
target: ios
- os: ubuntu-latest
target: macos
- os: ubuntu-latest
target: windows
- os: macos-latest
target: windows
- os: windows-latest
target: ios
- os: windows-latest
target: macos
- os: windows-latest
target: linux
# macos-latest is taking hours due to limited resources
- os: macos-latest
target: android
- os: macos-latest
target: web
- os: macos-latest
target: linux

steps:
- uses: actions/checkout@v2
Expand All @@ -37,6 +49,14 @@ jobs:
distribution: 'adopt'
java-version: '8'

# Install required dependencies for Flutter on Linux on Ubuntu
- name: 'Setup Linux'
run: |
sudo apt update
sudo apt install -y cmake dbus libblkid-dev libgtk-3-dev liblzma-dev ninja-build pkg-config xvfb
sudo apt install -y network-manager upower
if: matrix.os == 'ubuntu-latest'

- uses: subosito/flutter-action@v1
with:
channel: ${{ matrix.channel }}
Expand All @@ -59,19 +79,31 @@ jobs:
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
flutter config --enable-windows-desktop
flutter config --enable-macos-desktop
flutter config --enable-linux-desktop
cd flutter/example
TARGET=${{ matrix.target }}
flutter pub get
case $TARGET in
ios)
flutter build ios --release --no-codesign
flutter build ios --no-codesign
;;
macos)
flutter build macos
;;
android)
flutter build appbundle --release
flutter build appbundle
;;
web)
flutter build web
;;
linux)
flutter build linux
;;
windows)
flutter build windows
;;
esac

analyze:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Unreleased

* Fix: `Sentry.close()` closes native SDK integrations (#388)
* Feat: Support for macOS (#389)
* Feat: Support for Linux (#402)
* Feat: Support for Windows (#407)
* Fix: Mark `Sentry.currentHub` as deprecated (#406)
* Fix: Use name from pubspec.yaml for release if package id is not available (#411)
* Feat: `SentryHttpClient` tracks the duration which a request takes and logs failed requests (#414)
* Fix: Trim `\u0000` from Windows package info (#420)

# 5.0.0

Expand Down
1 change: 1 addition & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'src/default_integrations.dart';
export 'src/hub.dart';
// useful for tests
export 'src/hub_adapter.dart';
export 'src/platform_checker.dart';
export 'src/noop_isolate_error_integration.dart'
if (dart.library.io) 'src/isolate_error_integration.dart';
export 'src/protocol.dart';
Expand Down
20 changes: 20 additions & 0 deletions dart/lib/src/platform/_io_platform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:io' as io show Platform;

import 'platform.dart';

const Platform instance = IOPlatform();

/// [Platform] implementation that delegates directly to `dart:io`.
class IOPlatform extends Platform {
/// Creates a new [IOPlatform].
const IOPlatform();

@override
String get operatingSystem => io.Platform.operatingSystem;

@override
String get operatingSystemVersion => io.Platform.operatingSystemVersion;

@override
String get localHostname => io.Platform.localHostname;
}
51 changes: 51 additions & 0 deletions dart/lib/src/platform/_web_platform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dart:html' as html;
import 'platform.dart';

const Platform instance = WebPlatform();

/// [Platform] implementation that delegates to `dart:html`.
class WebPlatform extends Platform {
/// Creates a new [Platform].
const WebPlatform();

@override
String get operatingSystem => _browserPlatform();

@override
String get operatingSystemVersion => 'unknown';

@override
String get localHostname => html.window.location.hostname ?? 'unknown';

String _browserPlatform() {
final navigatorPlatform =
html.window.navigator.platform?.toLowerCase() ?? '';
if (navigatorPlatform.startsWith('mac')) {
return 'macos';
}
if (navigatorPlatform.startsWith('win')) {
return 'windows';
}
if (navigatorPlatform.contains('iphone') ||
navigatorPlatform.contains('ipad') ||
navigatorPlatform.contains('ipod')) {
return 'ios';
}
if (navigatorPlatform.contains('android')) {
return 'android';
}
if (navigatorPlatform.contains('fuchsia')) {
return 'fuchsia';
}

// Since some phones can report a window.navigator.platform as Linux, fall
// back to use CSS to disambiguate Android vs Linux desktop. If the CSS
// indicates that a device has a "fine pointer" (mouse) as the primary
// pointing device, then we'll assume desktop linux, and otherwise we'll
// assume Android.
if (html.window.matchMedia('only screen and (pointer: fine)').matches) {
return 'linux';
}
return 'android';
}
}
36 changes: 36 additions & 0 deletions dart/lib/src/platform/platform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import '_io_platform.dart' if (dart.library.html) '_web_platform.dart'
as platform;

const Platform instance = platform.instance;

abstract class Platform {
const Platform();

/// A string (`linux`, `macos`, `windows`, `android`, `ios`, or `fuchsia`)
/// representing the operating system.
String get operatingSystem;

/// A string representing the version of the operating system or platform.
String get operatingSystemVersion;

/// Get the local hostname for the system.
String get localHostname;

/// True if the operating system is Linux.
bool get isLinux => (operatingSystem == 'linux');

/// True if the operating system is OS X.
bool get isMacOS => (operatingSystem == 'macos');

/// True if the operating system is Windows.
bool get isWindows => (operatingSystem == 'windows');

/// True if the operating system is Android.
bool get isAndroid => (operatingSystem == 'android');

/// True if the operating system is iOS.
bool get isIOS => (operatingSystem == 'ios');

/// True if the operating system is Fuchsia
bool get isFuchsia => (operatingSystem == 'fuchsia');
}
26 changes: 25 additions & 1 deletion dart/lib/src/platform_checker.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import 'platform/platform.dart';

/// Helper to check in which enviroment the library is running.
/// The envirment checks (release/debug/profile) are mutually exclusive.
class PlatformChecker {
const PlatformChecker();
PlatformChecker({
this.platform = instance,
this.isWeb = identical(0, 0.0),
});

/// Check if running in release/production environment
bool isReleaseMode() {
Expand All @@ -17,4 +22,23 @@ class PlatformChecker {
bool isProfileMode() {
return const bool.fromEnvironment('dart.vm.profile', defaultValue: false);
}

final bool isWeb;

/// Indicates wether a native integration is available.
bool get hasNativeIntegration {
if (isWeb) {
return false;
}
// We need to check the platform after we checked for web, because
// the OS checks return true when the browser runs on the checked platform.
// Example: platform.isAndroid return true if the browser is used on an
// Android device.
if (platform.isAndroid || platform.isIOS || platform.isMacOS) {
return true;
}
return false;
}

final Platform platform;
}
3 changes: 1 addition & 2 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'noop_hub.dart';
import 'protocol.dart';
import 'sentry_client.dart';
import 'sentry_options.dart';
import 'utils.dart';
import 'integration.dart';

/// Configuration options callback
Expand Down Expand Up @@ -65,7 +64,7 @@ class Sentry {
_setEnvironmentVariables(options);

// Throws when running on the browser
if (!isWeb) {
if (!options.platformChecker.isWeb) {
// catch any errors that may occur within the entry function, main()
// in the ‘root zone’ where all Dart programs start
options.addIntegrationByIndex(0, IsolateErrorIntegration());
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SentryClient {
environment: event.environment ?? _options.environment,
release: event.release ?? _options.release,
sdk: event.sdk ?? _options.sdk,
platform: event.platform ?? sdkPlatform,
platform: event.platform ?? sdkPlatform(_options.platformChecker.isWeb),
);

event = _applyDefaultPii(event);
Expand Down
3 changes: 2 additions & 1 deletion dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class SentryOptions {
String? serverName;

/// Sdk object that contains the Sentry Client Name and its version
SdkVersion sdk = SdkVersion(name: sdkName, version: sdkVersion);
late SdkVersion sdk;

/// When enabled, stack traces are automatically attached to all messages logged.
/// Stack traces are always attached to exceptions;
Expand Down Expand Up @@ -161,6 +161,7 @@ class SentryOptions {
bool sendDefaultPii = false;

SentryOptions({this.dsn}) {
sdk = SdkVersion(name: sdkName(platformChecker.isWeb), version: sdkVersion);
sdk.addPackage('pub:sentry', sdkVersion);
}

Expand Down
6 changes: 3 additions & 3 deletions dart/lib/src/transport/http_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:http/http.dart';
import '../noop_client.dart';
import '../protocol.dart';
import '../sentry_options.dart';
import '../utils.dart';
import 'noop_encode.dart' if (dart.library.io) 'encode.dart';
import 'transport.dart';

Expand All @@ -30,7 +29,8 @@ class HttpTransport implements Transport {

HttpTransport._(this._options)
: _dsn = Dsn.parse(_options.dsn!),
_headers = _buildHeaders(_options.sdk.identifier) {
_headers = _buildHeaders(
_options.platformChecker.isWeb, _options.sdk.identifier) {
_credentialBuilder = _CredentialBuilder(
_dsn,
_options.sdk.identifier,
Expand Down Expand Up @@ -138,7 +138,7 @@ class _CredentialBuilder {
}
}

Map<String, String> _buildHeaders(String sdkIdentifier) {
Map<String, String> _buildHeaders(bool isWeb, String sdkIdentifier) {
final headers = {'Content-Type': 'application/json'};
// NOTE(lejard_h) overriding user agent on VM and Flutter not sure why
// for web it use browser user agent
Expand Down
3 changes: 0 additions & 3 deletions dart/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ String formatDateAsIso8601WithMillisPrecision(DateTime date) {
// appends Z because the substring removed it
return '${iso}Z';
}

/// helper to detect a browser context
const isWeb = identical(0, 0.0);
6 changes: 2 additions & 4 deletions dart/lib/src/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
/// This library contains Sentry.io SDK constants used by this package.
library version;

import 'utils.dart';

/// The SDK version reported to Sentry.io in the submitted events.
const String sdkVersion = '5.0.1';

String get sdkName => isWeb ? _browserSdkName : _ioSdkName;
String sdkName(bool isWeb) => isWeb ? _browserSdkName : _ioSdkName;

/// The default SDK name reported to Sentry.io in the submitted events.
const String _ioSdkName = 'sentry.dart';
Expand All @@ -24,7 +22,7 @@ const String _browserSdkName = 'sentry.dart.browser';
/// The name of the SDK platform reported to Sentry.io in the submitted events.
///
/// Used for IO version.
String get sdkPlatform => isWeb ? _browserPlatform : _ioSdkPlatform;
String sdkPlatform(bool isWeb) => isWeb ? _browserPlatform : _ioSdkPlatform;

/// The name of the SDK platform reported to Sentry.io in the submitted events.
///
Expand Down
Loading