diff --git a/CHANGELOG.md b/CHANGELOG.md index 2622377a5..1c2954aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 5.0.0 + +This major release contains all the changes from the 5.0.0 beta releases, along with the following changes: + +Improvements: +- [Android] Remove the Kotlin Standard Library from the dependencies, as it is automatically included in Kotlin 1.4+ + ## 5.0.0-beta.3 **BREAKING CHANGES:** diff --git a/android/build.gradle b/android/build.gradle index 2733a2905..b717a16e7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,7 +2,6 @@ group 'dev.steenbakker.mobile_scanner' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.7.22' repositories { google() mavenCentral() @@ -10,7 +9,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:8.3.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22" } } @@ -64,8 +63,6 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - def useUnbundled = project.findProperty('dev.steenbakker.mobile_scanner.useUnbundled') ?: false if (useUnbundled.toBoolean()) { // Dynamically downloaded model via Google Play Services diff --git a/lib/src/web/media_track_constraints_delegate.dart b/lib/src/web/media_track_constraints_delegate.dart index 8c5749200..721dd7f5a 100644 --- a/lib/src/web/media_track_constraints_delegate.dart +++ b/lib/src/web/media_track_constraints_delegate.dart @@ -1,5 +1,6 @@ import 'dart:js_interop'; +import 'package:mobile_scanner/src/web/media_track_extension.dart'; import 'package:web/web.dart'; /// This class represents a delegate that manages the constraints for a [MediaStreamTrack]. @@ -17,10 +18,18 @@ final class MediaTrackConstraintsDelegate { final MediaStreamTrack track = tracks.first; - final MediaTrackCapabilities capabilities = track.getCapabilities(); + final MediaTrackCapabilities capabilities; + + if (track.getCapabilitiesNullable != null) { + capabilities = track.getCapabilities(); + } else { + capabilities = MediaTrackCapabilities(); + } + final MediaTrackSettings settings = track.getSettings(); + final JSArray? facingModes = capabilities.facingModeNullable; - if (capabilities.facingMode.toDart.isEmpty) { + if (facingModes == null || facingModes.toDart.isEmpty) { return MediaTrackSettings( width: settings.width, height: settings.height, diff --git a/lib/src/web/media_track_extension.dart b/lib/src/web/media_track_extension.dart new file mode 100644 index 000000000..2b8743249 --- /dev/null +++ b/lib/src/web/media_track_extension.dart @@ -0,0 +1,18 @@ +import 'dart:js_interop'; +import 'package:web/web.dart'; + +/// This extension provides nullable properties for [MediaStreamTrack], +/// for cases where the properties are not supported by all browsers. +extension NullableMediaStreamTrackCapabilities on MediaStreamTrack { + /// The `getCapabilities` function is not supported on Firefox. + @JS('getCapabilities') + external JSFunction? get getCapabilitiesNullable; +} + +/// This extension provides nullable properties for [MediaTrackCapabilities], +/// for cases where the properties are not supported by all browsers. +extension NullableMediaTrackCapabilities on MediaTrackCapabilities { + /// The `facingMode` property is not supported on Safari. + @JS('facingMode') + external JSArray? get facingModeNullable; +} diff --git a/lib/src/web/mobile_scanner_web.dart b/lib/src/web/mobile_scanner_web.dart index ab77313f3..cee84d6b8 100644 --- a/lib/src/web/mobile_scanner_web.dart +++ b/lib/src/web/mobile_scanner_web.dart @@ -13,6 +13,7 @@ import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart'; import 'package:mobile_scanner/src/objects/barcode_capture.dart'; import 'package:mobile_scanner/src/objects/start_options.dart'; import 'package:mobile_scanner/src/web/barcode_reader.dart'; +import 'package:mobile_scanner/src/web/media_track_extension.dart'; import 'package:mobile_scanner/src/web/zxing/zxing_barcode_reader.dart'; import 'package:web/web.dart'; @@ -124,11 +125,19 @@ class MobileScannerWeb extends MobileScannerPlatform { } final MediaStreamTrack videoTrack = tracks.first; - final MediaTrackCapabilities capabilities = videoTrack.getCapabilities(); + final MediaTrackCapabilities capabilities; - // TODO: this is empty on MacOS, where there is no facing mode, but one, user facing camera. + if (videoTrack.getCapabilitiesNullable != null) { + capabilities = videoTrack.getCapabilities(); + } else { + capabilities = MediaTrackCapabilities(); + } + + final JSArray? facingModes = capabilities.facingModeNullable; + + // TODO: this is an empty array on MacOS Chrome, where there is no facing mode, but one, user facing camera. // Facing mode is not supported by this track, do nothing. - if (capabilities.facingMode.toDart.isEmpty) { + if (facingModes == null || facingModes.toDart.isEmpty) { return; } diff --git a/pubspec.yaml b/pubspec.yaml index 33b425138..d834e2d63 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mobile_scanner description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. -version: 5.0.0-beta.3 +version: 5.0.0 repository: https://github.com/juliansteenbakker/mobile_scanner screenshots: