From 4e840aef8a1528ff3420b271f4f7b727879227cb Mon Sep 17 00:00:00 2001 From: holzgeist Date: Tue, 8 Oct 2024 10:50:02 +0200 Subject: [PATCH] fix: don't crash on safari<16 (#1383) * fix: don't crash on safari<16 * fix: apply PR Pre-launch Checklist --- permission_handler_html/CHANGELOG.md | 4 ++++ .../lib/permission_handler_html.dart | 12 ++++++++++-- permission_handler_html/pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/permission_handler_html/CHANGELOG.md b/permission_handler_html/CHANGELOG.md index 7ac095361..c82c2977d 100644 --- a/permission_handler_html/CHANGELOG.md +++ b/permission_handler_html/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.3+3 + +- Safari < 16 compatibility: Don't crash on missing `window.navigator.permissions` property + ## 0.1.3+2 - `web: 1.0.0` compatibility: `PermissionDescriptor` was removed in web package. diff --git a/permission_handler_html/lib/permission_handler_html.dart b/permission_handler_html/lib/permission_handler_html.dart index cfea4756a..814f01f27 100644 --- a/permission_handler_html/lib/permission_handler_html.dart +++ b/permission_handler_html/lib/permission_handler_html.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:js_interop_unsafe'; import 'package:web/web.dart' as web; @@ -12,8 +13,15 @@ import 'web_delegate.dart'; class WebPermissionHandler extends PermissionHandlerPlatform { static final web.MediaDevices _devices = web.window.navigator.mediaDevices; static final web.Geolocation _geolocation = web.window.navigator.geolocation; - static final web.Permissions _htmlPermissions = - web.window.navigator.permissions; + static final web.Permissions? _htmlPermissions = (() { + // Using unsafe interop to check availability of `permissions`. + // It's not defined as nullable, so merely loading it into a web.Permission? variable + // causes the null-check to fail + if (!web.window.navigator.has("permissions")) { + return null; + } + return web.window.navigator.permissions; + })(); final WebDelegate _webDelegate; diff --git a/permission_handler_html/pubspec.yaml b/permission_handler_html/pubspec.yaml index 77bdf6437..e77acd741 100644 --- a/permission_handler_html/pubspec.yaml +++ b/permission_handler_html/pubspec.yaml @@ -1,6 +1,6 @@ name: permission_handler_html description: Permission plugin for Flutter. This plugin provides the web API to request and check permissions. -version: 0.1.3+2 +version: 0.1.3+3 homepage: https://github.com/baseflow/flutter-permission-handler