diff --git a/permission_handler/CHANGELOG.md b/permission_handler/CHANGELOG.md index d86f9e320..8612c6e34 100644 --- a/permission_handler/CHANGELOG.md +++ b/permission_handler/CHANGELOG.md @@ -1,3 +1,7 @@ +## 11.0.1 + +* Add linux platform support with `permission_handler_default`. + ## 11.0.0 * **BREAKING CHANGE:** Updates `permission_handler_android` dependency to version 11.0.0. diff --git a/permission_handler/pubspec.yaml b/permission_handler/pubspec.yaml index 95180d6ac..c36f44333 100644 --- a/permission_handler/pubspec.yaml +++ b/permission_handler/pubspec.yaml @@ -17,6 +17,8 @@ flutter: default_package: permission_handler_apple windows: default_package: permission_handler_windows + linux: + default_package: permission_handler_default dependencies: flutter: @@ -25,6 +27,7 @@ dependencies: permission_handler_android: ^11.0.0 permission_handler_apple: ^9.1.4 permission_handler_windows: ^0.1.3 + permission_handler_default: ^0.0.1 permission_handler_platform_interface: ^3.11.5 dev_dependencies: diff --git a/permission_handler_default/CHANGELOG.md b/permission_handler_default/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/permission_handler_default/LICENSE b/permission_handler_default/LICENSE new file mode 100644 index 000000000..f150c8522 --- /dev/null +++ b/permission_handler_default/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Baseflow + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/permission_handler_default/README.md b/permission_handler_default/README.md new file mode 100644 index 000000000..821ea8a55 --- /dev/null +++ b/permission_handler_default/README.md @@ -0,0 +1,23 @@ +# permission_handler_web + +[![pub package](https://img.shields.io/pub/v/permission_handler_default.svg)](https://pub.dartlang.org/packages/permission_handler_default) ![Build status](https://github.com/Baseflow/flutter-permission-handler/workflows/permission_handler_default/badge.svg?branch=master) [![style: flutter lints](https://img.shields.io/badge/style-flutter_lints-40c4ff.svg)](https://pub.dev/packages/flutter_lints) + +The official default implementation of the [permission_handler](https://pub.dev/packages/permission_handler) plugin by [Baseflow](https://baseflow.com). + +## Usage + +This is the officially endorsed default implementation of the permission_handler plugin. This means it will automatically be added to your dependencies when you depend on `permission_handler` in your applications pubspec.yaml. + +More detailed instructions on using the API can be found in the [README.md](../permission_handler/README.md) of the [permission_handler](https://pub.dev/packages/permission_handler) package. + +## Issues + +Please file any issues, bugs or feature requests as an issue on our [GitHub](https://github.com/Baseflow/flutter-permission-handler/issues) page. Commercial support is available, you can contact us at . + +## Want to contribute + +If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Baseflow/flutter-permission-handler/pulls). + +## Author + +This permission_handler plugin for Flutter is developed by [Patrick Northon](northon_patrick3@yahoo.ca). diff --git a/permission_handler_default/lib/permission_handler_default.dart b/permission_handler_default/lib/permission_handler_default.dart new file mode 100644 index 000000000..b3f5dc30f --- /dev/null +++ b/permission_handler_default/lib/permission_handler_default.dart @@ -0,0 +1,43 @@ +import 'package:flutter/foundation.dart'; +import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; + +/// Platform implementation of the permission_handler Flutter plugin. +class DefaultPermissionHandler extends PermissionHandlerPlatform { + /// Registers the default plugin implementation. + static void registerWith() { + PermissionHandlerPlatform.instance = DefaultPermissionHandler(); + } + + @override + Future> requestPermissions( + List permissions) async { + final Map permissionStatusMap = {}; + + for (final permission in permissions) { + permissionStatusMap[permission] = PermissionStatus.granted; + } + + return SynchronousFuture(permissionStatusMap); + } + + @override + Future checkPermissionStatus(Permission permission) async { + return SynchronousFuture(PermissionStatus.granted); + } + + @override + Future checkServiceStatus(Permission permission) async { + return SynchronousFuture(ServiceStatus.enabled); + } + + @override + Future shouldShowRequestPermissionRationale( + Permission permission) async { + return SynchronousFuture(false); + } + + @override + Future openAppSettings() { + return SynchronousFuture(false); + } +} diff --git a/permission_handler_default/pubspec.yaml b/permission_handler_default/pubspec.yaml new file mode 100644 index 000000000..99e245b7e --- /dev/null +++ b/permission_handler_default/pubspec.yaml @@ -0,0 +1,33 @@ +name: permission_handler_default +description: Permission handler for platforms that don't have specific support. It assume that all permissions are granted. +version: 0.0.1 +homepage: + +environment: + sdk: '>=3.0.5 <4.0.0' + flutter: ">=3.3.0" + +dependencies: + flutter: + sdk: flutter + permission_handler_platform_interface: ^3.7.0 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + build_runner: ^2.1.2 + test: ^1.24.4 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + plugin: + implements: permission_handler + platforms: + linux: + dartPluginClass: DefaultPermissionHandler + fileName: permission_handler_default.dart diff --git a/permission_handler_default/test/permission_handler_default_test.dart b/permission_handler_default/test/permission_handler_default_test.dart new file mode 100644 index 000000000..e58865c81 --- /dev/null +++ b/permission_handler_default/test/permission_handler_default_test.dart @@ -0,0 +1,43 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; +import 'package:permission_handler_default/permission_handler_default.dart'; + +void main() { + final List testPermissions = [ + Permission.camera, + Permission.contacts, + Permission.location, + Permission.microphone, + Permission.notification, + ]; + + final plugin = DefaultPermissionHandler(); + + test('check permissions are all granted', () async { + final permissions = await plugin.requestPermissions(testPermissions); + + for (final status in permissions.values) { + expect(status, PermissionStatus.granted); + } + }); + + test('check services are all enabled.', () async { + for (final permission in testPermissions) { + final serviceStatus = await plugin.checkServiceStatus(permission); + expect(serviceStatus, ServiceStatus.enabled); + } + }); + + test('never show unsupported permission rational.', () async { + for (final permission in testPermissions) { + final shouldIt = + await plugin.shouldShowRequestPermissionRationale(permission); + expect(shouldIt, false); + } + }); + + test('never show unsupported app settings.', () async { + final appSettings = await plugin.openAppSettings(); + expect(appSettings, false); + }); +}