@capgo/capacitor-health 7.2.14 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  s.frameworks = 'HealthKit'
package/Package.swift CHANGED
@@ -3,14 +3,14 @@ import PackageDescription
3
3
 
4
4
  let package = Package(
5
5
  name: "CapgoCapacitorHealth",
6
- platforms: [.iOS(.v14)],
6
+ platforms: [.iOS(.v15)],
7
7
  products: [
8
8
  .library(
9
9
  name: "CapgoCapacitorHealth",
10
10
  targets: ["HealthPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
14
  ],
15
15
  targets: [
16
16
  .target(
@@ -14,7 +14,7 @@ buildscript {
14
14
  mavenCentral()
15
15
  }
16
16
  dependencies {
17
- classpath 'com.android.tools.build:gradle:8.7.2'
17
+ classpath 'com.android.tools.build:gradle:8.13.0'
18
18
  classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24'
19
19
  }
20
20
  }
@@ -23,12 +23,12 @@ apply plugin: 'com.android.library'
23
23
  apply plugin: 'org.jetbrains.kotlin.android'
24
24
 
25
25
  android {
26
- namespace "app.capgo.plugin.health"
27
- compileSdk 35
26
+ namespace = "app.capgo.plugin.health"
27
+ compileSdk = 36
28
28
 
29
29
  defaultConfig {
30
30
  minSdk 26
31
- targetSdk 35
31
+ targetSdk 36
32
32
  versionCode 1
33
33
  versionName "1.0"
34
34
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -40,7 +40,7 @@ android {
40
40
  }
41
41
  }
42
42
  lint {
43
- abortOnError false
43
+ abortOnError = false
44
44
  }
45
45
  compileOptions {
46
46
  sourceCompatibility JavaVersion.VERSION_21
@@ -2,14 +2,16 @@ package app.capgo.plugin.health
2
2
 
3
3
  import android.app.Activity
4
4
  import android.content.Intent
5
+ import androidx.activity.result.ActivityResult
5
6
  import com.getcapacitor.JSArray
6
7
  import com.getcapacitor.JSObject
7
8
  import com.getcapacitor.Plugin
8
9
  import com.getcapacitor.PluginCall
9
10
  import com.getcapacitor.PluginMethod
11
+ import com.getcapacitor.annotation.ActivityCallback
10
12
  import com.getcapacitor.annotation.CapacitorPlugin
11
13
  import androidx.health.connect.client.HealthConnectClient
12
- import androidx.health.connect.client.contracts.HealthPermissionsRequestContract
14
+ import androidx.health.connect.client.PermissionController
13
15
  import java.time.Instant
14
16
  import java.time.Duration
15
17
  import java.time.format.DateTimeParseException
@@ -18,15 +20,17 @@ import kotlinx.coroutines.Dispatchers
18
20
  import kotlinx.coroutines.SupervisorJob
19
21
  import kotlinx.coroutines.cancel
20
22
  import kotlinx.coroutines.launch
21
- import kotlinx.coroutines.withContext
22
23
 
23
24
  @CapacitorPlugin(name = "Health")
24
25
  class HealthPlugin : Plugin() {
25
- private val pluginVersion = "7.2.5"
26
+ private val pluginVersion = "7.2.14"
26
27
  private val manager = HealthManager()
27
28
  private val pluginScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
28
- private var pendingAuthorization: PendingAuthorization? = null
29
- private val permissionRequestContract = HealthPermissionsRequestContract()
29
+ private val permissionContract = PermissionController.createRequestPermissionResultContract()
30
+
31
+ // Store pending request data for callback
32
+ private var pendingReadTypes: List<HealthDataType> = emptyList()
33
+ private var pendingWriteTypes: List<HealthDataType> = emptyList()
30
34
 
31
35
  override fun handleOnDestroy() {
32
36
  super.handleOnDestroy()
@@ -72,35 +76,41 @@ class HealthPlugin : Plugin() {
72
76
  return@launch
73
77
  }
74
78
 
75
- val activity = activity
76
- if (activity == null) {
77
- call.reject("Unable to request authorization without an active Activity.")
78
- return@launch
79
- }
79
+ // Store types for callback
80
+ pendingReadTypes = readTypes
81
+ pendingWriteTypes = writeTypes
80
82
 
81
- if (pendingAuthorization != null) {
82
- call.reject("Another authorization request is already running. Try again later.")
83
- return@launch
84
- }
83
+ // Create intent using the Health Connect permission contract
84
+ val intent = permissionContract.createIntent(context, permissions)
85
85
 
86
- val intent = withContext(Dispatchers.IO) {
87
- permissionRequestContract.createIntent(activity, permissions)
88
- }
89
- pendingAuthorization = PendingAuthorization(call, readTypes, writeTypes)
90
- call.setKeepAlive(true)
91
-
92
- withContext(Dispatchers.Main) {
93
- try {
94
- activity.startActivityForResult(intent, REQUEST_AUTHORIZATION)
95
- } catch (e: Exception) {
96
- pendingAuthorization = null
97
- call.setKeepAlive(false)
98
- call.reject("Failed to launch Health Connect permission request.", null, e)
99
- }
86
+ try {
87
+ startActivityForResult(call, intent, "handlePermissionResult")
88
+ } catch (e: Exception) {
89
+ pendingReadTypes = emptyList()
90
+ pendingWriteTypes = emptyList()
91
+ call.reject("Failed to launch Health Connect permission request.", null, e)
100
92
  }
101
93
  }
102
94
  }
103
95
 
96
+ @ActivityCallback
97
+ private fun handlePermissionResult(call: PluginCall?, result: ActivityResult) {
98
+ if (call == null) {
99
+ return
100
+ }
101
+
102
+ val readTypes = pendingReadTypes
103
+ val writeTypes = pendingWriteTypes
104
+ pendingReadTypes = emptyList()
105
+ pendingWriteTypes = emptyList()
106
+
107
+ pluginScope.launch {
108
+ val client = getClientOrReject(call) ?: return@launch
109
+ val status = manager.authorizationStatus(client, readTypes, writeTypes)
110
+ call.resolve(status)
111
+ }
112
+ }
113
+
104
114
  @PluginMethod
105
115
  fun checkAuthorization(call: PluginCall) {
106
116
  val readTypes = try {
@@ -242,28 +252,6 @@ class HealthPlugin : Plugin() {
242
252
  }
243
253
  }
244
254
 
245
- override fun handleOnActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
246
- super.handleOnActivityResult(requestCode, resultCode, data)
247
- if (requestCode != REQUEST_AUTHORIZATION) {
248
- return
249
- }
250
-
251
- val pending = pendingAuthorization ?: return
252
- pendingAuthorization = null
253
- pending.call.setKeepAlive(false)
254
-
255
- pluginScope.launch {
256
- val client = getClientOrReject(pending.call) ?: return@launch
257
- if (resultCode != Activity.RESULT_OK) {
258
- pending.call.reject("Authorization request was cancelled or denied.")
259
- return@launch
260
- }
261
-
262
- val status = manager.authorizationStatus(client, pending.readTypes, pending.writeTypes)
263
- pending.call.resolve(status)
264
- }
265
- }
266
-
267
255
  private fun parseTypeList(call: PluginCall, key: String): List<HealthDataType> {
268
256
  val array = call.getArray(key) ?: JSArray()
269
257
  val result = mutableListOf<HealthDataType>()
@@ -303,12 +291,6 @@ class HealthPlugin : Plugin() {
303
291
  }
304
292
  }
305
293
 
306
- private data class PendingAuthorization(
307
- val call: PluginCall,
308
- val readTypes: List<HealthDataType>,
309
- val writeTypes: List<HealthDataType>
310
- )
311
-
312
294
  @PluginMethod
313
295
  fun getPluginVersion(call: PluginCall) {
314
296
  try {
@@ -321,7 +303,6 @@ class HealthPlugin : Plugin() {
321
303
  }
322
304
 
323
305
  companion object {
324
- private const val REQUEST_AUTHORIZATION = 9501
325
306
  private const val DEFAULT_LIMIT = 100
326
307
  private val DEFAULT_PAST_DURATION: Duration = Duration.ofDays(1)
327
308
  }
@@ -1,5 +1,5 @@
1
- export declare type HealthDataType = 'steps' | 'distance' | 'calories' | 'heartRate' | 'weight';
2
- export declare type HealthUnit = 'count' | 'meter' | 'kilocalorie' | 'bpm' | 'kilogram';
1
+ export type HealthDataType = 'steps' | 'distance' | 'calories' | 'heartRate' | 'weight';
2
+ export type HealthUnit = 'count' | 'meter' | 'kilocalorie' | 'bpm' | 'kilogram';
3
3
  export interface AuthorizationOptions {
4
4
  /** Data types that should be readable after authorization. */
5
5
  read?: HealthDataType[];
@@ -3,7 +3,7 @@ import Capacitor
3
3
 
4
4
  @objc(HealthPlugin)
5
5
  public class HealthPlugin: CAPPlugin, CAPBridgedPlugin {
6
- private let pluginVersion: String = "7.2.14"
6
+ private let pluginVersion: String = "8.0.1"
7
7
  public let identifier = "HealthPlugin"
8
8
  public let jsName = "Health"
9
9
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-health",
3
- "version": "7.2.14",
3
+ "version": "8.0.1",
4
4
  "description": "Capacitor plugin to interact with data from Apple HealthKit and Health Connect",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -46,23 +46,25 @@
46
46
  "prepublishOnly": "npm run build"
47
47
  },
48
48
  "devDependencies": {
49
- "@capacitor/android": "^7.0.0",
50
- "@capacitor/core": "^7.0.0",
51
- "@capacitor/docgen": "^0.3.0",
52
- "@capacitor/ios": "^7.0.0",
49
+ "@capacitor/android": "^8.0.0",
50
+ "@capacitor/core": "^8.0.0",
51
+ "@capacitor/docgen": "^0.3.1",
52
+ "@capacitor/ios": "^8.0.0",
53
53
  "@ionic/eslint-config": "^0.4.0",
54
54
  "@ionic/prettier-config": "^4.0.0",
55
55
  "@ionic/swiftlint-config": "^2.0.0",
56
- "eslint": "^8.57.0",
57
- "prettier": "^3.4.2",
58
- "prettier-plugin-java": "^2.6.6",
59
- "rimraf": "^6.0.1",
60
- "rollup": "^4.30.1",
56
+ "@types/node": "^24.10.1",
57
+ "eslint": "^8.57.1",
58
+ "eslint-plugin-import": "^2.31.0",
59
+ "prettier": "^3.6.2",
60
+ "prettier-plugin-java": "^2.7.7",
61
+ "rimraf": "^6.1.0",
62
+ "rollup": "^4.53.2",
61
63
  "swiftlint": "^2.0.0",
62
- "typescript": "~4.1.5"
64
+ "typescript": "^5.9.3"
63
65
  },
64
66
  "peerDependencies": {
65
- "@capacitor/core": ">=7.0.0"
67
+ "@capacitor/core": ">=8.0.0"
66
68
  },
67
69
  "prettier": "@ionic/prettier-config",
68
70
  "swiftlint": "@ionic/swiftlint-config",