@ovok/native 1.6.50 → 1.6.51

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.
Files changed (474) hide show
  1. package/README.md +21 -0
  2. package/lib/commonjs/index.js +18 -7
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/modules/auth/default-translation.js +6 -1
  5. package/lib/commonjs/modules/auth/default-translation.js.map +1 -1
  6. package/lib/commonjs/modules/auth/delete-account-button/components/delete-account-button.js +9 -14
  7. package/lib/commonjs/modules/auth/delete-account-button/components/delete-account-button.js.map +1 -1
  8. package/lib/commonjs/modules/auth/hooks/use-auth-action.js +41 -0
  9. package/lib/commonjs/modules/auth/hooks/use-auth-action.js.map +1 -0
  10. package/lib/commonjs/modules/auth/hooks/use-delete-account.js +27 -0
  11. package/lib/commonjs/modules/auth/hooks/use-delete-account.js.map +1 -0
  12. package/lib/commonjs/modules/auth/hooks/use-session.js +14 -86
  13. package/lib/commonjs/modules/auth/hooks/use-session.js.map +1 -1
  14. package/lib/commonjs/modules/auth/hooks/use-sign-in.js +66 -0
  15. package/lib/commonjs/modules/auth/hooks/use-sign-in.js.map +1 -0
  16. package/lib/commonjs/modules/auth/hooks/use-sign-out.js +15 -0
  17. package/lib/commonjs/modules/auth/hooks/use-sign-out.js.map +1 -0
  18. package/lib/commonjs/modules/auth/hooks/use-social-sign-in.js +92 -0
  19. package/lib/commonjs/modules/auth/hooks/use-social-sign-in.js.map +1 -0
  20. package/lib/commonjs/modules/auth/index.js +55 -0
  21. package/lib/commonjs/modules/auth/index.js.map +1 -1
  22. package/lib/commonjs/modules/auth/logout-button/components/logout-button.js +11 -16
  23. package/lib/commonjs/modules/auth/logout-button/components/logout-button.js.map +1 -1
  24. package/lib/commonjs/modules/auth/profile/components/profile-form-provider.js +5 -3
  25. package/lib/commonjs/modules/auth/profile/components/profile-form-provider.js.map +1 -1
  26. package/lib/commonjs/modules/auth/profile/contexts/profile-form-context.js +1 -1
  27. package/lib/commonjs/modules/auth/profile/contexts/profile-form-context.js.map +1 -1
  28. package/lib/commonjs/modules/auth/profile/hooks/use-profile-form.js +1 -1
  29. package/lib/commonjs/modules/auth/profile/hooks/use-profile-form.js.map +1 -1
  30. package/lib/commonjs/modules/auth/register/components/form/register-form-provider.js +6 -4
  31. package/lib/commonjs/modules/auth/register/components/form/register-form-provider.js.map +1 -1
  32. package/lib/commonjs/modules/auth/reset-password/components/form/inputs.js +2 -4
  33. package/lib/commonjs/modules/auth/reset-password/components/form/inputs.js.map +1 -1
  34. package/lib/commonjs/modules/auth/reset-password/components/form/reset-password-form-provider.js +6 -4
  35. package/lib/commonjs/modules/auth/reset-password/components/form/reset-password-form-provider.js.map +1 -1
  36. package/lib/commonjs/modules/auth/reset-password/contexts/reset-password-form-context.js +1 -1
  37. package/lib/commonjs/modules/auth/reset-password/contexts/reset-password-form-context.js.map +1 -1
  38. package/lib/commonjs/modules/auth/reset-password/hooks/use-reset-password-form.js +1 -1
  39. package/lib/commonjs/modules/auth/reset-password/hooks/use-reset-password-form.js.map +1 -1
  40. package/lib/commonjs/modules/auth/session/logout-session.js +29 -0
  41. package/lib/commonjs/modules/auth/session/logout-session.js.map +1 -0
  42. package/lib/commonjs/modules/auth/session/session-store.js +152 -0
  43. package/lib/commonjs/modules/auth/session/session-store.js.map +1 -0
  44. package/lib/commonjs/modules/auth/sign-in/components/form/login-form-provider.js +25 -41
  45. package/lib/commonjs/modules/auth/sign-in/components/form/login-form-provider.js.map +1 -1
  46. package/lib/commonjs/modules/auth/sign-in/components/social-logins/apple-login-button.js +13 -12
  47. package/lib/commonjs/modules/auth/sign-in/components/social-logins/apple-login-button.js.map +1 -1
  48. package/lib/commonjs/modules/auth/sign-in/components/social-logins/google-login-button.js +4 -4
  49. package/lib/commonjs/modules/auth/sign-in/components/social-logins/google-login-button.js.map +1 -1
  50. package/lib/commonjs/modules/auth/sign-in/contexts/login-form-context.js +1 -1
  51. package/lib/commonjs/modules/auth/sign-in/contexts/login-form-context.js.map +1 -1
  52. package/lib/commonjs/modules/auth/sign-in/hooks/use-login-form.js +1 -1
  53. package/lib/commonjs/modules/auth/sign-in/hooks/use-login-form.js.map +1 -1
  54. package/lib/commonjs/modules/bt-device/components/device-list-provider.js +5 -4
  55. package/lib/commonjs/modules/bt-device/components/device-list-provider.js.map +1 -1
  56. package/lib/commonjs/modules/bt-device/components/hooks/use-device-list.js +1 -1
  57. package/lib/commonjs/modules/bt-device/components/hooks/use-device-list.js.map +1 -1
  58. package/lib/commonjs/modules/bt-device/contexts/device-list-context.js +1 -4
  59. package/lib/commonjs/modules/bt-device/contexts/device-list-context.js.map +1 -1
  60. package/lib/commonjs/modules/bt-management/components/bt-provider-child-wrapper.js +176 -84
  61. package/lib/commonjs/modules/bt-management/components/bt-provider-child-wrapper.js.map +1 -1
  62. package/lib/commonjs/modules/bt-management/components/bt-provider.js +3 -2
  63. package/lib/commonjs/modules/bt-management/components/bt-provider.js.map +1 -1
  64. package/lib/commonjs/modules/bt-management/hooks/runtime-context.js +146 -14
  65. package/lib/commonjs/modules/bt-management/hooks/runtime-context.js.map +1 -1
  66. package/lib/commonjs/modules/bt-management/hooks/use-background-sync.js +17 -11
  67. package/lib/commonjs/modules/bt-management/hooks/use-background-sync.js.map +1 -1
  68. package/lib/commonjs/modules/bt-management/hooks/use-bluetooth-permission.js +100 -0
  69. package/lib/commonjs/modules/bt-management/hooks/use-bluetooth-permission.js.map +1 -0
  70. package/lib/commonjs/modules/bt-management/hooks/use-bluetooth-state.js +13 -26
  71. package/lib/commonjs/modules/bt-management/hooks/use-bluetooth-state.js.map +1 -1
  72. package/lib/commonjs/modules/bt-management/hooks/use-bt-device.js +148 -0
  73. package/lib/commonjs/modules/bt-management/hooks/use-bt-device.js.map +1 -0
  74. package/lib/commonjs/modules/bt-management/hooks/use-device-connection.js +10 -26
  75. package/lib/commonjs/modules/bt-management/hooks/use-device-connection.js.map +1 -1
  76. package/lib/commonjs/modules/bt-management/hooks/use-health-import.js +7 -76
  77. package/lib/commonjs/modules/bt-management/hooks/use-health-import.js.map +1 -1
  78. package/lib/commonjs/modules/bt-management/hooks/use-measurements.js +43 -57
  79. package/lib/commonjs/modules/bt-management/hooks/use-measurements.js.map +1 -1
  80. package/lib/commonjs/modules/bt-management/hooks/use-nearby-devices.js +12 -16
  81. package/lib/commonjs/modules/bt-management/hooks/use-nearby-devices.js.map +1 -1
  82. package/lib/commonjs/modules/bt-management/hooks/use-paired-devices.js +31 -12
  83. package/lib/commonjs/modules/bt-management/hooks/use-paired-devices.js.map +1 -1
  84. package/lib/commonjs/modules/bt-management/hooks/use-request-permissions.js +12 -55
  85. package/lib/commonjs/modules/bt-management/hooks/use-request-permissions.js.map +1 -1
  86. package/lib/commonjs/modules/bt-management/hooks/use-scan-control.js +6 -4
  87. package/lib/commonjs/modules/bt-management/hooks/use-scan-control.js.map +1 -1
  88. package/lib/commonjs/modules/bt-management/index.js +133 -11
  89. package/lib/commonjs/modules/bt-management/index.js.map +1 -1
  90. package/lib/commonjs/modules/cms/hooks/use-cms-content.js +50 -0
  91. package/lib/commonjs/modules/cms/hooks/use-cms-content.js.map +1 -0
  92. package/lib/commonjs/modules/cms/hooks/use-cms-locale.js +20 -0
  93. package/lib/commonjs/modules/cms/hooks/use-cms-locale.js.map +1 -0
  94. package/lib/commonjs/modules/cms/hooks/use-cms-translations.js +50 -0
  95. package/lib/commonjs/modules/cms/hooks/use-cms-translations.js.map +1 -0
  96. package/lib/commonjs/modules/cms/index.js +39 -0
  97. package/lib/commonjs/modules/cms/index.js.map +1 -0
  98. package/lib/commonjs/modules/cms/merge-cms-translations.js +49 -0
  99. package/lib/commonjs/modules/cms/merge-cms-translations.js.map +1 -0
  100. package/lib/commonjs/modules/data-sync/components/android/android-health-connect-authorization-provider.js +23 -18
  101. package/lib/commonjs/modules/data-sync/components/android/android-health-connect-authorization-provider.js.map +1 -1
  102. package/lib/commonjs/modules/data-sync/components/apple/apple-health-authorization-provider.js +19 -18
  103. package/lib/commonjs/modules/data-sync/components/apple/apple-health-authorization-provider.js.map +1 -1
  104. package/lib/commonjs/modules/data-sync/components/apple/apple-health-authorization-utils.js +20 -0
  105. package/lib/commonjs/modules/data-sync/components/apple/apple-health-authorization-utils.js.map +1 -0
  106. package/lib/commonjs/modules/data-sync/contexts/health-authorization-context.js +18 -0
  107. package/lib/commonjs/modules/data-sync/contexts/health-authorization-context.js.map +1 -0
  108. package/lib/commonjs/modules/data-sync/hooks/use-health-import.js +81 -0
  109. package/lib/commonjs/modules/data-sync/hooks/use-health-import.js.map +1 -0
  110. package/lib/commonjs/modules/data-sync/index.js +37 -0
  111. package/lib/commonjs/modules/data-sync/index.js.map +1 -1
  112. package/lib/commonjs/modules/helpers/hooks/use-shallow-stable-value.js +20 -0
  113. package/lib/commonjs/modules/helpers/hooks/use-shallow-stable-value.js.map +1 -0
  114. package/lib/commonjs/modules/language-switcher/components/language-switcher.js +12 -4
  115. package/lib/commonjs/modules/language-switcher/components/language-switcher.js.map +1 -1
  116. package/lib/commonjs/modules/language-switcher/components/option/context/language-option-context.js +1 -1
  117. package/lib/commonjs/modules/language-switcher/components/option/context/language-option-context.js.map +1 -1
  118. package/lib/commonjs/modules/language-switcher/components/option/language-switcher-option.js +5 -4
  119. package/lib/commonjs/modules/language-switcher/components/option/language-switcher-option.js.map +1 -1
  120. package/lib/commonjs/modules/socket/components/socket-provider.js +78 -73
  121. package/lib/commonjs/modules/socket/components/socket-provider.js.map +1 -1
  122. package/lib/commonjs/modules/tab/components/tab-provider.js +12 -1
  123. package/lib/commonjs/modules/tab/components/tab-provider.js.map +1 -1
  124. package/lib/commonjs/modules/tab/contexts/tab-context.js +1 -1
  125. package/lib/commonjs/modules/tab/contexts/tab-context.js.map +1 -1
  126. package/lib/commonjs/modules/tab/hooks/use-tab.js +1 -1
  127. package/lib/commonjs/modules/tab/hooks/use-tab.js.map +1 -1
  128. package/lib/commonjs/modules/ui/components/health-import-card.js +2 -3
  129. package/lib/commonjs/modules/ui/components/health-import-card.js.map +1 -1
  130. package/lib/commonjs/modules/ui/components/pairing-flow.js.map +1 -1
  131. package/lib/module/index.js +1 -0
  132. package/lib/module/index.js.map +1 -1
  133. package/lib/module/modules/auth/default-translation.js +3 -1
  134. package/lib/module/modules/auth/default-translation.js.map +1 -1
  135. package/lib/module/modules/auth/delete-account-button/components/delete-account-button.js +9 -14
  136. package/lib/module/modules/auth/delete-account-button/components/delete-account-button.js.map +1 -1
  137. package/lib/module/modules/auth/hooks/use-auth-action.js +36 -0
  138. package/lib/module/modules/auth/hooks/use-auth-action.js.map +1 -0
  139. package/lib/module/modules/auth/hooks/use-delete-account.js +22 -0
  140. package/lib/module/modules/auth/hooks/use-delete-account.js.map +1 -0
  141. package/lib/module/modules/auth/hooks/use-session.js +17 -88
  142. package/lib/module/modules/auth/hooks/use-session.js.map +1 -1
  143. package/lib/module/modules/auth/hooks/use-sign-in.js +61 -0
  144. package/lib/module/modules/auth/hooks/use-sign-in.js.map +1 -0
  145. package/lib/module/modules/auth/hooks/use-sign-out.js +10 -0
  146. package/lib/module/modules/auth/hooks/use-sign-out.js.map +1 -0
  147. package/lib/module/modules/auth/hooks/use-social-sign-in.js +86 -0
  148. package/lib/module/modules/auth/hooks/use-social-sign-in.js.map +1 -0
  149. package/lib/module/modules/auth/index.js +5 -0
  150. package/lib/module/modules/auth/index.js.map +1 -1
  151. package/lib/module/modules/auth/logout-button/components/logout-button.js +11 -16
  152. package/lib/module/modules/auth/logout-button/components/logout-button.js.map +1 -1
  153. package/lib/module/modules/auth/profile/components/profile-form-provider.js +5 -3
  154. package/lib/module/modules/auth/profile/components/profile-form-provider.js.map +1 -1
  155. package/lib/module/modules/auth/profile/contexts/profile-form-context.js +1 -1
  156. package/lib/module/modules/auth/profile/contexts/profile-form-context.js.map +1 -1
  157. package/lib/module/modules/auth/profile/hooks/use-profile-form.js +1 -1
  158. package/lib/module/modules/auth/profile/hooks/use-profile-form.js.map +1 -1
  159. package/lib/module/modules/auth/register/components/form/register-form-provider.js +6 -4
  160. package/lib/module/modules/auth/register/components/form/register-form-provider.js.map +1 -1
  161. package/lib/module/modules/auth/reset-password/components/form/inputs.js +2 -4
  162. package/lib/module/modules/auth/reset-password/components/form/inputs.js.map +1 -1
  163. package/lib/module/modules/auth/reset-password/components/form/reset-password-form-provider.js +6 -4
  164. package/lib/module/modules/auth/reset-password/components/form/reset-password-form-provider.js.map +1 -1
  165. package/lib/module/modules/auth/reset-password/contexts/reset-password-form-context.js +1 -1
  166. package/lib/module/modules/auth/reset-password/contexts/reset-password-form-context.js.map +1 -1
  167. package/lib/module/modules/auth/reset-password/hooks/use-reset-password-form.js +1 -1
  168. package/lib/module/modules/auth/reset-password/hooks/use-reset-password-form.js.map +1 -1
  169. package/lib/module/modules/auth/session/logout-session.js +24 -0
  170. package/lib/module/modules/auth/session/logout-session.js.map +1 -0
  171. package/lib/module/modules/auth/session/session-store.js +148 -0
  172. package/lib/module/modules/auth/session/session-store.js.map +1 -0
  173. package/lib/module/modules/auth/sign-in/components/form/login-form-provider.js +25 -41
  174. package/lib/module/modules/auth/sign-in/components/form/login-form-provider.js.map +1 -1
  175. package/lib/module/modules/auth/sign-in/components/social-logins/apple-login-button.js +13 -12
  176. package/lib/module/modules/auth/sign-in/components/social-logins/apple-login-button.js.map +1 -1
  177. package/lib/module/modules/auth/sign-in/components/social-logins/google-login-button.js +4 -4
  178. package/lib/module/modules/auth/sign-in/components/social-logins/google-login-button.js.map +1 -1
  179. package/lib/module/modules/auth/sign-in/contexts/login-form-context.js +1 -1
  180. package/lib/module/modules/auth/sign-in/contexts/login-form-context.js.map +1 -1
  181. package/lib/module/modules/auth/sign-in/hooks/use-login-form.js +1 -1
  182. package/lib/module/modules/auth/sign-in/hooks/use-login-form.js.map +1 -1
  183. package/lib/module/modules/bt-device/components/device-list-provider.js +5 -4
  184. package/lib/module/modules/bt-device/components/device-list-provider.js.map +1 -1
  185. package/lib/module/modules/bt-device/components/hooks/use-device-list.js +1 -1
  186. package/lib/module/modules/bt-device/components/hooks/use-device-list.js.map +1 -1
  187. package/lib/module/modules/bt-device/contexts/device-list-context.js +1 -4
  188. package/lib/module/modules/bt-device/contexts/device-list-context.js.map +1 -1
  189. package/lib/module/modules/bt-management/components/bt-provider-child-wrapper.js +175 -84
  190. package/lib/module/modules/bt-management/components/bt-provider-child-wrapper.js.map +1 -1
  191. package/lib/module/modules/bt-management/components/bt-provider.js +3 -2
  192. package/lib/module/modules/bt-management/components/bt-provider.js.map +1 -1
  193. package/lib/module/modules/bt-management/hooks/runtime-context.js +144 -13
  194. package/lib/module/modules/bt-management/hooks/runtime-context.js.map +1 -1
  195. package/lib/module/modules/bt-management/hooks/use-background-sync.js +17 -11
  196. package/lib/module/modules/bt-management/hooks/use-background-sync.js.map +1 -1
  197. package/lib/module/modules/bt-management/hooks/use-bluetooth-permission.js +94 -0
  198. package/lib/module/modules/bt-management/hooks/use-bluetooth-permission.js.map +1 -0
  199. package/lib/module/modules/bt-management/hooks/use-bluetooth-state.js +13 -26
  200. package/lib/module/modules/bt-management/hooks/use-bluetooth-state.js.map +1 -1
  201. package/lib/module/modules/bt-management/hooks/use-bt-device.js +142 -0
  202. package/lib/module/modules/bt-management/hooks/use-bt-device.js.map +1 -0
  203. package/lib/module/modules/bt-management/hooks/use-device-connection.js +11 -26
  204. package/lib/module/modules/bt-management/hooks/use-device-connection.js.map +1 -1
  205. package/lib/module/modules/bt-management/hooks/use-health-import.js +2 -73
  206. package/lib/module/modules/bt-management/hooks/use-health-import.js.map +1 -1
  207. package/lib/module/modules/bt-management/hooks/use-measurements.js +44 -58
  208. package/lib/module/modules/bt-management/hooks/use-measurements.js.map +1 -1
  209. package/lib/module/modules/bt-management/hooks/use-nearby-devices.js +13 -17
  210. package/lib/module/modules/bt-management/hooks/use-nearby-devices.js.map +1 -1
  211. package/lib/module/modules/bt-management/hooks/use-paired-devices.js +31 -12
  212. package/lib/module/modules/bt-management/hooks/use-paired-devices.js.map +1 -1
  213. package/lib/module/modules/bt-management/hooks/use-request-permissions.js +12 -54
  214. package/lib/module/modules/bt-management/hooks/use-request-permissions.js.map +1 -1
  215. package/lib/module/modules/bt-management/hooks/use-scan-control.js +6 -4
  216. package/lib/module/modules/bt-management/hooks/use-scan-control.js.map +1 -1
  217. package/lib/module/modules/bt-management/index.js +8 -1
  218. package/lib/module/modules/bt-management/index.js.map +1 -1
  219. package/lib/module/modules/cms/hooks/use-cms-content.js +44 -0
  220. package/lib/module/modules/cms/hooks/use-cms-content.js.map +1 -0
  221. package/lib/module/modules/cms/hooks/use-cms-locale.js +16 -0
  222. package/lib/module/modules/cms/hooks/use-cms-locale.js.map +1 -0
  223. package/lib/module/modules/cms/hooks/use-cms-translations.js +45 -0
  224. package/lib/module/modules/cms/hooks/use-cms-translations.js.map +1 -0
  225. package/lib/module/modules/cms/index.js +6 -0
  226. package/lib/module/modules/cms/index.js.map +1 -0
  227. package/lib/module/modules/cms/merge-cms-translations.js +46 -0
  228. package/lib/module/modules/cms/merge-cms-translations.js.map +1 -0
  229. package/lib/module/modules/data-sync/components/android/android-health-connect-authorization-provider.js +23 -18
  230. package/lib/module/modules/data-sync/components/android/android-health-connect-authorization-provider.js.map +1 -1
  231. package/lib/module/modules/data-sync/components/apple/apple-health-authorization-provider.js +18 -17
  232. package/lib/module/modules/data-sync/components/apple/apple-health-authorization-provider.js.map +1 -1
  233. package/lib/module/modules/data-sync/components/apple/apple-health-authorization-utils.js +16 -0
  234. package/lib/module/modules/data-sync/components/apple/apple-health-authorization-utils.js.map +1 -0
  235. package/lib/module/modules/data-sync/contexts/health-authorization-context.js +13 -0
  236. package/lib/module/modules/data-sync/contexts/health-authorization-context.js.map +1 -0
  237. package/lib/module/modules/data-sync/hooks/use-health-import.js +76 -0
  238. package/lib/module/modules/data-sync/hooks/use-health-import.js.map +1 -0
  239. package/lib/module/modules/data-sync/index.js +2 -0
  240. package/lib/module/modules/data-sync/index.js.map +1 -1
  241. package/lib/module/modules/helpers/hooks/use-shallow-stable-value.js +14 -0
  242. package/lib/module/modules/helpers/hooks/use-shallow-stable-value.js.map +1 -0
  243. package/lib/module/modules/language-switcher/components/language-switcher.js +11 -4
  244. package/lib/module/modules/language-switcher/components/language-switcher.js.map +1 -1
  245. package/lib/module/modules/language-switcher/components/option/context/language-option-context.js +1 -1
  246. package/lib/module/modules/language-switcher/components/option/context/language-option-context.js.map +1 -1
  247. package/lib/module/modules/language-switcher/components/option/language-switcher-option.js +5 -4
  248. package/lib/module/modules/language-switcher/components/option/language-switcher-option.js.map +1 -1
  249. package/lib/module/modules/socket/components/socket-provider.js +78 -73
  250. package/lib/module/modules/socket/components/socket-provider.js.map +1 -1
  251. package/lib/module/modules/tab/components/tab-provider.js +11 -1
  252. package/lib/module/modules/tab/components/tab-provider.js.map +1 -1
  253. package/lib/module/modules/tab/contexts/tab-context.js +1 -1
  254. package/lib/module/modules/tab/contexts/tab-context.js.map +1 -1
  255. package/lib/module/modules/tab/hooks/use-tab.js +1 -1
  256. package/lib/module/modules/tab/hooks/use-tab.js.map +1 -1
  257. package/lib/module/modules/ui/components/health-import-card.js +1 -2
  258. package/lib/module/modules/ui/components/health-import-card.js.map +1 -1
  259. package/lib/module/modules/ui/components/pairing-flow.js.map +1 -1
  260. package/lib/typescript/commonjs/src/index.d.ts +1 -0
  261. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  262. package/lib/typescript/commonjs/src/modules/auth/default-translation.d.ts +53 -1
  263. package/lib/typescript/commonjs/src/modules/auth/default-translation.d.ts.map +1 -1
  264. package/lib/typescript/commonjs/src/modules/auth/delete-account-button/components/delete-account-button.d.ts.map +1 -1
  265. package/lib/typescript/commonjs/src/modules/auth/hooks/use-auth-action.d.ts +13 -0
  266. package/lib/typescript/commonjs/src/modules/auth/hooks/use-auth-action.d.ts.map +1 -0
  267. package/lib/typescript/commonjs/src/modules/auth/hooks/use-delete-account.d.ts +8 -0
  268. package/lib/typescript/commonjs/src/modules/auth/hooks/use-delete-account.d.ts.map +1 -0
  269. package/lib/typescript/commonjs/src/modules/auth/hooks/use-session.d.ts +6 -4
  270. package/lib/typescript/commonjs/src/modules/auth/hooks/use-session.d.ts.map +1 -1
  271. package/lib/typescript/commonjs/src/modules/auth/hooks/use-sign-in.d.ts +24 -0
  272. package/lib/typescript/commonjs/src/modules/auth/hooks/use-sign-in.d.ts.map +1 -0
  273. package/lib/typescript/commonjs/src/modules/auth/hooks/use-sign-out.d.ts +4 -0
  274. package/lib/typescript/commonjs/src/modules/auth/hooks/use-sign-out.d.ts.map +1 -0
  275. package/lib/typescript/commonjs/src/modules/auth/hooks/use-social-sign-in.d.ts +14 -0
  276. package/lib/typescript/commonjs/src/modules/auth/hooks/use-social-sign-in.d.ts.map +1 -0
  277. package/lib/typescript/commonjs/src/modules/auth/index.d.ts +5 -0
  278. package/lib/typescript/commonjs/src/modules/auth/index.d.ts.map +1 -1
  279. package/lib/typescript/commonjs/src/modules/auth/logout-button/components/logout-button.d.ts.map +1 -1
  280. package/lib/typescript/commonjs/src/modules/auth/profile/components/profile-form-provider.d.ts.map +1 -1
  281. package/lib/typescript/commonjs/src/modules/auth/profile/contexts/profile-form-context.d.ts +1 -1
  282. package/lib/typescript/commonjs/src/modules/auth/profile/contexts/profile-form-context.d.ts.map +1 -1
  283. package/lib/typescript/commonjs/src/modules/auth/profile/hooks/use-profile-form.d.ts.map +1 -1
  284. package/lib/typescript/commonjs/src/modules/auth/register/components/form/register-form-provider.d.ts.map +1 -1
  285. package/lib/typescript/commonjs/src/modules/auth/reset-password/components/form/inputs.d.ts.map +1 -1
  286. package/lib/typescript/commonjs/src/modules/auth/reset-password/components/form/reset-password-form-provider.d.ts.map +1 -1
  287. package/lib/typescript/commonjs/src/modules/auth/reset-password/contexts/reset-password-form-context.d.ts +1 -1
  288. package/lib/typescript/commonjs/src/modules/auth/reset-password/contexts/reset-password-form-context.d.ts.map +1 -1
  289. package/lib/typescript/commonjs/src/modules/auth/session/logout-session.d.ts +6 -0
  290. package/lib/typescript/commonjs/src/modules/auth/session/logout-session.d.ts.map +1 -0
  291. package/lib/typescript/commonjs/src/modules/auth/session/session-store.d.ts +21 -0
  292. package/lib/typescript/commonjs/src/modules/auth/session/session-store.d.ts.map +1 -0
  293. package/lib/typescript/commonjs/src/modules/auth/sign-in/components/form/login-form-provider.d.ts.map +1 -1
  294. package/lib/typescript/commonjs/src/modules/auth/sign-in/components/social-logins/apple-login-button.d.ts.map +1 -1
  295. package/lib/typescript/commonjs/src/modules/auth/sign-in/components/social-logins/google-login-button.d.ts.map +1 -1
  296. package/lib/typescript/commonjs/src/modules/auth/sign-in/contexts/login-form-context.d.ts +1 -1
  297. package/lib/typescript/commonjs/src/modules/auth/sign-in/contexts/login-form-context.d.ts.map +1 -1
  298. package/lib/typescript/commonjs/src/modules/bt-device/components/device-list-provider.d.ts.map +1 -1
  299. package/lib/typescript/commonjs/src/modules/bt-device/components/hooks/use-device-list.d.ts +1 -5
  300. package/lib/typescript/commonjs/src/modules/bt-device/components/hooks/use-device-list.d.ts.map +1 -1
  301. package/lib/typescript/commonjs/src/modules/bt-device/contexts/device-list-context.d.ts +3 -2
  302. package/lib/typescript/commonjs/src/modules/bt-device/contexts/device-list-context.d.ts.map +1 -1
  303. package/lib/typescript/commonjs/src/modules/bt-management/components/bt-provider-child-wrapper.d.ts +1 -1
  304. package/lib/typescript/commonjs/src/modules/bt-management/components/bt-provider-child-wrapper.d.ts.map +1 -1
  305. package/lib/typescript/commonjs/src/modules/bt-management/components/bt-provider.d.ts +1 -1
  306. package/lib/typescript/commonjs/src/modules/bt-management/components/bt-provider.d.ts.map +1 -1
  307. package/lib/typescript/commonjs/src/modules/bt-management/hooks/runtime-context.d.ts +40 -9
  308. package/lib/typescript/commonjs/src/modules/bt-management/hooks/runtime-context.d.ts.map +1 -1
  309. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-background-sync.d.ts.map +1 -1
  310. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-bluetooth-permission.d.ts +17 -0
  311. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-bluetooth-permission.d.ts.map +1 -0
  312. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-bluetooth-state.d.ts.map +1 -1
  313. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-bt-device.d.ts +31 -0
  314. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-bt-device.d.ts.map +1 -0
  315. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-device-connection.d.ts +2 -2
  316. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-device-connection.d.ts.map +1 -1
  317. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-health-import.d.ts +2 -15
  318. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-health-import.d.ts.map +1 -1
  319. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-measurements.d.ts.map +1 -1
  320. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-nearby-devices.d.ts.map +1 -1
  321. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-paired-devices.d.ts.map +1 -1
  322. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-request-permissions.d.ts +1 -0
  323. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-request-permissions.d.ts.map +1 -1
  324. package/lib/typescript/commonjs/src/modules/bt-management/hooks/use-scan-control.d.ts.map +1 -1
  325. package/lib/typescript/commonjs/src/modules/bt-management/index.d.ts +6 -1
  326. package/lib/typescript/commonjs/src/modules/bt-management/index.d.ts.map +1 -1
  327. package/lib/typescript/commonjs/src/modules/bt-management/types/btprovider-props.d.ts +2 -0
  328. package/lib/typescript/commonjs/src/modules/bt-management/types/btprovider-props.d.ts.map +1 -1
  329. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-content.d.ts +9 -0
  330. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-content.d.ts.map +1 -0
  331. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-locale.d.ts +7 -0
  332. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-locale.d.ts.map +1 -0
  333. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-translations.d.ts +10 -0
  334. package/lib/typescript/commonjs/src/modules/cms/hooks/use-cms-translations.d.ts.map +1 -0
  335. package/lib/typescript/commonjs/src/modules/cms/index.d.ts +4 -0
  336. package/lib/typescript/commonjs/src/modules/cms/index.d.ts.map +1 -0
  337. package/lib/typescript/commonjs/src/modules/cms/merge-cms-translations.d.ts +13 -0
  338. package/lib/typescript/commonjs/src/modules/cms/merge-cms-translations.d.ts.map +1 -0
  339. package/lib/typescript/commonjs/src/modules/data-sync/components/android/android-health-connect-authorization-provider.d.ts +1 -1
  340. package/lib/typescript/commonjs/src/modules/data-sync/components/android/android-health-connect-authorization-provider.d.ts.map +1 -1
  341. package/lib/typescript/commonjs/src/modules/data-sync/components/apple/apple-health-authorization-provider.d.ts.map +1 -1
  342. package/lib/typescript/commonjs/src/modules/data-sync/components/apple/apple-health-authorization-utils.d.ts +4 -0
  343. package/lib/typescript/commonjs/src/modules/data-sync/components/apple/apple-health-authorization-utils.d.ts.map +1 -0
  344. package/lib/typescript/commonjs/src/modules/data-sync/components/data-sync.d.ts +1 -1
  345. package/lib/typescript/commonjs/src/modules/data-sync/contexts/health-authorization-context.d.ts +17 -0
  346. package/lib/typescript/commonjs/src/modules/data-sync/contexts/health-authorization-context.d.ts.map +1 -0
  347. package/lib/typescript/commonjs/src/modules/data-sync/hooks/use-health-import.d.ts +17 -0
  348. package/lib/typescript/commonjs/src/modules/data-sync/hooks/use-health-import.d.ts.map +1 -0
  349. package/lib/typescript/commonjs/src/modules/data-sync/index.d.ts +3 -0
  350. package/lib/typescript/commonjs/src/modules/data-sync/index.d.ts.map +1 -1
  351. package/lib/typescript/commonjs/src/modules/data-sync/types/health-authorization-status.d.ts +1 -0
  352. package/lib/typescript/commonjs/src/modules/data-sync/types/health-authorization-status.d.ts.map +1 -1
  353. package/lib/typescript/commonjs/src/modules/helpers/hooks/use-shallow-stable-value.d.ts +2 -0
  354. package/lib/typescript/commonjs/src/modules/helpers/hooks/use-shallow-stable-value.d.ts.map +1 -0
  355. package/lib/typescript/commonjs/src/modules/language-switcher/components/language-switcher.d.ts +6 -5
  356. package/lib/typescript/commonjs/src/modules/language-switcher/components/language-switcher.d.ts.map +1 -1
  357. package/lib/typescript/commonjs/src/modules/language-switcher/components/option/context/language-option-context.d.ts +1 -1
  358. package/lib/typescript/commonjs/src/modules/language-switcher/components/option/context/language-option-context.d.ts.map +1 -1
  359. package/lib/typescript/commonjs/src/modules/socket/components/socket-provider.d.ts.map +1 -1
  360. package/lib/typescript/commonjs/src/modules/tab/components/tab-provider.d.ts +2 -1
  361. package/lib/typescript/commonjs/src/modules/tab/components/tab-provider.d.ts.map +1 -1
  362. package/lib/typescript/commonjs/src/modules/tab/contexts/tab-context.d.ts +1 -1
  363. package/lib/typescript/commonjs/src/modules/tab/contexts/tab-context.d.ts.map +1 -1
  364. package/lib/typescript/commonjs/src/modules/ui/components/health-import-card.d.ts +1 -2
  365. package/lib/typescript/commonjs/src/modules/ui/components/health-import-card.d.ts.map +1 -1
  366. package/lib/typescript/commonjs/src/modules/ui/components/pairing-flow.d.ts.map +1 -1
  367. package/lib/typescript/module/src/index.d.ts +1 -0
  368. package/lib/typescript/module/src/index.d.ts.map +1 -1
  369. package/lib/typescript/module/src/modules/auth/default-translation.d.ts +53 -1
  370. package/lib/typescript/module/src/modules/auth/default-translation.d.ts.map +1 -1
  371. package/lib/typescript/module/src/modules/auth/delete-account-button/components/delete-account-button.d.ts.map +1 -1
  372. package/lib/typescript/module/src/modules/auth/hooks/use-auth-action.d.ts +13 -0
  373. package/lib/typescript/module/src/modules/auth/hooks/use-auth-action.d.ts.map +1 -0
  374. package/lib/typescript/module/src/modules/auth/hooks/use-delete-account.d.ts +8 -0
  375. package/lib/typescript/module/src/modules/auth/hooks/use-delete-account.d.ts.map +1 -0
  376. package/lib/typescript/module/src/modules/auth/hooks/use-session.d.ts +6 -4
  377. package/lib/typescript/module/src/modules/auth/hooks/use-session.d.ts.map +1 -1
  378. package/lib/typescript/module/src/modules/auth/hooks/use-sign-in.d.ts +24 -0
  379. package/lib/typescript/module/src/modules/auth/hooks/use-sign-in.d.ts.map +1 -0
  380. package/lib/typescript/module/src/modules/auth/hooks/use-sign-out.d.ts +4 -0
  381. package/lib/typescript/module/src/modules/auth/hooks/use-sign-out.d.ts.map +1 -0
  382. package/lib/typescript/module/src/modules/auth/hooks/use-social-sign-in.d.ts +14 -0
  383. package/lib/typescript/module/src/modules/auth/hooks/use-social-sign-in.d.ts.map +1 -0
  384. package/lib/typescript/module/src/modules/auth/index.d.ts +5 -0
  385. package/lib/typescript/module/src/modules/auth/index.d.ts.map +1 -1
  386. package/lib/typescript/module/src/modules/auth/logout-button/components/logout-button.d.ts.map +1 -1
  387. package/lib/typescript/module/src/modules/auth/profile/components/profile-form-provider.d.ts.map +1 -1
  388. package/lib/typescript/module/src/modules/auth/profile/contexts/profile-form-context.d.ts +1 -1
  389. package/lib/typescript/module/src/modules/auth/profile/contexts/profile-form-context.d.ts.map +1 -1
  390. package/lib/typescript/module/src/modules/auth/profile/hooks/use-profile-form.d.ts.map +1 -1
  391. package/lib/typescript/module/src/modules/auth/register/components/form/register-form-provider.d.ts.map +1 -1
  392. package/lib/typescript/module/src/modules/auth/reset-password/components/form/inputs.d.ts.map +1 -1
  393. package/lib/typescript/module/src/modules/auth/reset-password/components/form/reset-password-form-provider.d.ts.map +1 -1
  394. package/lib/typescript/module/src/modules/auth/reset-password/contexts/reset-password-form-context.d.ts +1 -1
  395. package/lib/typescript/module/src/modules/auth/reset-password/contexts/reset-password-form-context.d.ts.map +1 -1
  396. package/lib/typescript/module/src/modules/auth/session/logout-session.d.ts +6 -0
  397. package/lib/typescript/module/src/modules/auth/session/logout-session.d.ts.map +1 -0
  398. package/lib/typescript/module/src/modules/auth/session/session-store.d.ts +21 -0
  399. package/lib/typescript/module/src/modules/auth/session/session-store.d.ts.map +1 -0
  400. package/lib/typescript/module/src/modules/auth/sign-in/components/form/login-form-provider.d.ts.map +1 -1
  401. package/lib/typescript/module/src/modules/auth/sign-in/components/social-logins/apple-login-button.d.ts.map +1 -1
  402. package/lib/typescript/module/src/modules/auth/sign-in/components/social-logins/google-login-button.d.ts.map +1 -1
  403. package/lib/typescript/module/src/modules/auth/sign-in/contexts/login-form-context.d.ts +1 -1
  404. package/lib/typescript/module/src/modules/auth/sign-in/contexts/login-form-context.d.ts.map +1 -1
  405. package/lib/typescript/module/src/modules/bt-device/components/device-list-provider.d.ts.map +1 -1
  406. package/lib/typescript/module/src/modules/bt-device/components/hooks/use-device-list.d.ts +1 -5
  407. package/lib/typescript/module/src/modules/bt-device/components/hooks/use-device-list.d.ts.map +1 -1
  408. package/lib/typescript/module/src/modules/bt-device/contexts/device-list-context.d.ts +3 -2
  409. package/lib/typescript/module/src/modules/bt-device/contexts/device-list-context.d.ts.map +1 -1
  410. package/lib/typescript/module/src/modules/bt-management/components/bt-provider-child-wrapper.d.ts +1 -1
  411. package/lib/typescript/module/src/modules/bt-management/components/bt-provider-child-wrapper.d.ts.map +1 -1
  412. package/lib/typescript/module/src/modules/bt-management/components/bt-provider.d.ts +1 -1
  413. package/lib/typescript/module/src/modules/bt-management/components/bt-provider.d.ts.map +1 -1
  414. package/lib/typescript/module/src/modules/bt-management/hooks/runtime-context.d.ts +40 -9
  415. package/lib/typescript/module/src/modules/bt-management/hooks/runtime-context.d.ts.map +1 -1
  416. package/lib/typescript/module/src/modules/bt-management/hooks/use-background-sync.d.ts.map +1 -1
  417. package/lib/typescript/module/src/modules/bt-management/hooks/use-bluetooth-permission.d.ts +17 -0
  418. package/lib/typescript/module/src/modules/bt-management/hooks/use-bluetooth-permission.d.ts.map +1 -0
  419. package/lib/typescript/module/src/modules/bt-management/hooks/use-bluetooth-state.d.ts.map +1 -1
  420. package/lib/typescript/module/src/modules/bt-management/hooks/use-bt-device.d.ts +31 -0
  421. package/lib/typescript/module/src/modules/bt-management/hooks/use-bt-device.d.ts.map +1 -0
  422. package/lib/typescript/module/src/modules/bt-management/hooks/use-device-connection.d.ts +2 -2
  423. package/lib/typescript/module/src/modules/bt-management/hooks/use-device-connection.d.ts.map +1 -1
  424. package/lib/typescript/module/src/modules/bt-management/hooks/use-health-import.d.ts +2 -15
  425. package/lib/typescript/module/src/modules/bt-management/hooks/use-health-import.d.ts.map +1 -1
  426. package/lib/typescript/module/src/modules/bt-management/hooks/use-measurements.d.ts.map +1 -1
  427. package/lib/typescript/module/src/modules/bt-management/hooks/use-nearby-devices.d.ts.map +1 -1
  428. package/lib/typescript/module/src/modules/bt-management/hooks/use-paired-devices.d.ts.map +1 -1
  429. package/lib/typescript/module/src/modules/bt-management/hooks/use-request-permissions.d.ts +1 -0
  430. package/lib/typescript/module/src/modules/bt-management/hooks/use-request-permissions.d.ts.map +1 -1
  431. package/lib/typescript/module/src/modules/bt-management/hooks/use-scan-control.d.ts.map +1 -1
  432. package/lib/typescript/module/src/modules/bt-management/index.d.ts +6 -1
  433. package/lib/typescript/module/src/modules/bt-management/index.d.ts.map +1 -1
  434. package/lib/typescript/module/src/modules/bt-management/types/btprovider-props.d.ts +2 -0
  435. package/lib/typescript/module/src/modules/bt-management/types/btprovider-props.d.ts.map +1 -1
  436. package/lib/typescript/module/src/modules/cms/hooks/use-cms-content.d.ts +9 -0
  437. package/lib/typescript/module/src/modules/cms/hooks/use-cms-content.d.ts.map +1 -0
  438. package/lib/typescript/module/src/modules/cms/hooks/use-cms-locale.d.ts +7 -0
  439. package/lib/typescript/module/src/modules/cms/hooks/use-cms-locale.d.ts.map +1 -0
  440. package/lib/typescript/module/src/modules/cms/hooks/use-cms-translations.d.ts +10 -0
  441. package/lib/typescript/module/src/modules/cms/hooks/use-cms-translations.d.ts.map +1 -0
  442. package/lib/typescript/module/src/modules/cms/index.d.ts +4 -0
  443. package/lib/typescript/module/src/modules/cms/index.d.ts.map +1 -0
  444. package/lib/typescript/module/src/modules/cms/merge-cms-translations.d.ts +13 -0
  445. package/lib/typescript/module/src/modules/cms/merge-cms-translations.d.ts.map +1 -0
  446. package/lib/typescript/module/src/modules/data-sync/components/android/android-health-connect-authorization-provider.d.ts +1 -1
  447. package/lib/typescript/module/src/modules/data-sync/components/android/android-health-connect-authorization-provider.d.ts.map +1 -1
  448. package/lib/typescript/module/src/modules/data-sync/components/apple/apple-health-authorization-provider.d.ts.map +1 -1
  449. package/lib/typescript/module/src/modules/data-sync/components/apple/apple-health-authorization-utils.d.ts +4 -0
  450. package/lib/typescript/module/src/modules/data-sync/components/apple/apple-health-authorization-utils.d.ts.map +1 -0
  451. package/lib/typescript/module/src/modules/data-sync/components/data-sync.d.ts +1 -1
  452. package/lib/typescript/module/src/modules/data-sync/contexts/health-authorization-context.d.ts +17 -0
  453. package/lib/typescript/module/src/modules/data-sync/contexts/health-authorization-context.d.ts.map +1 -0
  454. package/lib/typescript/module/src/modules/data-sync/hooks/use-health-import.d.ts +17 -0
  455. package/lib/typescript/module/src/modules/data-sync/hooks/use-health-import.d.ts.map +1 -0
  456. package/lib/typescript/module/src/modules/data-sync/index.d.ts +3 -0
  457. package/lib/typescript/module/src/modules/data-sync/index.d.ts.map +1 -1
  458. package/lib/typescript/module/src/modules/data-sync/types/health-authorization-status.d.ts +1 -0
  459. package/lib/typescript/module/src/modules/data-sync/types/health-authorization-status.d.ts.map +1 -1
  460. package/lib/typescript/module/src/modules/helpers/hooks/use-shallow-stable-value.d.ts +2 -0
  461. package/lib/typescript/module/src/modules/helpers/hooks/use-shallow-stable-value.d.ts.map +1 -0
  462. package/lib/typescript/module/src/modules/language-switcher/components/language-switcher.d.ts +6 -5
  463. package/lib/typescript/module/src/modules/language-switcher/components/language-switcher.d.ts.map +1 -1
  464. package/lib/typescript/module/src/modules/language-switcher/components/option/context/language-option-context.d.ts +1 -1
  465. package/lib/typescript/module/src/modules/language-switcher/components/option/context/language-option-context.d.ts.map +1 -1
  466. package/lib/typescript/module/src/modules/socket/components/socket-provider.d.ts.map +1 -1
  467. package/lib/typescript/module/src/modules/tab/components/tab-provider.d.ts +2 -1
  468. package/lib/typescript/module/src/modules/tab/components/tab-provider.d.ts.map +1 -1
  469. package/lib/typescript/module/src/modules/tab/contexts/tab-context.d.ts +1 -1
  470. package/lib/typescript/module/src/modules/tab/contexts/tab-context.d.ts.map +1 -1
  471. package/lib/typescript/module/src/modules/ui/components/health-import-card.d.ts +1 -2
  472. package/lib/typescript/module/src/modules/ui/components/health-import-card.d.ts.map +1 -1
  473. package/lib/typescript/module/src/modules/ui/components/pairing-flow.d.ts.map +1 -1
  474. package/package.json +3 -3
@@ -3,14 +3,37 @@
3
3
  /* eslint-disable import/group-exports, max-lines */
4
4
 
5
5
  import * as React from "react";
6
+
7
+ /** Typed union exposed when a host listens to every accepted device. */
6
8
  import { jsx as _jsx } from "react/jsx-runtime";
7
9
  const RuntimeContext = /*#__PURE__*/React.createContext(null);
8
- export const createBluetoothRuntime = bleManager => {
10
+ export const createBluetoothRuntime = (bleManager, initialBackgroundScanEnabled) => {
9
11
  const listeners = new Map();
10
12
  let currentManager;
11
13
  let currentDevices = [];
14
+ let backgroundScanEnabled = initialBackgroundScanEnabled ?? false;
15
+ let backgroundScanInitialized = initialBackgroundScanEnabled !== undefined;
16
+ let bluetoothState = "unknown";
12
17
  const subscribers = new Set();
18
+ let currentSnapshot = {
19
+ devices: currentDevices,
20
+ backgroundScanEnabled,
21
+ managerReady: false,
22
+ bluetoothState
23
+ };
24
+ const publishState = (devices = currentDevices) => {
25
+ currentDevices = devices;
26
+ currentSnapshot = {
27
+ devices: currentDevices,
28
+ backgroundScanEnabled,
29
+ managerReady: currentManager !== undefined,
30
+ bluetoothState
31
+ };
32
+ subscribers.forEach(notify => notify());
33
+ };
13
34
  const pairedState = new Map();
35
+ const connectionIds = new Map();
36
+ const resultConnectionIds = new WeakMap();
14
37
  const getPairedState = storageKey => {
15
38
  const current = pairedState.get(storageKey);
16
39
  if (current) {
@@ -27,16 +50,40 @@ export const createBluetoothRuntime = bleManager => {
27
50
  storageKey
28
51
  };
29
52
  listeners.get("pairedDevices")?.forEach(callback => callback(value));
30
- subscribers.forEach(notify => notify());
31
53
  };
32
54
  return {
33
55
  bleManager,
34
56
  get manager() {
35
57
  return currentManager;
36
58
  },
59
+ getSnapshot: () => currentSnapshot,
37
60
  get devices() {
38
61
  return currentDevices;
39
62
  },
63
+ getBackgroundScanEnabled: () => backgroundScanEnabled,
64
+ initializeBackgroundScanEnabled: enabled => {
65
+ if (backgroundScanInitialized) {
66
+ return;
67
+ }
68
+ backgroundScanInitialized = true;
69
+ backgroundScanEnabled = enabled;
70
+ publishState();
71
+ },
72
+ setBackgroundScanEnabled: enabled => {
73
+ if (backgroundScanEnabled === enabled) {
74
+ return;
75
+ }
76
+ backgroundScanInitialized = true;
77
+ backgroundScanEnabled = enabled;
78
+ publishState();
79
+ },
80
+ setBluetoothState: state => {
81
+ if (bluetoothState === state) {
82
+ return;
83
+ }
84
+ bluetoothState = state;
85
+ publishState();
86
+ },
40
87
  subscribe: (event, callback) => {
41
88
  const eventListeners = listeners.get(event) ?? new Set();
42
89
  eventListeners.add(callback);
@@ -50,11 +97,13 @@ export const createBluetoothRuntime = bleManager => {
50
97
  hasListeners: event => (listeners.get(event)?.size ?? 0) > 0,
51
98
  emit: (event, value) => {
52
99
  listeners.get(event)?.forEach(callback => callback(value));
53
- subscribers.forEach(notify => notify());
54
100
  },
55
101
  setManager: manager => {
102
+ if (currentManager === manager) {
103
+ return;
104
+ }
56
105
  currentManager = manager;
57
- subscribers.forEach(notify => notify());
106
+ publishState();
58
107
  },
59
108
  setAutoConnect: (enabled, delayMs, onDeviceSelectionRequired) => {
60
109
  currentManager?.setAutoConnect(enabled, delayMs, onDeviceSelectionRequired);
@@ -84,31 +133,92 @@ export const createBluetoothRuntime = bleManager => {
84
133
  },
85
134
  setPairedDeviceIds: (storageKey, ids) => {
86
135
  const state = getPairedState(storageKey);
136
+ const next = [...new Set(ids)];
137
+ if (state.value?.length === next.length && state.value.every((id, index) => id === next[index])) {
138
+ return;
139
+ }
87
140
  state.revision += 1;
88
- state.value = [...new Set(ids)];
141
+ state.value = next;
89
142
  notifyPairedDevices(storageKey);
90
143
  },
91
144
  upsertDevice: device => {
92
145
  const existing = currentDevices.findIndex(item => item.id === device.id);
146
+ const previous = existing === -1 ? undefined : currentDevices[existing];
147
+ if (previous?.device === device && previous.deviceData === device.deviceData) {
148
+ return;
149
+ }
93
150
  const next = {
94
151
  id: device.id,
95
152
  deviceData: device.deviceData,
96
153
  device,
97
- status: existing === -1 ? undefined : currentDevices[existing]?.status
154
+ status: previous?.status,
155
+ latestResult: previous?.latestResult,
156
+ results: previous?.results ?? [],
157
+ events: previous?.events ?? []
98
158
  };
99
- currentDevices = existing === -1 ? [...currentDevices, next] : currentDevices.map((item, index) => index === existing ? next : item);
100
- subscribers.forEach(notify => notify());
159
+ publishState(existing === -1 ? [...currentDevices, next] : currentDevices.map((item, index) => index === existing ? next : item));
160
+ },
161
+ setDeviceResult: result => {
162
+ const existing = currentDevices.findIndex(item => item.id === result.deviceData.id);
163
+ if (existing === -1) {
164
+ return;
165
+ }
166
+ const device = currentDevices[existing];
167
+ if (!device || device.results?.some(item => item.id === result.id)) {
168
+ return;
169
+ }
170
+ resultConnectionIds.set(result, connectionIds.get(result.deviceData.id) ?? 0);
171
+ const next = {
172
+ ...device,
173
+ latestResult: result,
174
+ results: [...(device.results ?? []), result].slice(-100)
175
+ };
176
+ publishState(currentDevices.map((item, index) => index === existing ? next : item));
177
+ },
178
+ getResultConnectionId: result => resultConnectionIds.get(result) ?? 0,
179
+ clearResults: () => {
180
+ if (!currentDevices.some(device => device.results?.length || device.latestResult)) {
181
+ return;
182
+ }
183
+ publishState(currentDevices.map(device => ({
184
+ ...device,
185
+ latestResult: undefined,
186
+ results: []
187
+ })));
188
+ },
189
+ setDeviceConnectionEvent: event => {
190
+ if (event.kind === "connected" || event.kind === "bonded") {
191
+ const id = event.deviceData.id;
192
+ connectionIds.set(id, (connectionIds.get(id) ?? 0) + 1);
193
+ }
194
+ const existing = currentDevices.findIndex(item => item.id === event.deviceData.id);
195
+ if (existing === -1) {
196
+ return;
197
+ }
198
+ const device = currentDevices[existing];
199
+ if (!device) {
200
+ return;
201
+ }
202
+ const next = {
203
+ ...device,
204
+ events: [...(device.events ?? []), event].slice(-100)
205
+ };
206
+ publishState(currentDevices.map((item, index) => index === existing ? next : item));
101
207
  },
102
208
  setDeviceStatus: ({
103
209
  deviceData,
104
210
  status
105
211
  }) => {
106
- currentDevices = currentDevices.map(item => item.id === deviceData.id ? {
212
+ const existing = currentDevices.findIndex(item => item.id === deviceData.id);
213
+ const device = currentDevices[existing];
214
+ if (!device || device.status === status && device.deviceData === deviceData) {
215
+ return;
216
+ }
217
+ publishState(currentDevices.map((item, index) => index === existing ? {
107
218
  ...item,
108
219
  deviceData,
109
220
  status
110
- } : item);
111
- subscribers.forEach(notify => notify());
221
+ } : item));
112
222
  }
113
223
  };
114
224
  };
@@ -132,6 +242,27 @@ export const useRuntimeEvent = (event, callback) => {
132
242
  callbackRef.current = callback;
133
243
  React.useEffect(() => runtime.subscribe(event, value => callbackRef.current(value)), [event, runtime]);
134
244
  };
135
-
136
- /** Typed union exposed when a host listens to every accepted device. */
245
+ export const useBluetoothSelector = (selector, isEqual = Object.is) => {
246
+ const runtime = useBluetoothRuntime();
247
+ const selectorRef = React.useRef(selector);
248
+ const equalityRef = React.useRef(isEqual);
249
+ const selectionRef = React.useRef({
250
+ hasValue: false
251
+ });
252
+ selectorRef.current = selector;
253
+ equalityRef.current = isEqual;
254
+ const getSelection = React.useCallback(() => {
255
+ const next = selectorRef.current(runtime.getSnapshot());
256
+ const previous = selectionRef.current;
257
+ if (previous.hasValue && equalityRef.current(previous.value, next)) {
258
+ return previous.value;
259
+ }
260
+ selectionRef.current = {
261
+ hasValue: true,
262
+ value: next
263
+ };
264
+ return next;
265
+ }, [runtime]);
266
+ return React.useSyncExternalStore(runtime.subscribeState, getSelection, getSelection);
267
+ };
137
268
  //# sourceMappingURL=runtime-context.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","jsx","_jsx","RuntimeContext","createContext","createBluetoothRuntime","bleManager","listeners","Map","currentManager","currentDevices","subscribers","Set","pairedState","getPairedState","storageKey","current","get","next","revision","set","notifyPairedDevices","value","forEach","callback","notify","manager","devices","subscribe","event","eventListeners","add","delete","subscribeState","hasListeners","size","emit","setManager","setAutoConnect","enabled","delayMs","onDeviceSelectionRequired","getPairedDeviceIds","loadPairedDeviceIds","load","state","Promise","resolve","loading","then","finally","undefined","setPairedDeviceIds","ids","upsertDevice","device","existing","findIndex","item","id","deviceData","status","map","index","setDeviceStatus","BluetoothRuntimeProvider","runtime","children","Provider","useBluetoothRuntime","useContext","Error","useRuntimeEvent","callbackRef","useRef","useEffect"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/runtime-context.tsx"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAwE/B,MAAMC,cAAc,gBAAGH,KAAK,CAACI,aAAa,CAA0B,IAAI,CAAC;AAEzE,OAAO,MAAMC,sBAAsB,GACjCC,UAAuB,IACF;EACrB,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAA8C,CAAC;EACxE,IAAIC,cAES;EACb,IAAIC,cAA+B,GAAG,EAAE;EACxC,MAAMC,WAAW,GAAG,IAAIC,GAAG,CAAa,CAAC;EAEzC,MAAMC,WAAW,GAAG,IAAIL,GAAG,CAOzB,CAAC;EAEH,MAAMM,cAAc,GAAIC,UAAkB,IAAK;IAC7C,MAAMC,OAAO,GAAGH,WAAW,CAACI,GAAG,CAACF,UAAU,CAAC;IAE3C,IAAIC,OAAO,EAAE;MACX,OAAOA,OAAO;IAChB;IAEA,MAAME,IAIL,GAAG;MAAEC,QAAQ,EAAE;IAAE,CAAC;IAEnBN,WAAW,CAACO,GAAG,CAACL,UAAU,EAAEG,IAAI,CAAC;IAEjC,OAAOA,IAAI;EACb,CAAC;EAED,MAAMG,mBAAmB,GAAI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MACD/C,WAAW,CAACY,OAAO,CAAEE,MAAM,IAAKA,MAAM,CAAC,CAAC,CAAC;IAC3C;EACF,CAAC;AACH,CAAC;AAED,OAAO,MAAMwC,wBAAwB,GAAGA,CAAC;EACvCC,OAAO;EACPC;AACsD,CAAC,kBACvDjE,IAAA,CAACC,cAAc,CAACiE,QAAQ;EAAC9C,KAAK,EAAE4C,OAAQ;EAAAC,QAAA,EAAEA;AAAQ,CAA0B,CAC7E;AAED,OAAO,MAAME,mBAAmB,GAAGA,CAAA,KAAwB;EACzD,MAAMH,OAAO,GAAGlE,KAAK,CAACsE,UAAU,CAACnE,cAAc,CAAC;EAEhD,IAAI,CAAC+D,OAAO,EAAE;IACZ,MAAM,IAAIK,KAAK,CAAC,oDAAoD,CAAC;EACvE;EAEA,OAAOL,OAAO;AAChB,CAAC;AAED,OAAO,MAAMM,eAAe,GAAGA,CAC7B3C,KAAmB,EACnBL,QAA4B,KACnB;EACT,MAAM0C,OAAO,GAAGG,mBAAmB,CAAC,CAAC;EACrC,MAAMI,WAAW,GAAGzE,KAAK,CAAC0E,MAAM,CAAClD,QAAQ,CAAC;EAE1CiD,WAAW,CAACzD,OAAO,GAAGQ,QAAQ;EAE9BxB,KAAK,CAAC2E,SAAS,CACb,MAAMT,OAAO,CAACtC,SAAS,CAAIC,KAAK,EAAGP,KAAK,IAAKmD,WAAW,CAACzD,OAAO,CAACM,KAAK,CAAC,CAAC,EACxE,CAACO,KAAK,EAAEqC,OAAO,CACjB,CAAC;AACH,CAAC;;AAED","ignoreList":[]}
1
+ {"version":3,"names":["React","jsx","_jsx","RuntimeContext","createContext","createBluetoothRuntime","bleManager","initialBackgroundScanEnabled","listeners","Map","currentManager","currentDevices","backgroundScanEnabled","backgroundScanInitialized","undefined","bluetoothState","subscribers","Set","currentSnapshot","devices","managerReady","publishState","forEach","notify","pairedState","connectionIds","resultConnectionIds","WeakMap","getPairedState","storageKey","current","get","next","revision","set","notifyPairedDevices","value","callback","manager","getSnapshot","getBackgroundScanEnabled","initializeBackgroundScanEnabled","enabled","setBackgroundScanEnabled","setBluetoothState","state","subscribe","event","eventListeners","add","delete","subscribeState","hasListeners","size","emit","setManager","setAutoConnect","delayMs","onDeviceSelectionRequired","getPairedDeviceIds","loadPairedDeviceIds","load","Promise","resolve","loading","then","finally","setPairedDeviceIds","ids","length","every","id","index","upsertDevice","device","existing","findIndex","item","previous","deviceData","status","latestResult","results","events","map","setDeviceResult","result","some","slice","getResultConnectionId","clearResults","setDeviceConnectionEvent","kind","setDeviceStatus","BluetoothRuntimeProvider","runtime","children","Provider","useBluetoothRuntime","useContext","Error","useRuntimeEvent","callbackRef","useRef","useEffect","useBluetoothSelector","selector","isEqual","Object","is","selectorRef","equalityRef","selectionRef","hasValue","getSelection","useCallback","useSyncExternalStore"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/runtime-context.tsx"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;;AAY9B;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAyFA,MAAMC,cAAc,gBAAGH,KAAK,CAACI,aAAa,CAA0B,IAAI,CAAC;AAEzE,OAAO,MAAMC,sBAAsB,GAAGA,CACpCC,UAAuB,EACvBC,4BAAsC,KACjB;EACrB,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAoE,CAAC;EAC9F,IAAIC,cAES;EACb,IAAIC,cAA+B,GAAG,EAAE;EACxC,IAAIC,qBAAqB,GAAGL,4BAA4B,IAAI,KAAK;EACjE,IAAIM,yBAAyB,GAAGN,4BAA4B,KAAKO,SAAS;EAC1E,IAAIC,cAAqC,GAAG,SAAS;EACrD,MAAMC,WAAW,GAAG,IAAIC,GAAG,CAAa,CAAC;EACzC,IAAIC,eAAyC,GAAG;IAC9CC,OAAO,EAAER,cAAc;IACvBC,qBAAqB;IACrBQ,YAAY,EAAE,KAAK;IACnBL;EACF,CAAC;EAED,MAAMM,YAAY,GAAGA,CAACF,OAAO,GAAGR,cAAc,KAAK;IAC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AC;AACH,CAAC","ignoreList":[]}
@@ -10,30 +10,36 @@ export const useBackgroundSync = ({
10
10
  onEnabledChange
11
11
  } = {}) => {
12
12
  const runtime = useBluetoothRuntime();
13
- const [enabled, setEnabledState] = React.useState(initialEnabled);
14
13
  const [error, setError] = React.useState();
15
- const [status, setStatus] = React.useState(initialEnabled ? "on" : "off");
16
- React.useSyncExternalStore(runtime.subscribeState, () => runtime.manager, () => undefined);
14
+ const canEnableRef = React.useRef(canEnable);
15
+ const onEnabledChangeRef = React.useRef(onEnabledChange);
16
+ canEnableRef.current = canEnable;
17
+ onEnabledChangeRef.current = onEnabledChange;
18
+ React.useEffect(() => {
19
+ runtime.initializeBackgroundScanEnabled(initialEnabled);
20
+ }, [initialEnabled, runtime]);
21
+ const enabled = React.useSyncExternalStore(runtime.subscribeState, runtime.getBackgroundScanEnabled, () => initialEnabled);
22
+ const [statusOverride, setStatusOverride] = React.useState();
23
+ const status = statusOverride ?? (enabled ? "on" : "off");
17
24
  const setEnabled = React.useCallback(async next => {
18
25
  setError(undefined);
19
26
  try {
20
- if (next && canEnable && !(await canEnable())) {
21
- setStatus("restricted");
27
+ if (next && canEnableRef.current && !(await canEnableRef.current())) {
28
+ setStatusOverride("restricted");
22
29
  return;
23
30
  }
24
31
  if (next && !runtime.manager) {
25
32
  throw new Error("Bluetooth background sync is not ready yet.");
26
33
  }
27
- runtime.manager?.setBackgroundScanEnabled(next);
28
- await onEnabledChange?.(next);
29
- setEnabledState(next);
30
- setStatus(next ? "on" : "off");
34
+ await onEnabledChangeRef.current?.(next);
35
+ runtime.setBackgroundScanEnabled(next);
36
+ setStatusOverride(undefined);
31
37
  } catch (cause) {
32
38
  const nextError = cause instanceof Error ? cause : new Error(String(cause));
33
39
  setError(nextError);
34
- setStatus("blocked");
40
+ setStatusOverride("blocked");
35
41
  }
36
- }, [canEnable, onEnabledChange, runtime]);
42
+ }, [runtime]);
37
43
  return {
38
44
  enabled,
39
45
  setEnabled,
@@ -1 +1 @@
1
- {"version":3,"names":["React","useBluetoothRuntime","useBackgroundSync","enabled","initialEnabled","canEnable","onEnabledChange","runtime","setEnabledState","useState","error","setError","status","setStatus","useSyncExternalStore","subscribeState","manager","undefined","setEnabled","useCallback","next","Error","setBackgroundScanEnabled","cause","nextError","String","reason"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/use-background-sync.ts"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,mBAAmB,QAAQ,sBAAmB;AAUvD,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,OAAO,EAAEC,cAAc,GAAG,KAAK;EAC/BC,SAAS;EACTC;AACwB,CAAC,GAAG,CAAC,CAAC,KAM3B;EACH,MAAMC,OAAO,GAAGN,mBAAmB,CAAC,CAAC;EACrC,MAAM,CAACE,OAAO,EAAEK,eAAe,CAAC,GAAGR,KAAK,CAACS,QAAQ,CAACL,cAAc,CAAC;EACjE,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGX,KAAK,CAACS,QAAQ,CAAQ,CAAC;EAEjD,MAAM,CAACG,MAAM,EAAEC,SAAS,CAAC,GAAGb,KAAK,CAACS,QAAQ,CACxCL,cAAc,GAAG,IAAI,GAAG,KAC1B,CAAC;EAEDJ,KAAK,CAACc,oBAAoB,CACxBP,OAAO,CAACQ,cAAc,EACtB,MAAMR,OAAO,CAACS,OAAO,EACrB,MAAMC,SACR,CAAC;EAED,MAAMC,UAAU,GAAGlB,KAAK,CAACmB,WAAW,CAAC,MAAOC,IAAa,IAAK;IAC5DT,QAAQ,CAACM,SAAS,CAAC;IAEnB,IAAI;MACF,IAAIG,IAAI,IAAIf,SAAS,IAAI,EAAE,MAAMA,SAAS,CAAC,CAAC,CAAC,EAAE;QAC7CQ,SAAS,CAAC,YAAY,CAAC;QAEvB;MACF;MAEA,IAAIO,IAAI,IAAI,CAACb,OAAO,CAACS,OAAO,EAAE;QAC5B,MAAM,IAAIK,KAAK,CAAC,6CAA6C,CAAC;MAChE;MAEAd,OAAO,CAACS,OAAO,EAAEM,wBAAwB,CAACF,IAAI,CAAC;MAC/C,MAAMd,eAAe,GAAGc,IAAI,CAAC;MAC7BZ,eAAe,CAACY,IAAI,CAAC;MACrBP,SAAS,CAACO,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IAChC,CAAC,CAAC,OAAOG,KAAK,EAAE;MACd,MAAMC,SAAS,GAAGD,KAAK,YAAYF,KAAK,GAAGE,KAAK,GAAG,IAAIF,KAAK,CAACI,MAAM,CAACF,KAAK,CAAC,CAAC;MAE3EZ,QAAQ,CAACa,SAAS,CAAC;MACnBX,SAAS,CAAC,SAAS,CAAC;IACtB;EACF,CAAC,EAAE,CAACR,SAAS,EAAEC,eAAe,EAAEC,OAAO,CAAC,CAAC;EAEzC,OAAO;IAAEJ,OAAO;IAAEe,UAAU;IAAEN,MAAM;IAAEF,KAAK;IAAEgB,MAAM,EAAEd,MAAM,KAAK,YAAY,GAAG,iCAAiC,GAAGK;EAAU,CAAC;AAChI,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useBluetoothRuntime","useBackgroundSync","enabled","initialEnabled","canEnable","onEnabledChange","runtime","error","setError","useState","canEnableRef","useRef","onEnabledChangeRef","current","useEffect","initializeBackgroundScanEnabled","useSyncExternalStore","subscribeState","getBackgroundScanEnabled","statusOverride","setStatusOverride","status","setEnabled","useCallback","next","undefined","manager","Error","setBackgroundScanEnabled","cause","nextError","String","reason"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/use-background-sync.ts"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,mBAAmB,QAAQ,sBAAmB;AAUvD,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,OAAO,EAAEC,cAAc,GAAG,KAAK;EAC/BC,SAAS;EACTC;AACwB,CAAC,GAAG,CAAC,CAAC,KAM3B;EACH,MAAMC,OAAO,GAAGN,mBAAmB,C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AiB,CAACK,SAAS,CAAC;IAC9B,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,MAAMC,SAAS,GAAGD,KAAK,YAAYF,KAAK,GAAGE,KAAK,GAAG,IAAIF,KAAK,CAACI,MAAM,CAACF,KAAK,CAAC,CAAC;MAE3ErB,QAAQ,CAACsB,SAAS,CAAC;MACnBV,iBAAiB,CAAC,SAAS,CAAC;IAC9B;EACF,CAAC,EAAE,CAACd,OAAO,CAAC,CAAC;EAEb,OAAO;IAAEJ,OAAO;IAAEoB,UAAU;IAAED,MAAM;IAAEd,KAAK;IAAEyB,MAAM,EAAEX,MAAM,KAAK,YAAY,GAAG,iCAAiC,GAAGI;EAAU,CAAC;AAChI,CAAC","ignoreList":[]}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ import * as React from "react";
4
+ import { AppState, Linking, Platform } from "react-native";
5
+ import { PERMISSIONS, requestMultiple } from "react-native-permissions";
6
+ let sharedPermissionRequest;
7
+ const requestBluetoothPermissionResult = () => {
8
+ if (sharedPermissionRequest) {
9
+ return sharedPermissionRequest;
10
+ }
11
+ const requestedPermissions = Platform.OS === "android" ? Number(Platform.Version) >= 31 ? [PERMISSIONS.ANDROID.BLUETOOTH_CONNECT, PERMISSIONS.ANDROID.BLUETOOTH_SCAN] : [PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION] : Platform.OS === "ios" ? [PERMISSIONS.IOS.BLUETOOTH] : [];
12
+ const permissionRequest = requestMultiple(requestedPermissions).then(results => {
13
+ const granted = requestedPermissions.length > 0 && requestedPermissions.every(permission => results[permission] === "granted");
14
+ return {
15
+ granted,
16
+ status: granted ? "granted" : requestedPermissions.some(permission => results[permission] === "blocked") ? "blocked" : "denied"
17
+ };
18
+ }).finally(() => {
19
+ sharedPermissionRequest = undefined;
20
+ });
21
+ sharedPermissionRequest = permissionRequest;
22
+ return permissionRequest;
23
+ };
24
+ const requestBluetoothPermission = async () => (await requestBluetoothPermissionResult()).granted;
25
+ const useBluetoothPermission = ({
26
+ requestOnMount = false,
27
+ requestPermission = requestBluetoothPermission,
28
+ onPermissionChanged,
29
+ onRequestError
30
+ } = {}) => {
31
+ const [status, setStatus] = React.useState("unknown");
32
+ const onPermissionChangedRef = React.useRef(onPermissionChanged);
33
+ const onRequestErrorRef = React.useRef(onRequestError);
34
+ const requestPermissionRef = React.useRef(requestPermission);
35
+ const requestInFlightRef = React.useRef(undefined);
36
+ const requestOnResumeRef = React.useRef(false);
37
+ onPermissionChangedRef.current = onPermissionChanged;
38
+ onRequestErrorRef.current = onRequestError;
39
+ requestPermissionRef.current = requestPermission;
40
+ const request = React.useCallback(() => {
41
+ if (requestInFlightRef.current) {
42
+ return requestInFlightRef.current;
43
+ }
44
+ const requestPromise = requestPermissionRef.current === requestBluetoothPermission ? requestBluetoothPermissionResult() : requestPermissionRef.current().then(granted => ({
45
+ granted,
46
+ status: granted ? "granted" : "denied"
47
+ }));
48
+ const pending = requestPromise.then(({
49
+ granted,
50
+ status: nextStatus
51
+ }) => {
52
+ setStatus(nextStatus);
53
+ onPermissionChangedRef.current?.(granted);
54
+ return granted;
55
+ }).catch(error => {
56
+ setStatus("denied");
57
+ onPermissionChangedRef.current?.(false);
58
+ onRequestErrorRef.current?.(error);
59
+ throw error;
60
+ }).finally(() => {
61
+ requestInFlightRef.current = undefined;
62
+ });
63
+ requestInFlightRef.current = pending;
64
+ return pending;
65
+ }, []);
66
+ const openSettings = React.useCallback(() => {
67
+ requestOnResumeRef.current = true;
68
+ void Linking.openSettings();
69
+ }, []);
70
+ React.useEffect(() => {
71
+ let wasActive = AppState.currentState === "active";
72
+ const listener = AppState.addEventListener("change", nextState => {
73
+ const resumed = nextState === "active" && !wasActive;
74
+ wasActive = nextState === "active";
75
+ if (resumed && requestOnResumeRef.current) {
76
+ requestOnResumeRef.current = false;
77
+ void request().catch(() => undefined);
78
+ }
79
+ });
80
+ if (requestOnMount) {
81
+ void request().catch(() => undefined);
82
+ }
83
+ return () => listener.remove();
84
+ }, [request, requestOnMount]);
85
+ return {
86
+ status,
87
+ request,
88
+ requestPermission: request,
89
+ openSettings,
90
+ accessPermission: status === "unknown" ? undefined : status === "granted"
91
+ };
92
+ };
93
+ export { requestBluetoothPermission, useBluetoothPermission };
94
+ //# sourceMappingURL=use-bluetooth-permission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","AppState","Linking","Platform","PERMISSIONS","requestMultiple","sharedPermissionRequest","requestBluetoothPermissionResult","requestedPermissions","OS","Number","Version","ANDROID","BLUETOOTH_CONNECT","BLUETOOTH_SCAN","ACCESS_FINE_LOCATION","IOS","BLUETOOTH","permissionRequest","then","results","granted","length","every","permission","status","some","finally","undefined","requestBluetoothPermission","useBluetoothPermission","requestOnMount","requestPermission","onPermissionChanged","onRequestError","setStatus","useState","onPermissionChangedRef","useRef","onRequestErrorRef","requestPermissionRef","requestInFlightRef","requestOnResumeRef","current","request","useCallback","requestPromise","pending","nextStatus","catch","error","openSettings","useEffect","wasActive","currentState","listener","addEventListener","nextState","resumed","remove","accessPermission"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/use-bluetooth-permission.ts"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,cAAc;AAC1D,SAASC,WAAW,EAAEC,eAAe,QAAQ,0BAA0B;AAoBvE,IAAIC,uBAAuE;AAE3E,MAAMC,gCAAgC,GAAGA,CAAA,KAA0C;EACjF,IAAID,uBAAuB,EAAE;IAC3B,OAAOA,uBAAuB;EAChC;EAEA,MAAME,oBAAoB,GAAGL,QAAQ,CAACM,EAAE,KAAK,SAAS,GAClDC,MAAM,CAACP,QAAQ,CAACQ,OAAO,CAAC,IAAI,EAAE,GAC5B,CACEP,WAAW,CAACQ,OAAO,CAACC,iBAAiB,EACrCT,WAAW,CAACQ,OAAO,CAACE,cAAc,CACnC,GACD,CAACV,WAAW,CAACQ,OAAO,CAACG,oBAAoB,CAAC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;EAChB,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMI,YAAY,GAAGnD,KAAK,CAAC6C,WAAW,CAAC,MAAM;IAC3CH,kBAAkB,CAACC,OAAO,GAAG,IAAI;IACjC,KAAKzC,OAAO,CAACiD,YAAY,CAAC,CAAC;EAC7B,CAAC,EAAE,EAAE,CAAC;EAENnD,KAAK,CAACoD,SAAS,CAAC,MAAM;IACpB,IAAIC,SAAS,GAAGpD,QAAQ,CAACqD,YAAY,KAAK,QAAQ;IAElD,MAAMC,QAAQ,GAAGtD,QAAQ,CAACuD,gBAAgB,CAAC,QAAQ,EAAGC,SAAS,IAAK;MAClE,MAAMC,OAAO,GAAGD,SAAS,KAAK,QAAQ,IAAI,CAACJ,SAAS;MAEpDA,SAAS,GAAGI,SAAS,KAAK,QAAQ;MAElC,IAAIC,OAAO,IAAIhB,kBAAkB,CAACC,OAAO,EAAE;QACzCD,kBAAkB,CAACC,OAAO,GAAG,KAAK;QAClC,KAAKC,OAAO,CAAC,CAAC,CAACK,KAAK,CAAC,MAAMrB,SAAS,CAAC;MACvC;IACF,CAAC,CAAC;IAEF,IAAIG,cAAc,EAAE;MAClB,KAAKa,OAAO,CAAC,CAAC,CAACK,KAAK,CAAC,MAAMrB,SAAS,CAAC;IACvC;IAEA,OAAO,MAAM2B,QAAQ,CAACI,MAAM,CAAC,CAAC;EAChC,CAAC,EAAE,CAACf,OAAO,EAAEb,cAAc,CAAC,CAAC;EAE7B,OAAO;IACLN,MAAM;IACNmB,OAAO;IACPZ,iBAAiB,EAAEY,OAAO;IAC1BO,YAAY;IACZS,gBAAgB,EAAEnC,MAAM,KAAK,SAAS,GAAGG,SAAS,GAAGH,MAAM,KAAK;EAClE,CAAC;AACH,CAAC;AAED,SAEEI,0BAA0B,EAE1BC,sBAAsB","ignoreList":[]}
@@ -3,43 +3,30 @@
3
3
  /* eslint-disable import/group-exports */
4
4
 
5
5
  import * as React from "react";
6
- import { Platform } from "react-native";
7
6
  import { State } from "react-native-ble-plx";
8
- import { PERMISSIONS, requestMultiple } from "react-native-permissions";
9
- const requestBluetoothPermission = async () => {
10
- const permissions = Platform.select({
11
- android: [PERMISSIONS.ANDROID.BLUETOOTH_SCAN, PERMISSIONS.ANDROID.BLUETOOTH_CONNECT],
12
- ios: [PERMISSIONS.IOS.BLUETOOTH],
13
- default: []
14
- });
15
- const result = await requestMultiple(permissions);
16
- return Object.values(result).every(value => value === "granted");
17
- };
7
+ import { useBluetoothRuntime, useBluetoothSelector } from "./runtime-context.js";
8
+ import { useBluetoothPermission } from "./use-bluetooth-permission.js";
18
9
  export const useBluetoothState = ({
19
10
  bleManager,
20
- requestPermission = requestBluetoothPermission
11
+ requestPermission
21
12
  } = {}) => {
22
- const [state, setState] = React.useState(bleManager ? "off" : "unsupported");
13
+ const runtime = useBluetoothRuntime();
14
+ const runtimeState = useBluetoothSelector(snapshot => snapshot.bluetoothState);
15
+ const permission = useBluetoothPermission({
16
+ requestPermission
17
+ });
23
18
  React.useEffect(() => {
24
- if (!bleManager) {
25
- setState("unsupported");
19
+ if (!bleManager || bleManager === runtime.bleManager) {
26
20
  return;
27
21
  }
28
22
  const subscription = bleManager.onStateChange(nextState => {
29
- setState(nextState === State.PoweredOn ? "on" : nextState === State.Unsupported ? "unsupported" : nextState === State.Unauthorized ? "unauthorized" : "off");
23
+ runtime.setBluetoothState(nextState === State.PoweredOn ? "on" : nextState === State.Unsupported ? "unsupported" : nextState === State.Unauthorized ? "unauthorized" : "off");
30
24
  }, true);
31
25
  return () => subscription.remove();
32
- }, [bleManager]);
33
- const request = React.useCallback(async () => {
34
- const granted = await requestPermission();
35
- if (!granted) {
36
- setState("unauthorized");
37
- }
38
- return granted;
39
- }, [requestPermission]);
26
+ }, [bleManager, runtime]);
40
27
  return {
41
- state,
42
- requestPermission: request
28
+ state: permission.status === "denied" || permission.status === "blocked" ? "unauthorized" : runtimeState === "unknown" ? runtime.bleManager || bleManager ? "off" : "unsupported" : runtimeState,
29
+ requestPermission: permission.request
43
30
  };
44
31
  };
45
32
  //# sourceMappingURL=use-bluetooth-state.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","Platform","State","PERMISSIONS","requestMultiple","requestBluetoothPermission","permissions","select","android","ANDROID","BLUETOOTH_SCAN","BLUETOOTH_CONNECT","ios","IOS","BLUETOOTH","default","result","Object","values","every","value","useBluetoothState","bleManager","requestPermission","state","setState","useState","useEffect","subscription","onStateChange","nextState","PoweredOn","Unsupported","Unauthorized","remove","request","useCallback","granted"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/use-bluetooth-state.ts"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,cAAc;AACvC,SAAqBC,KAAK,QAAQ,sBAAsB;AACxD,SAASC,WAAW,EAAEC,eAAe,QAAQ,0BAA0B;AASvE,MAAMC,0BAA0B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,MAAMC,WAAW,GAAGL,QAAQ,CAACM,MAAM,CAAC;IAClCC,OAAO,EAAE,CACPL,WAAW,CAACM,OAAO,CAACC,cAAc,EAClCP,WAAW,CAACM,OAAO,CAACE,iBAAiB,CACtC;IACDC,GAAG,EAAE,CAACT,WAAW,CAACU,GAAG,CAACC,SAAS,CAAC;IAChCC,OAAO,EAAE;EACX,CAAC,CAAC;EAEF,MAAMC,MAAM,GAAG,MAAMZ,eAAe,CAACE,WAAW,CAAC;EAEjD,OAAOW,MAAM,CAACC,MAAM,CAACF,MAAM,CAAC,CAACG,KAAK,CAAEC,KAAK,IAAKA,KAAK,KAAK,SAAS,CAAC;AACpE,CAAC;AAED,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,UAAU;EACVC,iBAAiB,GAAGlB;AACI,CAAC,GAAG,CAAC,CAAC,KAG3B;EACH,MAAM,CAACmB,KAAK,EAAEC,QAAQ,CAAC,GAAGzB,KAAK,CAAC0B,QAAQ,CACtCJ,UAAU,GAAG,KAAK,GAAG,aACvB,CAAC;EAEDtB,KAAK,CAAC2B,SAAS,CAAC,MAAM;IACpB,IAAI,CAACL,UAAU,EAAE;MACfG,QAAQ,CAAC,aAAa,CAAC;MAEvB;IACF;IAEA,MAAMG,YAAY,GAAGN,UAAU,CAACO,aAAa,CAAEC,SAAS,IAAK;MAC3DL,QAAQ,CACNK,SAAS,KAAK5B,KAAK,CAAC6B,SAAS,GACzB,IAAI,GACJD,SAAS,KAAK5B,KAAK,CAAC8B,WAAW,GAC7B,aAAa,GACbF,SAAS,KAAK5B,KAAK,CAAC+B,YAAY,GAC9B,cAAc,GACd,KACV,CAAC;IACH,CAAC,EAAE,IAAI,CAAC;IAER,OAAO,MAAML,YAAY,CAACM,MAAM,CAAC,CAAC;EACpC,CAAC,EAAE,CAACZ,UAAU,CAAC,CAAC;EAEhB,MAAMa,OAAO,GAAGnC,KAAK,CAACoC,WAAW,CAAC,YAAY;IAC5C,MAAMC,OAAO,GAAG,MAAMd,iBAAiB,CAAC,CAAC;IAEzC,IAAI,CAACc,OAAO,EAAE;MAACZ,QAAQ,CAAC,cAAc,CAAC;IAAC;IAExC,OAAOY,OAAO;EAChB,CAAC,EAAE,CAACd,iBAAiB,CAAC,CAAC;EAEvB,OAAO;IAAEC,KAAK;IAAED,iBAAiB,EAAEY;EAAQ,CAAC;AAC9C,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","State","useBluetoothRuntime","useBluetoothSelector","useBluetoothPermission","useBluetoothState","bleManager","requestPermission","runtime","runtimeState","snapshot","bluetoothState","permission","useEffect","subscription","onStateChange","nextState","setBluetoothState","PoweredOn","Unsupported","Unauthorized","remove","state","status","request"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/hooks/use-bluetooth-state.ts"],"mappings":";;AAAA;;AAEA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAqBC,KAAK,QAAQ,sBAAsB;AAExD,SAASC,mBAAmB,EAAEC,oBAAoB,QAAQ,sBAAmB;AAC7E,SAASC,sBAAsB,QAAQ,+BAA4B;AASnE,OAAO,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,UAAU;EACVC;AACwB,CAAC,GAAG,CAAC,CAAC,KAG3B;EACH,MAAMC,OAAO,GAAGN,mBAAmB,CAAC,CAAC;EACrC,MAAMO,YAAY,GAAGN,oBAAoB,CAAEO,QAAQ,IAAKA,QAAQ,CAACC,cAAc,CAAC;EAChF,MAAMC,UAAU,GAAGR,sBAAsB,CAAC;IAAEG;EAAkB,CAAC,CAAC;EAEhEP,KAAK,CAACa,SAAS,CAAC,MAAM;IACpB,IAAI,CAACP,UAAU,IAAIA,UAAU,KAAKE,OAAO,CAACF,UAAU,EAAE;MACpD;IACF;IAEA,MAAMQ,YAAY,GAAGR,UAAU,CAACS,aAAa,CAAEC,SAAS,IAAK;MAC3DR,OAAO,CAACS,iBAAiB,CACvBD,SAAS,KAAKf,KAAK,CAACiB,SAAS,GACzB,IAAI,GACJF,SAAS,KAAKf,KAAK,CAACkB,WAAW,GAC7B,aAAa,GACbH,SAAS,KAAKf,KAAK,CAACmB,YAAY,GAC9B,cAAc,GACd,KACV,CAAC;IACH,CAAC,EAAE,IAAI,CAAC;IAER,OAAO,MAAMN,YAAY,CAACO,MAAM,CAAC,CAAC;EACpC,CAAC,EAAE,CAACf,UAAU,EAAEE,OAAO,CAAC,CAAC;EAEzB,OAAO;IACLc,KAAK,EAAEV,UAAU,CAACW,MAAM,KAAK,QAAQ,IAAIX,UAAU,CAACW,MAAM,KAAK,SAAS,GACpE,cAAc,GACdd,YAAY,KAAK,SAAS,GACxBD,OAAO,CAACF,UAAU,IAAIA,UAAU,GAC9B,KAAK,GACL,aAAa,GACfG,YAAY;IAClBF,iBAAiB,EAAEK,UAAU,CAACY;EAChC,CAAC;AACH,CAAC","ignoreList":[]}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ import * as React from "react";
4
+ import { useBluetoothRuntime, useBluetoothSelector } from "./runtime-context.js";
5
+ class DeviceSelectionRequiredError extends Error {
6
+ constructor(model, ids) {
7
+ super(`Choose a device ID for ${model}; found ${ids.join(", ")}.`);
8
+ this.name = "DeviceSelectionRequiredError";
9
+ }
10
+ }
11
+ const EMPTY_RESULTS = [];
12
+ const EMPTY_EVENTS = [];
13
+ const deviceQueues = new WeakMap();
14
+ const serializeForDevice = (runtime, deviceId, operation) => {
15
+ let queues = deviceQueues.get(runtime);
16
+ if (!queues) {
17
+ queues = new Map();
18
+ deviceQueues.set(runtime, queues);
19
+ }
20
+ const previous = queues.get(deviceId) ?? Promise.resolve();
21
+ const current = previous.catch(() => undefined).then(operation);
22
+ queues.set(deviceId, current);
23
+ void current.finally(() => {
24
+ if (queues?.get(deviceId) === current) {
25
+ queues.delete(deviceId);
26
+ }
27
+ }).catch(() => undefined);
28
+ return current;
29
+ };
30
+ const getRawDevice = device => device.device.device;
31
+ const useBTDevice = (model, {
32
+ id,
33
+ autoConnect = false,
34
+ allowRawAccess = false
35
+ } = {}) => {
36
+ const runtime = useBluetoothRuntime();
37
+ const [selectedId, setSelectedId] = React.useState(id);
38
+ const matches = useBluetoothSelector(snapshot => snapshot.devices.filter(device => device.deviceData.name === model || device.deviceData.model === model), (previous, next) => previous.length === next.length && previous.every((item, index) => {
39
+ const candidate = next[index];
40
+ return candidate?.id === item.id && candidate === item;
41
+ }));
42
+ const selected = selectedId ? matches.find(device => device.id === selectedId) : matches.length === 1 ? matches[0] : undefined;
43
+ const selectedIdRef = React.useRef(selectedId);
44
+ const matchesRef = React.useRef(matches);
45
+ const modelRef = React.useRef(model);
46
+ const autoConnectedRef = React.useRef(new Set());
47
+ selectedIdRef.current = selectedId;
48
+ matchesRef.current = matches;
49
+ modelRef.current = model;
50
+ React.useEffect(() => {
51
+ if (id !== undefined) {
52
+ setSelectedId(id);
53
+ }
54
+ }, [id]);
55
+ React.useEffect(() => {
56
+ if (!autoConnect || !selected) {
57
+ return;
58
+ }
59
+ if (autoConnectedRef.current.has(selected.id)) {
60
+ return;
61
+ }
62
+ autoConnectedRef.current.add(selected.id);
63
+ void selected.device.connect().catch(() => {
64
+ autoConnectedRef.current.delete(selected.id);
65
+ });
66
+ }, [autoConnect, selected]);
67
+ const select = React.useCallback(deviceId => {
68
+ if (!matchesRef.current.some(device => device.id === deviceId)) {
69
+ return false;
70
+ }
71
+ setSelectedId(deviceId);
72
+ return true;
73
+ }, []);
74
+ const connect = React.useCallback(async () => {
75
+ const currentMatches = matchesRef.current;
76
+ const device = currentMatches.find(candidate => candidate.id === selectedIdRef.current) ?? (currentMatches.length === 1 ? currentMatches[0] : undefined);
77
+ if (!device) {
78
+ throw new DeviceSelectionRequiredError(modelRef.current, currentMatches.map(candidate => candidate.id));
79
+ }
80
+ await device.device.connect();
81
+ }, []);
82
+ const disconnect = React.useCallback(async () => {
83
+ const currentMatches = matchesRef.current;
84
+ const device = currentMatches.find(candidate => candidate.id === selectedIdRef.current) ?? (currentMatches.length === 1 ? currentMatches[0] : undefined);
85
+ if (!device) {
86
+ throw new DeviceSelectionRequiredError(modelRef.current, currentMatches.map(candidate => candidate.id));
87
+ }
88
+ await device.device.disconnect();
89
+ }, []);
90
+ const raw = React.useMemo(() => {
91
+ if (!allowRawAccess) {
92
+ return undefined;
93
+ }
94
+ const resolveDevice = () => {
95
+ const currentMatches = matchesRef.current;
96
+ const device = currentMatches.find(candidate => candidate.id === selectedIdRef.current) ?? (currentMatches.length === 1 ? currentMatches[0] : undefined);
97
+ if (!device) {
98
+ throw new DeviceSelectionRequiredError(modelRef.current, currentMatches.map(candidate => candidate.id));
99
+ }
100
+ const rawDevice = getRawDevice(device);
101
+ if (!rawDevice) {
102
+ throw new Error("Raw Bluetooth access is unavailable for this device.");
103
+ }
104
+ return {
105
+ device,
106
+ rawDevice
107
+ };
108
+ };
109
+ return {
110
+ read: (serviceUUID, characteristicUUID) => {
111
+ const {
112
+ device,
113
+ rawDevice
114
+ } = resolveDevice();
115
+ return serializeForDevice(runtime, device.id, () => rawDevice.readCharacteristicForService(serviceUUID, characteristicUUID));
116
+ },
117
+ write: (serviceUUID, characteristicUUID, base64Value, withResponse = true) => {
118
+ const {
119
+ device,
120
+ rawDevice
121
+ } = resolveDevice();
122
+ return serializeForDevice(runtime, device.id, () => withResponse ? rawDevice.writeCharacteristicWithResponseForService(serviceUUID, characteristicUUID, base64Value) : rawDevice.writeCharacteristicWithoutResponseForService(serviceUUID, characteristicUUID, base64Value));
123
+ }
124
+ };
125
+ }, [allowRawAccess, runtime]);
126
+ return {
127
+ model,
128
+ devices: matches,
129
+ device: selected,
130
+ requiresSelection: matches.length > 1 && selected === undefined,
131
+ status: selected?.status,
132
+ latestResult: selected?.latestResult,
133
+ results: selected?.results ?? EMPTY_RESULTS,
134
+ events: selected?.events ?? EMPTY_EVENTS,
135
+ select,
136
+ connect,
137
+ disconnect,
138
+ raw
139
+ };
140
+ };
141
+ export { DeviceSelectionRequiredError, useBTDevice };
142
+ //# sourceMappingURL=use-bt-device.js.map