Skip to content

Commit

Permalink
Add check flag for permission to prevent multiple requests
Browse files Browse the repository at this point in the history
  • Loading branch information
iarata committed Oct 30, 2024
1 parent e01f132 commit 22f3587
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/app_usage/example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"app_usage","path":"/Users/hoffmatteo/Desktop/CACHET/flutter-plugins/packages/app_usage/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"app_usage","dependencies":[]}],"date_created":"2023-07-20 21:35:52.362642","version":"3.10.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"app_usage","path":"/Users/arata/Developer/carp/flutter-plugins/packages/app_usage/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"app_usage","dependencies":[]}],"date_created":"2024-10-30 13:38:21.146381","version":"3.24.3","swift_package_manager_enabled":false}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
null
private lateinit var healthConnectClient: HealthConnectClient
private lateinit var scope: CoroutineScope
private var isReplySubmitted = false


override fun onAttachedToEngine(
Expand Down Expand Up @@ -219,15 +220,18 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
}

private fun onHealthConnectPermissionCallback(permissionGranted: Set<String>) {
if (permissionGranted.isEmpty()) {
mResult?.success(false)
Log.i("FLUTTER_HEALTH", "Health Connect permissions were not granted! Make sure to declare the required permissions in the AndroidManifest.xml file.")
} else {
mResult?.success(true)
Log.i("FLUTTER_HEALTH", "${permissionGranted.size} Health Connect permissions were granted!")

// log the permissions granted for debugging
Log.i("FLUTTER_HEALTH", "Permissions granted: $permissionGranted")
if (!isReplySubmitted) {
if (permissionGranted.isEmpty()) {
mResult?.success(false)
Log.i("FLUTTER_HEALTH", "Health Connect permissions were not granted! Make sure to declare the required permissions in the AndroidManifest.xml file.")
} else {
mResult?.success(true)
Log.i("FLUTTER_HEALTH", "${permissionGranted.size} Health Connect permissions were granted!")

// log the permissions granted for debugging
Log.i("FLUTTER_HEALTH", "Permissions granted: $permissionGranted")
}
isReplySubmitted = true
}
}

Expand Down Expand Up @@ -666,6 +670,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :

// Store the result to be called in [onHealthConnectPermissionCallback]
mResult = result
isReplySubmitted = false
healthConnectRequestPermissionsLauncher!!.launch(permList.toSet())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"notifications","path":"/Users/bardram/dev/flutter-plugins/packages/notifications/","dependencies":[]}],"android":[{"name":"notifications","path":"/Users/bardram/dev/flutter-plugins/packages/notifications/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"notifications","dependencies":[]}],"date_created":"2021-07-22 09:08:42.769208","version":"2.2.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"notifications","path":"/Users/arata/Developer/carp/flutter-plugins/packages/notifications/","native_build":true,"dependencies":[]}],"android":[{"name":"notifications","path":"/Users/arata/Developer/carp/flutter-plugins/packages/notifications/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"notifications","dependencies":[]}],"date_created":"2024-10-30 13:38:55.333244","version":"3.24.3","swift_package_manager_enabled":false}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/hoffmatteo/dev/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/hoffmatteo/Desktop/CACHET/flutter-plugins/packages/notifications/example"
export "FLUTTER_ROOT=/opt/homebrew/Caskroom/flutter/3.24.3/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/arata/Developer/carp/flutter-plugins/packages/notifications/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
Expand Down
2 changes: 1 addition & 1 deletion packages/pedometer/example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"pedometer","path":"/Users/bardram/dev/flutter-plugins/packages/pedometer/","native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/bardram/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.5/","native_build":true,"dependencies":[]}],"android":[{"name":"pedometer","path":"/Users/bardram/dev/flutter-plugins/packages/pedometer/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/bardram/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.7/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[{"name":"permission_handler_windows","path":"/Users/bardram/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/","native_build":true,"dependencies":[]}],"web":[{"name":"permission_handler_html","path":"/Users/bardram/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"pedometer","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2024-07-31 13:12:00.381228","version":"3.22.2"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"pedometer","path":"/Users/arata/Developer/carp/flutter-plugins/packages/pedometer/","native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/arata/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.5/","native_build":true,"dependencies":[]}],"android":[{"name":"pedometer","path":"/Users/arata/Developer/carp/flutter-plugins/packages/pedometer/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/arata/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.13/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[{"name":"permission_handler_windows","path":"/Users/arata/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/","native_build":true,"dependencies":[]}],"web":[{"name":"permission_handler_html","path":"/Users/arata/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.3+2/","dependencies":[]}]},"dependencyGraph":[{"name":"pedometer","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2024-10-30 13:38:57.617363","version":"3.24.3","swift_package_manager_enabled":false}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/bardram/dev/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/bardram/dev/flutter-plugins/packages/pedometer/example"
export "FLUTTER_ROOT=/opt/homebrew/Caskroom/flutter/3.24.3/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/arata/Developer/carp/flutter-plugins/packages/pedometer/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
Expand Down

0 comments on commit 22f3587

Please sign in to comment.