diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 63f50d922e..0ab9c9524a 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -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 @@ -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 }} @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de4ecdb7e..ddc6f8c42b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dart/lib/sentry.dart b/dart/lib/sentry.dart index 5b057ac928..156a9d0752 100644 --- a/dart/lib/sentry.dart +++ b/dart/lib/sentry.dart @@ -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'; diff --git a/dart/lib/src/platform/_io_platform.dart b/dart/lib/src/platform/_io_platform.dart new file mode 100644 index 0000000000..ecc9c2035c --- /dev/null +++ b/dart/lib/src/platform/_io_platform.dart @@ -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; +} diff --git a/dart/lib/src/platform/_web_platform.dart b/dart/lib/src/platform/_web_platform.dart new file mode 100644 index 0000000000..d3fa84eed9 --- /dev/null +++ b/dart/lib/src/platform/_web_platform.dart @@ -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'; + } +} diff --git a/dart/lib/src/platform/platform.dart b/dart/lib/src/platform/platform.dart new file mode 100644 index 0000000000..8f6d0760e8 --- /dev/null +++ b/dart/lib/src/platform/platform.dart @@ -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'); +} diff --git a/dart/lib/src/platform_checker.dart b/dart/lib/src/platform_checker.dart index 8ae8b51117..a7cb783f5c 100644 --- a/dart/lib/src/platform_checker.dart +++ b/dart/lib/src/platform_checker.dart @@ -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() { @@ -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; } diff --git a/dart/lib/src/sentry.dart b/dart/lib/src/sentry.dart index e164755f91..d8bd364a65 100644 --- a/dart/lib/src/sentry.dart +++ b/dart/lib/src/sentry.dart @@ -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 @@ -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()); diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index f5637043fe..fb20d6ad2f 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -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); diff --git a/dart/lib/src/sentry_options.dart b/dart/lib/src/sentry_options.dart index 6b62c32a8f..41bbb745c4 100644 --- a/dart/lib/src/sentry_options.dart +++ b/dart/lib/src/sentry_options.dart @@ -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; @@ -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); } diff --git a/dart/lib/src/transport/http_transport.dart b/dart/lib/src/transport/http_transport.dart index b21f0fb67c..bb5b05b8e4 100644 --- a/dart/lib/src/transport/http_transport.dart +++ b/dart/lib/src/transport/http_transport.dart @@ -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'; @@ -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, @@ -138,7 +138,7 @@ class _CredentialBuilder { } } -Map _buildHeaders(String sdkIdentifier) { +Map _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 diff --git a/dart/lib/src/utils.dart b/dart/lib/src/utils.dart index 622f24ac3a..432a926e34 100644 --- a/dart/lib/src/utils.dart +++ b/dart/lib/src/utils.dart @@ -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); diff --git a/dart/lib/src/version.dart b/dart/lib/src/version.dart index 08d1b041ec..8b3688ccd0 100644 --- a/dart/lib/src/version.dart +++ b/dart/lib/src/version.dart @@ -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'; @@ -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. /// diff --git a/dart/test/sentry_event_test.dart b/dart/test/sentry_event_test.dart index 9c168ab2d7..51847556f7 100644 --- a/dart/test/sentry_event_test.dart +++ b/dart/test/sentry_event_test.dart @@ -5,7 +5,6 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/protocol/sentry_request.dart'; import 'package:sentry/src/sentry_stack_trace_factory.dart'; -import 'package:sentry/src/utils.dart'; import 'package:sentry/src/version.dart'; import 'package:test/test.dart'; @@ -30,10 +29,12 @@ void main() { ); }); test('$SdkVersion serializes', () { + var platformChecker = PlatformChecker(); + final event = SentryEvent( eventId: SentryId.empty(), timestamp: DateTime.utc(2019), - platform: sdkPlatform, + platform: sdkPlatform(platformChecker.isWeb), sdk: SdkVersion( name: 'sentry.dart.flutter', version: '4.3.2', @@ -44,7 +45,7 @@ void main() { ), ); expect(event.toJson(), { - 'platform': isWeb ? 'javascript' : 'other', + 'platform': platformChecker.isWeb ? 'javascript' : 'other', 'event_id': '00000000000000000000000000000000', 'timestamp': '2019-01-01T00:00:00.000Z', 'sdk': { @@ -58,6 +59,8 @@ void main() { }); }); test('serializes to JSON', () { + var platformChecker = PlatformChecker(); + final timestamp = DateTime.utc(2019); final user = SentryUser( id: 'user_id', @@ -85,7 +88,7 @@ void main() { SentryEvent( eventId: SentryId.empty(), timestamp: timestamp, - platform: sdkPlatform, + platform: sdkPlatform(platformChecker.isWeb), message: SentryMessage( 'test-message 1 2', template: 'test-message %d %d', @@ -128,7 +131,7 @@ void main() { ), ).toJson(), { - 'platform': isWeb ? 'javascript' : 'other', + 'platform': platformChecker.isWeb ? 'javascript' : 'other', 'event_id': '00000000000000000000000000000000', 'timestamp': '2019-01-01T00:00:00.000Z', 'message': { diff --git a/dart/test/test_utils.dart b/dart/test/test_utils.dart index d4e987ac85..cb000f9b11 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -98,7 +98,7 @@ Future testCaptureException( fakeClockProvider, compressPayload: compressPayload, withUserAgent: !isWeb, - sdkName: sdkName, + sdkName: sdkName(isWeb), ); Map? data; @@ -142,7 +142,7 @@ Future testCaptureException( expect(data['platform'], 'javascript'); expect(data['sdk'], { 'version': sdkVersion, - 'name': sdkName, + 'name': sdkName(isWeb), 'packages': [ {'name': 'pub:sentry', 'version': sdkVersion} ] @@ -289,7 +289,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { withUserAgent: !isWeb, compressPayload: false, withSecret: false, - sdkName: sdkName, + sdkName: sdkName(isWeb), ); client.close(); diff --git a/flutter/example/lib/main.dart b/flutter/example/lib/main.dart index e6f80a813c..3902cab9f9 100644 --- a/flutter/example/lib/main.dart +++ b/flutter/example/lib/main.dart @@ -17,7 +17,7 @@ Future main() async { // use breadcrumb tracking of WidgetsBindingObserver // options.useFlutterBreadcrumbTracking(); // use breadcrumb tracking of platform Sentry SDKs - options.useNativeBreadcrumbTracking(); + // options.useNativeBreadcrumbTracking(); }, // Init your App. appRunner: () => runApp(MyApp()), @@ -113,7 +113,8 @@ class MainScaffold extends StatelessWidget { child: const Text('Dart: Web request'), onPressed: () => makeWebRequest(context), ), - if (UniversalPlatform.isIOS) const CocoaExample(), + if (UniversalPlatform.isIOS || UniversalPlatform.isMacOS) + const CocoaExample(), if (UniversalPlatform.isAndroid) const AndroidExample(), ], ), diff --git a/flutter/example/linux/.gitignore b/flutter/example/linux/.gitignore new file mode 100644 index 0000000000..82b8a4eb8e --- /dev/null +++ b/flutter/example/linux/.gitignore @@ -0,0 +1,2 @@ +flutter/ephemeral +flutter/generated_plugin* diff --git a/flutter/example/linux/CMakeLists.txt b/flutter/example/linux/CMakeLists.txt new file mode 100644 index 0000000000..19559cb5ab --- /dev/null +++ b/flutter/example/linux/CMakeLists.txt @@ -0,0 +1,106 @@ +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +set(BINARY_NAME "sentry_flutter_example") +set(APPLICATION_ID "io.sentry.flutter.sentry_flutter") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Application build +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) +apply_standard_settings(${BINARY_NAME}) +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) +add_dependencies(${BINARY_NAME} flutter_assemble) +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/flutter/example/linux/flutter/CMakeLists.txt b/flutter/example/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000000..a1da1b9e53 --- /dev/null +++ b/flutter/example/linux/flutter/CMakeLists.txt @@ -0,0 +1,91 @@ +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) +pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid) +pkg_check_modules(LZMA REQUIRED IMPORTED_TARGET liblzma) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO + PkgConfig::BLKID + PkgConfig::LZMA +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + linux-x64 ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/flutter/example/linux/main.cc b/flutter/example/linux/main.cc new file mode 100644 index 0000000000..e7c5c54370 --- /dev/null +++ b/flutter/example/linux/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/flutter/example/linux/my_application.cc b/flutter/example/linux/my_application.cc new file mode 100644 index 0000000000..c13dff9b7a --- /dev/null +++ b/flutter/example/linux/my_application.cc @@ -0,0 +1,104 @@ +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen *screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "sentry_flutter_example"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } + else { + gtk_window_set_title(window, "sentry_flutter_example"); + } + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, gchar ***arguments, int *exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject *object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, + nullptr)); +} diff --git a/flutter/example/linux/my_application.h b/flutter/example/linux/my_application.h new file mode 100644 index 0000000000..72271d5e41 --- /dev/null +++ b/flutter/example/linux/my_application.h @@ -0,0 +1,18 @@ +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/flutter/example/macos/.gitignore b/flutter/example/macos/.gitignore new file mode 100644 index 0000000000..8506087342 --- /dev/null +++ b/flutter/example/macos/.gitignore @@ -0,0 +1,35 @@ +# Flutter-related +**/Flutter/ephemeral/ +**/Pods/ + +# Xcode-related +**/xcuserdata/ + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno + +Flutter/GeneratedPluginRegistrant.* \ No newline at end of file diff --git a/flutter/example/macos/Flutter/Flutter-Debug.xcconfig b/flutter/example/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000000..4b81f9b2d2 --- /dev/null +++ b/flutter/example/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/flutter/example/macos/Flutter/Flutter-Release.xcconfig b/flutter/example/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000000..5caa9d1579 --- /dev/null +++ b/flutter/example/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/flutter/example/macos/Podfile b/flutter/example/macos/Podfile new file mode 100644 index 0000000000..dade8dfad0 --- /dev/null +++ b/flutter/example/macos/Podfile @@ -0,0 +1,40 @@ +platform :osx, '10.11' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/flutter/example/macos/Runner.xcodeproj/project.pbxproj b/flutter/example/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..2d7e217ce7 --- /dev/null +++ b/flutter/example/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,642 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + 7FCF229C370F12EFF1B0FDF5 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1015E8E2F636E9884C600742 /* Pods_Runner.framework */; }; + DD7C8EE62624143F007C0E17 /* Buggy.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7C8EE42624143F007C0E17 /* Buggy.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 0E8F9AE402DA69C8F8BB2BAC /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + 1015E8E2F636E9884C600742 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* sentry_flutter_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sentry_flutter_example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 4DC7A330CF4AAABA0A32DC9E /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; + DD7C8EE32624143F007C0E17 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + DD7C8EE42624143F007C0E17 /* Buggy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Buggy.m; sourceTree = ""; }; + DD7C8EE52624143F007C0E17 /* Buggy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Buggy.h; sourceTree = ""; }; + E92729910C7E9CCF423200A0 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7FCF229C370F12EFF1B0FDF5 /* Pods_Runner.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1C7E056CED0931B0D5D5E8A4 /* Pods */ = { + isa = PBXGroup; + children = ( + 0E8F9AE402DA69C8F8BB2BAC /* Pods-Runner.debug.xcconfig */, + 4DC7A330CF4AAABA0A32DC9E /* Pods-Runner.release.xcconfig */, + E92729910C7E9CCF423200A0 /* Pods-Runner.profile.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + 1C7E056CED0931B0D5D5E8A4 /* Pods */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* sentry_flutter_example.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + DD7C8EE52624143F007C0E17 /* Buggy.h */, + DD7C8EE42624143F007C0E17 /* Buggy.m */, + DD7C8EE32624143F007C0E17 /* Runner-Bridging-Header.h */, + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1015E8E2F636E9884C600742 /* Pods_Runner.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + DBB14594CC644BB8564AC84B /* [CP] Check Pods Manifest.lock */, + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + 8E1A276E60B7113778522DF6 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* sentry_flutter_example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 0930; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1240; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; + 8E1A276E60B7113778522DF6 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + DBB14594CC644BB8564AC84B /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DD7C8EE62624143F007C0E17 /* Buggy.m in Sources */, + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/flutter/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/flutter/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/flutter/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/flutter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/flutter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..d9ffbdd84c --- /dev/null +++ b/flutter/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..21a3cc14c7 --- /dev/null +++ b/flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/flutter/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/flutter/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/flutter/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/flutter/example/macos/Runner/AppDelegate.swift b/flutter/example/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000000..bfe34620c7 --- /dev/null +++ b/flutter/example/macos/Runner/AppDelegate.swift @@ -0,0 +1,9 @@ +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..a2ec33f19f --- /dev/null +++ b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png new file mode 100644 index 0000000000..3c4935a7ca Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png new file mode 100644 index 0000000000..ed4cc16421 Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png new file mode 100644 index 0000000000..483be61389 Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png new file mode 100644 index 0000000000..bcbf36df2f Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png new file mode 100644 index 0000000000..9c0a652864 Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png new file mode 100644 index 0000000000..e71a726136 Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png differ diff --git a/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png new file mode 100644 index 0000000000..8a31fe2dd3 Binary files /dev/null and b/flutter/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png differ diff --git a/flutter/example/macos/Runner/Base.lproj/MainMenu.xib b/flutter/example/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000000..537341abf9 --- /dev/null +++ b/flutter/example/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,339 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/flutter/example/macos/Runner/Buggy.h b/flutter/example/macos/Runner/Buggy.h new file mode 100644 index 0000000000..fa3f27935d --- /dev/null +++ b/flutter/example/macos/Runner/Buggy.h @@ -0,0 +1,13 @@ +#ifndef Buggy_h +#define Buggy_h + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface Buggy : NSObject ++ (void)throw; +@end + +NS_ASSUME_NONNULL_END +#endif diff --git a/flutter/example/macos/Runner/Buggy.m b/flutter/example/macos/Runner/Buggy.m new file mode 100644 index 0000000000..d1d768b26b --- /dev/null +++ b/flutter/example/macos/Runner/Buggy.m @@ -0,0 +1,9 @@ +#import "Buggy.h" + +@implementation Buggy + ++ (void)throw { + [NSException raise:@"Raised from Objective-C." format:@"The value %d is the answer", 42]; +} + +@end diff --git a/flutter/example/macos/Runner/Configs/AppInfo.xcconfig b/flutter/example/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000000..69142118c1 --- /dev/null +++ b/flutter/example/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = sentry_flutter_example + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = io.sentry.flutter.sentryFlutterExample + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2021 io.sentry.flutter. All rights reserved. diff --git a/flutter/example/macos/Runner/Configs/Debug.xcconfig b/flutter/example/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000000..36b0fd9464 --- /dev/null +++ b/flutter/example/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/flutter/example/macos/Runner/Configs/Release.xcconfig b/flutter/example/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000000..dff4f49561 --- /dev/null +++ b/flutter/example/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/flutter/example/macos/Runner/Configs/Warnings.xcconfig b/flutter/example/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000000..42bcbf4780 --- /dev/null +++ b/flutter/example/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/flutter/example/macos/Runner/DebugProfile.entitlements b/flutter/example/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000000..3ba6c1266f --- /dev/null +++ b/flutter/example/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,14 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.client + + com.apple.security.network.server + + + diff --git a/flutter/example/macos/Runner/Info.plist b/flutter/example/macos/Runner/Info.plist new file mode 100644 index 0000000000..4789daa6a4 --- /dev/null +++ b/flutter/example/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/flutter/example/macos/Runner/MainFlutterWindow.swift b/flutter/example/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000000..f84cecfff3 --- /dev/null +++ b/flutter/example/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,42 @@ +import Cocoa +import FlutterMacOS +import Sentry + +class MainFlutterWindow: NSWindow { + private let _channel = "example.flutter.sentry.io" + + override func awakeFromNib() { + let flutterViewController = FlutterViewController.init() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + // swiftlint:disable:next force_cast + let controller = self.contentViewController as! FlutterViewController + let channel = FlutterMethodChannel(name: _channel, + binaryMessenger: controller.engine.binaryMessenger) + channel.setMethodCallHandler(handleMessage) + + super.awakeFromNib() + } + + private func handleMessage(call: FlutterMethodCall, result: FlutterResult) { + if call.method == "fatalError" { + fatalError("fatalError") + } else if call.method == "crash" { + SentrySDK.crash() + } else if call.method == "capture" { + let exception = NSException( + name: NSExceptionName("NSException"), + reason: "Swift NSException Captured", + userInfo: ["details": "lots"]) + SentrySDK.capture(exception: exception) + } else if call.method == "capture_message" { + SentrySDK.capture(message: "A message from Swift.") + } else if call.method == "throw" { + Buggy.throw() + } + } +} diff --git a/flutter/example/macos/Runner/Release.entitlements b/flutter/example/macos/Runner/Release.entitlements new file mode 100644 index 0000000000..ee95ab7e58 --- /dev/null +++ b/flutter/example/macos/Runner/Release.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/flutter/example/macos/Runner/Runner-Bridging-Header.h b/flutter/example/macos/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000000..d8245e27b0 --- /dev/null +++ b/flutter/example/macos/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "Buggy.h" diff --git a/flutter/example/windows/.gitignore b/flutter/example/windows/.gitignore new file mode 100644 index 0000000000..ec4098aa65 --- /dev/null +++ b/flutter/example/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/flutter/example/windows/CMakeLists.txt b/flutter/example/windows/CMakeLists.txt new file mode 100644 index 0000000000..845ddf6fef --- /dev/null +++ b/flutter/example/windows/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.15) +project(sentry_flutter_example LANGUAGES CXX) + +set(BINARY_NAME "sentry_flutter_example") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() + +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/flutter/example/windows/flutter/CMakeLists.txt b/flutter/example/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000000..c10f4f62cb --- /dev/null +++ b/flutter/example/windows/flutter/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.15) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + windows-x64 $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/flutter/example/windows/runner/CMakeLists.txt b/flutter/example/windows/runner/CMakeLists.txt new file mode 100644 index 0000000000..e993217632 --- /dev/null +++ b/flutter/example/windows/runner/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.15) +project(runner LANGUAGES CXX) + +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "run_loop.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) +apply_standard_settings(${BINARY_NAME}) +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/flutter/example/windows/runner/Runner.rc b/flutter/example/windows/runner/Runner.rc new file mode 100644 index 0000000000..a059a08d0d --- /dev/null +++ b/flutter/example/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#ifdef FLUTTER_BUILD_NUMBER +#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#else +#define VERSION_AS_NUMBER 1,0,0 +#endif + +#ifdef FLUTTER_BUILD_NAME +#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "Demonstrates how to use the sentry_flutter plugin." "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "sentry_flutter_example" "\0" + VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "sentry_flutter_example.exe" "\0" + VALUE "ProductName", "sentry_flutter_example" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/flutter/example/windows/runner/flutter_window.cpp b/flutter/example/windows/runner/flutter_window.cpp new file mode 100644 index 0000000000..ac04f7790a --- /dev/null +++ b/flutter/example/windows/runner/flutter_window.cpp @@ -0,0 +1,64 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(RunLoop* run_loop, + const flutter::DartProject& project) + : run_loop_(run_loop), project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + run_loop_->RegisterFlutterInstance(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + run_loop_->UnregisterFlutterInstance(flutter_controller_->engine()); + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opporutunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/flutter/example/windows/runner/flutter_window.h b/flutter/example/windows/runner/flutter_window.h new file mode 100644 index 0000000000..ba86031c6c --- /dev/null +++ b/flutter/example/windows/runner/flutter_window.h @@ -0,0 +1,39 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "run_loop.h" +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow driven by the |run_loop|, hosting a + // Flutter view running |project|. + explicit FlutterWindow(RunLoop* run_loop, + const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The run loop driving events for this window. + RunLoop* run_loop_; + + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/flutter/example/windows/runner/main.cpp b/flutter/example/windows/runner/main.cpp new file mode 100644 index 0000000000..0685ffa6aa --- /dev/null +++ b/flutter/example/windows/runner/main.cpp @@ -0,0 +1,42 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "run_loop.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + RunLoop run_loop; + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(&run_loop, project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.CreateAndShow(L"sentry_flutter_example", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + run_loop.Run(); + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/flutter/example/windows/runner/resource.h b/flutter/example/windows/runner/resource.h new file mode 100644 index 0000000000..ddc7f3efc0 --- /dev/null +++ b/flutter/example/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/flutter/example/windows/runner/resources/app_icon.ico b/flutter/example/windows/runner/resources/app_icon.ico new file mode 100644 index 0000000000..c04e20caf6 Binary files /dev/null and b/flutter/example/windows/runner/resources/app_icon.ico differ diff --git a/flutter/example/windows/runner/run_loop.cpp b/flutter/example/windows/runner/run_loop.cpp new file mode 100644 index 0000000000..0d912118c2 --- /dev/null +++ b/flutter/example/windows/runner/run_loop.cpp @@ -0,0 +1,66 @@ +#include "run_loop.h" + +#include + +#include + +RunLoop::RunLoop() {} + +RunLoop::~RunLoop() {} + +void RunLoop::Run() { + bool keep_running = true; + TimePoint next_flutter_event_time = TimePoint::clock::now(); + while (keep_running) { + std::chrono::nanoseconds wait_duration = + std::max(std::chrono::nanoseconds(0), + next_flutter_event_time - TimePoint::clock::now()); + ::MsgWaitForMultipleObjects( + 0, nullptr, FALSE, static_cast(wait_duration.count() / 1000), + QS_ALLINPUT); + bool processed_events = false; + MSG message; + // All pending Windows messages must be processed; MsgWaitForMultipleObjects + // won't return again for items left in the queue after PeekMessage. + while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) { + processed_events = true; + if (message.message == WM_QUIT) { + keep_running = false; + break; + } + ::TranslateMessage(&message); + ::DispatchMessage(&message); + // Allow Flutter to process messages each time a Windows message is + // processed, to prevent starvation. + next_flutter_event_time = + std::min(next_flutter_event_time, ProcessFlutterMessages()); + } + // If the PeekMessage loop didn't run, process Flutter messages. + if (!processed_events) { + next_flutter_event_time = + std::min(next_flutter_event_time, ProcessFlutterMessages()); + } + } +} + +void RunLoop::RegisterFlutterInstance( + flutter::FlutterEngine* flutter_instance) { + flutter_instances_.insert(flutter_instance); +} + +void RunLoop::UnregisterFlutterInstance( + flutter::FlutterEngine* flutter_instance) { + flutter_instances_.erase(flutter_instance); +} + +RunLoop::TimePoint RunLoop::ProcessFlutterMessages() { + TimePoint next_event_time = TimePoint::max(); + for (auto instance : flutter_instances_) { + std::chrono::nanoseconds wait_duration = instance->ProcessMessages(); + if (wait_duration != std::chrono::nanoseconds::max()) { + next_event_time = + std::min(next_event_time, TimePoint::clock::now() + wait_duration); + } + } + return next_event_time; +} diff --git a/flutter/example/windows/runner/run_loop.h b/flutter/example/windows/runner/run_loop.h new file mode 100644 index 0000000000..54927f9773 --- /dev/null +++ b/flutter/example/windows/runner/run_loop.h @@ -0,0 +1,40 @@ +#ifndef RUNNER_RUN_LOOP_H_ +#define RUNNER_RUN_LOOP_H_ + +#include + +#include +#include + +// A runloop that will service events for Flutter instances as well +// as native messages. +class RunLoop { + public: + RunLoop(); + ~RunLoop(); + + // Prevent copying + RunLoop(RunLoop const&) = delete; + RunLoop& operator=(RunLoop const&) = delete; + + // Runs the run loop until the application quits. + void Run(); + + // Registers the given Flutter instance for event servicing. + void RegisterFlutterInstance( + flutter::FlutterEngine* flutter_instance); + + // Unregisters the given Flutter instance from event servicing. + void UnregisterFlutterInstance( + flutter::FlutterEngine* flutter_instance); + + private: + using TimePoint = std::chrono::steady_clock::time_point; + + // Processes all currently pending messages for registered Flutter instances. + TimePoint ProcessFlutterMessages(); + + std::set flutter_instances_; +}; + +#endif // RUNNER_RUN_LOOP_H_ diff --git a/flutter/example/windows/runner/runner.exe.manifest b/flutter/example/windows/runner/runner.exe.manifest new file mode 100644 index 0000000000..2c680b8be2 --- /dev/null +++ b/flutter/example/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/flutter/example/windows/runner/utils.cpp b/flutter/example/windows/runner/utils.cpp new file mode 100644 index 0000000000..05b53c01b4 --- /dev/null +++ b/flutter/example/windows/runner/utils.cpp @@ -0,0 +1,64 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr); + if (target_length == 0) { + return std::string(); + } + std::string utf8_string; + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), + target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/flutter/example/windows/runner/utils.h b/flutter/example/windows/runner/utils.h new file mode 100644 index 0000000000..3f0e05cba3 --- /dev/null +++ b/flutter/example/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/flutter/example/windows/runner/win32_window.cpp b/flutter/example/windows/runner/win32_window.cpp new file mode 100644 index 0000000000..97f4439cd1 --- /dev/null +++ b/flutter/example/windows/runner/win32_window.cpp @@ -0,0 +1,245 @@ +#include "win32_window.h" + +#include + +#include "resource.h" + +namespace { + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + FreeLibrary(user32_module); + } +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + return OnCreate(); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} diff --git a/flutter/example/windows/runner/win32_window.h b/flutter/example/windows/runner/win32_window.h new file mode 100644 index 0000000000..d9bcac1b60 --- /dev/null +++ b/flutter/example/windows/runner/win32_window.h @@ -0,0 +1,98 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates and shows a win32 window with |title| and position and size using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size to will treat the width height passed in to this function + // as logical pixels and scale to appropriate for the default monitor. Returns + // true if the window was created successfully. + bool CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responsponds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/flutter/ios/Classes/SentryFlutterPlugin.m b/flutter/ios/Classes/SentryFlutterPlugin.m index aed1dc1224..f541e31c0e 100644 --- a/flutter/ios/Classes/SentryFlutterPlugin.m +++ b/flutter/ios/Classes/SentryFlutterPlugin.m @@ -10,6 +10,6 @@ @implementation SentryFlutterPlugin + (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftSentryFlutterPlugin registerWithRegistrar:registrar]; + [SentryFlutterPluginApple registerWithRegistrar:registrar]; } @end diff --git a/flutter/ios/Classes/SwiftSentryFlutterPlugin.swift b/flutter/ios/Classes/SentryFlutterPluginApple.swift similarity index 93% rename from flutter/ios/Classes/SwiftSentryFlutterPlugin.swift rename to flutter/ios/Classes/SentryFlutterPluginApple.swift index 0eaf68245d..6b661ea78f 100644 --- a/flutter/ios/Classes/SwiftSentryFlutterPlugin.swift +++ b/flutter/ios/Classes/SentryFlutterPluginApple.swift @@ -1,8 +1,13 @@ -import Flutter import Sentry +#if os(iOS) +import Flutter import UIKit +#elseif os(macOS) +import FlutterMacOS +import AppKit +#endif -public class SwiftSentryFlutterPlugin: NSObject, FlutterPlugin { +public class SentryFlutterPluginApple: NSObject, FlutterPlugin { private var sentryOptions: Options? @@ -10,10 +15,22 @@ public class SwiftSentryFlutterPlugin: NSObject, FlutterPlugin { // We need to be able to receive this notification and start a session when the SDK is fully operational. private var didReceiveDidBecomeActiveNotification = false + private var didBecomeActiveNotificationName: NSNotification.Name { +#if os(iOS) + return UIApplication.didBecomeActiveNotification +#elseif os(macOS) + return NSApplication.didBecomeActiveNotification +#endif + } + public static func register(with registrar: FlutterPluginRegistrar) { +#if os(iOS) let channel = FlutterMethodChannel(name: "sentry_flutter", binaryMessenger: registrar.messenger()) +#elseif os(macOS) + let channel = FlutterMethodChannel(name: "sentry_flutter", binaryMessenger: registrar.messenger) +#endif - let instance = SwiftSentryFlutterPlugin() + let instance = SentryFlutterPluginApple() instance.registerObserver() registrar.addMethodCallDelegate(instance, channel: channel) @@ -22,17 +39,17 @@ public class SwiftSentryFlutterPlugin: NSObject, FlutterPlugin { private func registerObserver() { NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), - name: UIApplication.didBecomeActiveNotification, + name: didBecomeActiveNotificationName, object: nil) } @objc private func applicationDidBecomeActive() { didReceiveDidBecomeActiveNotification = true - // we only need to do that in the 1st time, so removing it NotificationCenter.default.removeObserver(self, - name: UIApplication.didBecomeActiveNotification, + name: didBecomeActiveNotificationName, object: nil) + } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { diff --git a/flutter/ios/sentry_flutter.podspec b/flutter/ios/sentry_flutter.podspec index 768c4aa29f..4ea47fc865 100644 --- a/flutter/ios/sentry_flutter.podspec +++ b/flutter/ios/sentry_flutter.podspec @@ -6,11 +6,11 @@ Pod::Spec.new do |s| Sentry SDK for Flutter with support to native through sentry-cocoa. DESC s.homepage = 'https://sentry.io' - s.license = { :type => 'MIT', :file => '../LICENSE' } + s.license = { :file => '../LICENSE' } s.authors = "Sentry" s.source = { :git => "https://github.com/getsentry/sentry-dart.git", :tag => s.version.to_s } - s.source_files = 'Classes/**/*' + s.source_files = 'Classes/**/*' s.dependency 'Sentry', '~> 6.2.1' s.dependency 'Flutter' s.platform = :ios, '9.0' diff --git a/flutter/lib/src/default_integrations.dart b/flutter/lib/src/default_integrations.dart index 784ce5062f..93bee046e8 100644 --- a/flutter/lib/src/default_integrations.dart +++ b/flutter/lib/src/default_integrations.dart @@ -109,7 +109,7 @@ class FlutterErrorIntegration extends Integration { /// the Message channel. /// We intend to unify this behaviour in the future. /// -/// This integration is only executed on iOS Apps. +/// This integration is only executed on iOS & MacOS Apps. class LoadContextsIntegration extends Integration { final MethodChannel _channel; @@ -364,22 +364,32 @@ class LoadReleaseIntegration extends Integration { @override FutureOr call(Hub hub, SentryFlutterOptions options) async { try { - if (!kIsWeb) { - if (options.release == null || options.dist == null) { - final packageInfo = await _packageLoader(); - var name = packageInfo.packageName; - if (name.isEmpty) { - // Not all platforms have a packageName. - // If no packageName is available, use the appName instead. - name = _cleanAppName(packageInfo.appName); - } + if (options.release == null || options.dist == null) { + final packageInfo = await _packageLoader(); + var name = _cleanString(packageInfo.packageName); + if (name.isEmpty) { + // Not all platforms have a packageName. + // If no packageName is available, use the appName instead. + name = _cleanString(packageInfo.appName); + } + + final version = _cleanString(packageInfo.version); + final buildNumber = _cleanString(packageInfo.buildNumber); + + var release = name; + if (version.isNotEmpty) { + release = '$release@$version'; + } + // At least windows sometimes does not have a buildNumber + if (buildNumber.isNotEmpty) { + release = '$release+$buildNumber'; + } - final release = - '$name@${packageInfo.version}+${packageInfo.buildNumber}'; - options.logger(SentryLevel.debug, 'release: $release'); + options.logger(SentryLevel.debug, 'release: $release'); - options.release = options.release ?? release; - options.dist = options.dist ?? packageInfo.buildNumber; + options.release = options.release ?? release; + if (buildNumber.isNotEmpty) { + options.dist = options.dist ?? buildNumber; } } } catch (error) { @@ -390,15 +400,21 @@ class LoadReleaseIntegration extends Integration { options.sdk.addIntegration('loadReleaseIntegration'); } - String _cleanAppName(String appName) { + /// This method cleans the given string from characters which should not be + /// used. + /// For example https://docs.sentry.io/platforms/flutter/configuration/releases/#bind-the-version + /// imposes some requirements. Also Windows uses some characters which + /// should not be used. + String _cleanString(String appName) { // Replace disallowed chars with an underscore '_' - // https://docs.sentry.io/platforms/flutter/configuration/releases/#bind-the-version return appName .replaceAll('/', '_') .replaceAll('\\', '_') .replaceAll('\t', '_') .replaceAll('\r\n', '_') .replaceAll('\r', '_') - .replaceAll('\n', '_'); + .replaceAll('\n', '_') + // replace Unicode NULL character with an empty string + .replaceAll('\u{0000}', ''); } } diff --git a/flutter/lib/src/platform_checker.dart b/flutter/lib/src/platform_checker.dart deleted file mode 100644 index 1579130d72..0000000000 --- a/flutter/lib/src/platform_checker.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'dart:io'; - -/// verify if the platform is iOS -/// used to run loadContextsIntegration only on iOS -bool isIOS() => Platform.isIOS; - -/// verify if the platform is Android -bool isAndroid() => Platform.isAndroid; diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 41c71eef38..3731dd3931 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -1,6 +1,5 @@ import 'dart:async'; -import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:sentry/sentry.dart'; @@ -9,11 +8,6 @@ import 'sentry_flutter_options.dart'; import 'default_integrations.dart'; import 'file_system_transport.dart'; import 'version.dart'; -// conditional import for the iOSPlatformChecker -// in browser, the iOSPlatformChecker will always return false -// the iOSPlatformChecker is used to run the loadContextsIntegration only on iOS. -// this injected PlatformChecker allows to test this behavior -import 'web_platform_checker.dart' if (dart.library.io) 'platform_checker.dart'; /// Configuration options callback typedef FlutterOptionsConfiguration = FutureOr Function( @@ -27,19 +21,20 @@ mixin SentryFlutter { FlutterOptionsConfiguration optionsConfiguration, { AppRunner? appRunner, PackageLoader packageLoader = _loadPackageInfo, - iOSPlatformChecker isIOSChecker = isIOS, - AndroidPlatformChecker isAndroidChecker = isAndroid, MethodChannel channel = _channel, + PlatformChecker? platformChecker, }) async { final flutterOptions = SentryFlutterOptions(); + if (platformChecker != null) { + flutterOptions.platformChecker = platformChecker; + } // first step is to install the native integration and set default values, // so we are able to capture future errors. final defaultIntegrations = _createDefaultIntegrations( - isIOSChecker, - isAndroidChecker, packageLoader, channel, + flutterOptions, ); for (final defaultIntegration in defaultIntegrations) { flutterOptions.addIntegration(defaultIntegration); @@ -60,8 +55,8 @@ mixin SentryFlutter { SentryFlutterOptions options, MethodChannel channel, ) async { - // web still uses a http transport for Web which is set by default - if (!kIsWeb) { + // Not all platforms have a native integration. + if (options.platformChecker.hasNativeIntegration) { options.transport = FileSystemTransport(channel, options); } @@ -71,40 +66,40 @@ mixin SentryFlutter { /// Install default integrations /// https://medium.com/flutter-community/error-handling-in-flutter-98fce88a34f0 static List _createDefaultIntegrations( - iOSPlatformChecker isIOS, - AndroidPlatformChecker isAndroid, PackageLoader packageLoader, MethodChannel channel, + SentryFlutterOptions options, ) { final integrations = []; // Will call WidgetsFlutterBinding.ensureInitialized() before all other integrations. integrations.add(WidgetsFlutterBindingIntegration()); - // will catch any errors that may occur in the Flutter framework itself. + // Will catch any errors that may occur in the Flutter framework itself. integrations.add(FlutterErrorIntegration()); // This tracks Flutter application events, such as lifecycle events. integrations.add(WidgetsBindingIntegration()); - // the ordering here matters, as we'd like to first start the native integration - // that allow us to send events to the network and then the Flutter integrations. + // The ordering here matters, as we'd like to first start the native integration. + // That allow us to send events to the network and then the Flutter integrations. // Flutter Web doesn't need that, only Android and iOS. - if (!kIsWeb) { + if (options.platformChecker.hasNativeIntegration) { integrations.add(NativeSdkIntegration(channel)); } - // will enrich the events with the device context and native packages and integrations - if (isIOS()) { + // Will enrich events with device context, native packages and integrations + if (options.platformChecker.platform.isIOS || + options.platformChecker.platform.isMacOS) { integrations.add(LoadContextsIntegration(channel)); } - if (isAndroid()) { + if (options.platformChecker.platform.isAndroid) { integrations.add(LoadAndroidImageListIntegration(channel)); } - // this is an Integration because we want to execute after all the - // error handlers are in place, calling a Channel might result + // This is an Integration because we want to execute it after all the + // error handlers are in place. Calling a MethodChannel might result // in errors. integrations.add(LoadReleaseIntegration(packageLoader)); @@ -124,12 +119,6 @@ mixin SentryFlutter { } } -/// an iOS PlatformChecker wrapper to make it testable -typedef iOSPlatformChecker = bool Function(); - -/// an Android PlatformChecker wrapper to make it testable -typedef AndroidPlatformChecker = bool Function(); - /// Package info loader. Future _loadPackageInfo() async { return await PackageInfo.fromPlatform(); diff --git a/flutter/lib/src/sentry_flutter_options.dart b/flutter/lib/src/sentry_flutter_options.dart index cd560676b5..c5fa7411dd 100644 --- a/flutter/lib/src/sentry_flutter_options.dart +++ b/flutter/lib/src/sentry_flutter_options.dart @@ -186,11 +186,11 @@ class SentryFlutterOptions extends SentryOptions { switch (platform) { case foundation.TargetPlatform.android: case foundation.TargetPlatform.iOS: + case foundation.TargetPlatform.macOS: useNativeBreadcrumbTracking(); break; case foundation.TargetPlatform.fuchsia: case foundation.TargetPlatform.linux: - case foundation.TargetPlatform.macOS: case foundation.TargetPlatform.windows: // These platforms have no native integration, so just use the Flutter // integration. diff --git a/flutter/lib/src/web_platform_checker.dart b/flutter/lib/src/web_platform_checker.dart deleted file mode 100644 index fc42d2cd46..0000000000 --- a/flutter/lib/src/web_platform_checker.dart +++ /dev/null @@ -1,5 +0,0 @@ -/// always false for flutter web -bool isIOS() => false; - -/// always false for flutter web -bool isAndroid() => false; diff --git a/flutter/linux/CMakeLists.txt b/flutter/linux/CMakeLists.txt new file mode 100644 index 0000000000..b63ea90066 --- /dev/null +++ b/flutter/linux/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) +set(PROJECT_NAME "sentry_flutter") +project(${PROJECT_NAME} LANGUAGES CXX) + +# This value is used when generating builds using this plugin, so it must +# not be changed +set(PLUGIN_NAME "sentry_flutter_plugin") + +add_library(${PLUGIN_NAME} SHARED + "sentry_flutter_plugin.cc" +) +apply_standard_settings(${PLUGIN_NAME}) +set_target_properties(${PLUGIN_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) +target_include_directories(${PLUGIN_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) +target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) + +# List of absolute paths to libraries that should be bundled with the plugin +set(sentry_flutter_bundled_libraries + "" + PARENT_SCOPE +) diff --git a/flutter/linux/include/sentry_flutter/sentry_flutter_plugin.h b/flutter/linux/include/sentry_flutter/sentry_flutter_plugin.h new file mode 100644 index 0000000000..d0f8df001f --- /dev/null +++ b/flutter/linux/include/sentry_flutter/sentry_flutter_plugin.h @@ -0,0 +1,26 @@ +#ifndef FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ +#define FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ + +#include + +G_BEGIN_DECLS + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) +#else +#define FLUTTER_PLUGIN_EXPORT +#endif + +typedef struct _SentryFlutterPlugin SentryFlutterPlugin; +typedef struct { + GObjectClass parent_class; +} SentryFlutterPluginClass; + +FLUTTER_PLUGIN_EXPORT GType sentry_flutter_plugin_get_type(); + +FLUTTER_PLUGIN_EXPORT void sentry_flutter_plugin_register_with_registrar( + FlPluginRegistrar* registrar); + +G_END_DECLS + +#endif // FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ diff --git a/flutter/linux/sentry_flutter_plugin.cc b/flutter/linux/sentry_flutter_plugin.cc new file mode 100644 index 0000000000..c8ac1220c7 --- /dev/null +++ b/flutter/linux/sentry_flutter_plugin.cc @@ -0,0 +1,60 @@ +#include "include/sentry_flutter/sentry_flutter_plugin.h" + +#include +#include +#include + +#include + +#define SENTRY_FLUTTER_PLUGIN(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), sentry_flutter_plugin_get_type(), \ + SentryFlutterPlugin)) + +struct _SentryFlutterPlugin { + GObject parent_instance; +}; + +G_DEFINE_TYPE(SentryFlutterPlugin, sentry_flutter_plugin, g_object_get_type()) + +// Called when a method call is received from Flutter. +static void sentry_flutter_plugin_handle_method_call( + SentryFlutterPlugin* self, + FlMethodCall* method_call) { + g_autoptr(FlMethodResponse) response = nullptr; + + response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); + + fl_method_call_respond(method_call, response, nullptr); +} + +static void sentry_flutter_plugin_dispose(GObject* object) { + G_OBJECT_CLASS(sentry_flutter_plugin_parent_class)->dispose(object); +} + +static void sentry_flutter_plugin_class_init(SentryFlutterPluginClass* klass) { + G_OBJECT_CLASS(klass)->dispose = sentry_flutter_plugin_dispose; +} + +static void sentry_flutter_plugin_init(SentryFlutterPlugin* self) {} + +static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call, + gpointer user_data) { + SentryFlutterPlugin* plugin = SENTRY_FLUTTER_PLUGIN(user_data); + sentry_flutter_plugin_handle_method_call(plugin, method_call); +} + +void sentry_flutter_plugin_register_with_registrar(FlPluginRegistrar* registrar) { + SentryFlutterPlugin* plugin = SENTRY_FLUTTER_PLUGIN( + g_object_new(sentry_flutter_plugin_get_type(), nullptr)); + + g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new(); + g_autoptr(FlMethodChannel) channel = + fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar), + "sentry_flutter", + FL_METHOD_CODEC(codec)); + fl_method_channel_set_method_call_handler(channel, method_call_cb, + g_object_ref(plugin), + g_object_unref); + + g_object_unref(plugin); +} diff --git a/flutter/macos/Classes/SentryFlutterPluginApple.swift b/flutter/macos/Classes/SentryFlutterPluginApple.swift new file mode 120000 index 0000000000..1ac6c4f5be --- /dev/null +++ b/flutter/macos/Classes/SentryFlutterPluginApple.swift @@ -0,0 +1 @@ +../../ios/Classes/SentryFlutterPluginApple.swift \ No newline at end of file diff --git a/flutter/macos/sentry_flutter.podspec b/flutter/macos/sentry_flutter.podspec new file mode 100644 index 0000000000..bd0629dd00 --- /dev/null +++ b/flutter/macos/sentry_flutter.podspec @@ -0,0 +1,20 @@ +Pod::Spec.new do |s| + s.name = 'sentry_flutter' + s.version = '0.0.1' + s.summary = 'Sentry SDK for Flutter.' + s.description = <<-DESC +Sentry SDK for Flutter with support to native through sentry-cocoa. + DESC + s.homepage = 'https://sentry.io' + s.license = { :file => '../LICENSE' } + s.authors = "Sentry" + s.source = { :git => "https://github.com/getsentry/sentry-dart.git", + :tag => s.version.to_s } + s.source_files = 'Classes/**/*' + s.dependency 'Sentry', '~> 6.2.1' + s.dependency 'FlutterMacOS' + s.platform = :osx, '10.11' + + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.swift_version = '5.0' +end diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 37da80b8f1..235d9e8743 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -36,6 +36,12 @@ flutter: package: io.sentry.flutter ios: pluginClass: SentryFlutterPlugin + macos: + pluginClass: SentryFlutterPluginApple web: pluginClass: SentryFlutterWeb fileName: sentry_flutter_web.dart + linux: + pluginClass: SentryFlutterPlugin + windows: + pluginClass: SentryFlutterPlugin diff --git a/flutter/test/default_integrations_test.dart b/flutter/test/default_integrations_test.dart index 35b2b45ab2..4e5866c10d 100644 --- a/flutter/test/default_integrations_test.dart +++ b/flutter/test/default_integrations_test.dart @@ -267,7 +267,8 @@ void main() { expect(fixture.options.dist, '789'); }); - test('release name does not contain ivalid chars', () async { + test('release name does not contain invalid chars defined by Sentry', + () async { final loader = () { return Future.value(PackageInfo( appName: '\\/sentry\tflutter \r\nfoo\nbar\r', @@ -283,6 +284,69 @@ void main() { expect(fixture.options.release, '__sentry_flutter _foo_bar_@1.2.3+789'); expect(fixture.options.dist, '789'); }); + + /// See the following issues: + /// - https://github.com/getsentry/sentry-dart/issues/410 + /// - https://github.com/fluttercommunity/plus_plugins/issues/182 + test('does not send Unicode NULL \\u0000 character in app name or version', + () async { + final loader = () { + return Future.value(PackageInfo( + // As per + // https://api.dart.dev/stable/2.12.4/dart-core/String-class.html + // this is how \u0000 is added to a string in dart + appName: 'sentry_flutter_example\u{0000}', + packageName: '', + version: '1.0.0\u{0000}', + buildNumber: '', + )); + }; + await fixture + .getIntegration(loader: loader) + .call(MockHub(), fixture.options); + + expect(fixture.options.release, 'sentry_flutter_example@1.0.0'); + }); + + /// See the following issues: + /// - https://github.com/getsentry/sentry-dart/issues/410 + /// - https://github.com/fluttercommunity/plus_plugins/issues/182 + test( + 'does not send Unicode NULL \\u0000 character in package name or build number', + () async { + final loader = () { + return Future.value(PackageInfo( + // As per + // https://api.dart.dev/stable/2.12.4/dart-core/String-class.html + // this is how \u0000 is added to a string in dart + appName: '', + packageName: 'sentry_flutter_example\u{0000}', + version: '', + buildNumber: '123\u{0000}', + )); + }; + await fixture + .getIntegration(loader: loader) + .call(MockHub(), fixture.options); + + expect(fixture.options.release, 'sentry_flutter_example+123'); + }); + + test('dist is null if build number is an empty string', () async { + final loader = () { + return Future.value(PackageInfo( + appName: 'sentry_flutter_example', + packageName: 'a.b.c', + version: '1.0.0', + buildNumber: '', + )); + }; + await fixture + .getIntegration(loader: loader) + .call(MockHub(), fixture.options); + + expect(fixture.options.dist, isNull); + }); }); } diff --git a/flutter/test/mocks.dart b/flutter/test/mocks.dart index 787cc98bd5..499f31eb91 100644 --- a/flutter/test/mocks.dart +++ b/flutter/test/mocks.dart @@ -1,7 +1,45 @@ import 'package:mockito/annotations.dart'; import 'package:sentry/sentry.dart'; +import 'package:sentry/src/platform/platform.dart'; const fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; @GenerateMocks([Hub, Transport]) void main() {} + +class MockPlatform implements Platform { + MockPlatform({ + String? os, + String? osVersion, + String? hostname, + }) : operatingSystem = os ?? '', + operatingSystemVersion = osVersion ?? '', + localHostname = hostname ?? ''; + + @override + String operatingSystem; + + @override + String operatingSystemVersion; + + @override + String localHostname; + + @override + bool get isLinux => (operatingSystem == 'linux'); + + @override + bool get isMacOS => (operatingSystem == 'macos'); + + @override + bool get isWindows => (operatingSystem == 'windows'); + + @override + bool get isAndroid => (operatingSystem == 'android'); + + @override + bool get isIOS => (operatingSystem == 'ios'); + + @override + bool get isFuchsia => (operatingSystem == 'fuchsia'); +} diff --git a/flutter/test/sentry_flutter_options_test.dart b/flutter/test/sentry_flutter_options_test.dart index 9859cc0453..a5dc1c750d 100644 --- a/flutter/test/sentry_flutter_options_test.dart +++ b/flutter/test/sentry_flutter_options_test.dart @@ -7,33 +7,32 @@ void main() { group('SentryFlutterOptions', () { testWidgets('auto breadcrumb tracking', (WidgetTester tester) async { final options = SentryFlutterOptions(); - options.configureBreadcrumbTrackingForPlatform(TargetPlatform.android); - expect(options.enableAppLifecycleBreadcrumbs, isFalse); - expect(options.enableWindowMetricBreadcrumbs, isFalse); - expect(options.enableBrightnessChangeBreadcrumbs, isFalse); - expect(options.enableTextScaleChangeBreadcrumbs, isFalse); - expect(options.enableMemoryPressureBreadcrumbs, isFalse); - expect(options.enableAutoNativeBreadcrumbs, isTrue); + final platformsWithNativeIntegration = [ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ]; - options.configureBreadcrumbTrackingForPlatform(TargetPlatform.iOS); + for (final platform in platformsWithNativeIntegration) { + options.configureBreadcrumbTrackingForPlatform(platform); - expect(options.enableAppLifecycleBreadcrumbs, isFalse); - expect(options.enableWindowMetricBreadcrumbs, isFalse); - expect(options.enableBrightnessChangeBreadcrumbs, isFalse); - expect(options.enableTextScaleChangeBreadcrumbs, isFalse); - expect(options.enableMemoryPressureBreadcrumbs, isFalse); - expect(options.enableAutoNativeBreadcrumbs, isTrue); + expect(options.enableAppLifecycleBreadcrumbs, isFalse); + expect(options.enableWindowMetricBreadcrumbs, isFalse); + expect(options.enableBrightnessChangeBreadcrumbs, isFalse); + expect(options.enableTextScaleChangeBreadcrumbs, isFalse); + expect(options.enableMemoryPressureBreadcrumbs, isFalse); + expect(options.enableAutoNativeBreadcrumbs, isTrue); + } // for all other platform the inverse is true - final platforms = [ + final platformsWithoutNativeIntegration = [ TargetPlatform.fuchsia, TargetPlatform.linux, - TargetPlatform.macOS, TargetPlatform.windows, ]; - for (final platform in platforms) { + for (final platform in platformsWithoutNativeIntegration) { options.configureBreadcrumbTrackingForPlatform(platform); expect(options.enableAppLifecycleBreadcrumbs, isTrue); diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 8d116f6206..0fe719fa9e 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -4,6 +4,7 @@ import 'package:mockito/mockito.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; +import 'package:sentry/src/platform_checker.dart'; import 'mocks.dart'; import 'mocks.mocks.dart'; @@ -28,8 +29,8 @@ void main() { getConfigurationTester(isAndroid: true), appRunner: appRunner, packageLoader: loadTestPackage, - isAndroidChecker: () => true, channel: _channel, + platformChecker: getPlatformChecker(isAndroid: true), ); }); @@ -38,8 +39,8 @@ void main() { getConfigurationTester(isIOS: true), appRunner: appRunner, packageLoader: loadTestPackage, - isIOSChecker: () => true, channel: _channel, + platformChecker: getPlatformChecker(isIOS: true), ); }); }); @@ -67,8 +68,8 @@ void main() { ..dsn = fakeDsn ..transport = transport, packageLoader: loadTestPackage, - isIOSChecker: () => true, channel: _channel, + platformChecker: getPlatformChecker(isIOS: true), ); await Sentry.captureMessage('a message'); @@ -86,7 +87,7 @@ void main() { ..dsn = fakeDsn ..transport = transport, packageLoader: loadTestPackage, - isIOSChecker: () => false, + platformChecker: getPlatformChecker(isAndroid: true), channel: _channel, ); @@ -95,9 +96,11 @@ void main() { final event = verify(transport.send(captureAny)).captured.first as SentryEvent; - expect(event.sdk!.integrations.length, 6); + expect(event.sdk!.integrations.length, 7); expect( - event.sdk!.integrations.contains('loadContextsIntegration'), false); + event.sdk!.integrations.contains('loadContextsIntegration'), + false, + ); }); test('should not add loadAndroidImageListIntegration if not Android', @@ -107,7 +110,7 @@ void main() { ..dsn = fakeDsn ..transport = transport, packageLoader: loadTestPackage, - isAndroidChecker: () => false, + platformChecker: getPlatformChecker(isIOS: true), channel: _channel, ); @@ -116,10 +119,11 @@ void main() { final event = verify(transport.send(captureAny)).captured.first as SentryEvent; - expect(event.sdk!.integrations.length, 6); + expect(event.sdk!.integrations.length, 7); expect( - event.sdk!.integrations.contains('loadAndroidImageListIntegration'), - false); + event.sdk!.integrations.contains('loadAndroidImageListIntegration'), + false, + ); }); }); } @@ -134,3 +138,24 @@ Future loadTestPackage() async { buildNumber: 'buildNumber', ); } + +PlatformChecker getPlatformChecker({ + bool isIOS = false, + bool isWeb = false, + bool isAndroid = false, +}) { + var osName = ''; + if (isIOS) { + osName = 'ios'; + } + if (isAndroid) { + osName = 'android'; + } + final platformChecker = PlatformChecker( + isWeb: isWeb, + platform: MockPlatform( + os: osName, + ), + ); + return platformChecker; +} diff --git a/flutter/test/sentry_flutter_util.dart b/flutter/test/sentry_flutter_util.dart index 533344269a..eb85481211 100644 --- a/flutter/test/sentry_flutter_util.dart +++ b/flutter/test/sentry_flutter_util.dart @@ -22,14 +22,15 @@ FutureOr Function(SentryOptions) getConfigurationTester({ expect(kDebugMode, options.debug); expect('debug', options.environment); - expect(!isWeb, options.transport is FileSystemTransport); + expect(options.platformChecker.hasNativeIntegration, + options.transport is FileSystemTransport); expect( options.integrations.whereType().length, 1, ); - if (!isWeb) { + if (options.platformChecker.hasNativeIntegration) { expect( options.integrations.whereType().length, 1, diff --git a/flutter/windows/.gitignore b/flutter/windows/.gitignore new file mode 100644 index 0000000000..2c36fa939d --- /dev/null +++ b/flutter/windows/.gitignore @@ -0,0 +1,20 @@ +flutter/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +flutter/example/windows/flutter/generated_plugins.cmake +flutter/example/windows/flutter/generated_plugin_registrant.* \ No newline at end of file diff --git a/flutter/windows/CMakeLists.txt b/flutter/windows/CMakeLists.txt new file mode 100644 index 0000000000..1f0a4aff9d --- /dev/null +++ b/flutter/windows/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.15) +set(PROJECT_NAME "sentry_flutter") +project(${PROJECT_NAME} LANGUAGES CXX) + +# This value is used when generating builds using this plugin, so it must +# not be changed +set(PLUGIN_NAME "sentry_flutter_plugin") + +add_library(${PLUGIN_NAME} SHARED + "sentry_flutter_plugin.cpp" +) +apply_standard_settings(${PLUGIN_NAME}) +set_target_properties(${PLUGIN_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) +target_include_directories(${PLUGIN_NAME} INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) + +# List of absolute paths to libraries that should be bundled with the plugin +set(sentry_flutter_bundled_libraries + "" + PARENT_SCOPE +) diff --git a/flutter/windows/include/sentry_flutter/sentry_flutter_plugin.h b/flutter/windows/include/sentry_flutter/sentry_flutter_plugin.h new file mode 100644 index 0000000000..d8482b94cd --- /dev/null +++ b/flutter/windows/include/sentry_flutter/sentry_flutter_plugin.h @@ -0,0 +1,23 @@ +#ifndef FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ +#define FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void SentryFlutterPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_PLUGIN_SENTRY_FLUTTER_PLUGIN_H_ diff --git a/flutter/windows/sentry_flutter_plugin.cpp b/flutter/windows/sentry_flutter_plugin.cpp new file mode 100644 index 0000000000..c8b9b9142b --- /dev/null +++ b/flutter/windows/sentry_flutter_plugin.cpp @@ -0,0 +1,69 @@ +#include "include/sentry_flutter/sentry_flutter_plugin.h" + +// This must be included before many other Windows headers. +#include + +// For getPlatformVersion; remove unless needed for your plugin implementation. +#include + +#include +#include +#include + +#include +#include +#include + +namespace { + +class SentryFlutterPlugin : public flutter::Plugin { + public: + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); + + SentryFlutterPlugin(); + + virtual ~SentryFlutterPlugin(); + + private: + // Called when a method is called on this plugin's channel from Dart. + void HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result); +}; + +// static +void SentryFlutterPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarWindows *registrar) { + auto channel = + std::make_unique>( + registrar->messenger(), "sentry_flutter", + &flutter::StandardMethodCodec::GetInstance()); + + auto plugin = std::make_unique(); + + channel->SetMethodCallHandler( + [plugin_pointer = plugin.get()](const auto &call, auto result) { + plugin_pointer->HandleMethodCall(call, std::move(result)); + }); + + registrar->AddPlugin(std::move(plugin)); +} + +SentryFlutterPlugin::SentryFlutterPlugin() {} + +SentryFlutterPlugin::~SentryFlutterPlugin() {} + +void SentryFlutterPlugin::HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result) { + // Native features will be added in a next release +} + +} // namespace + +void SentryFlutterPluginRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + SentryFlutterPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +}