@@ -3,10 +3,48 @@ package com.juul.kable
33import com.benasher44.uuid.Uuid
44
55/* * https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice */
6- public data class Options (
6+ public fun Options (builder : OptionsBuilder .() -> Unit ): Options =
7+ OptionsBuilder ().apply (builder).build()
8+
9+ @Deprecated(
10+ message = " Use Options builder instead. See https://github.com/JuulLabs/kable/issues/723 for details." ,
11+ replaceWith = ReplaceWith (" Options { }" ),
12+ )
13+ public fun Options (
14+ filters : List <Filter >? = null,
15+ filterSets : List <FilterSet >? = null,
16+ optionalServices : List <Uuid >? = null,
17+ ): Options = Options {
18+ filters {
19+ if (filters != null ) {
20+ filters.forEach { filter ->
21+ match {
22+ when (filter) {
23+ is Filter .Name -> name = filter
24+ is Filter .Service -> services = listOf (filter.uuid)
25+ is Filter .ManufacturerData -> manufacturerData = listOf (filter)
26+ is Filter .Address -> { /* no-op */ }
27+ }
28+ }
29+ }
30+ } else if (filterSets != null ) {
31+ filterSets.forEach { filterSet ->
32+ match {
33+ name = filterSet.name
34+ services = filterSet.services.map { it.uuid }
35+ manufacturerData = filterSet.manufacturerData
36+ }
37+ }
38+ }
39+ }
40+ this .optionalServices = optionalServices
41+ }
42+
43+ public data class Options internal constructor(
44+
745 @Deprecated(
8- message = " Replaced with filters builder DSL" ,
9- replaceWith = ReplaceWith (" filters = { }" ),
46+ message = " Replaced with filters builder DSL. See https://github.com/JuulLabs/kable/issues/723 for details. " ,
47+ replaceWith = ReplaceWith (" Options { filters { } }" ),
1048 level = DeprecationLevel .WARNING ,
1149 )
1250 val filterSets : List <FilterSet >? = null ,
@@ -17,17 +55,11 @@ public data class Options(
1755 *
1856 * https://webbluetoothcg.github.io/web-bluetooth/#device-discovery
1957 */
58+ @Deprecated(
59+ message = " Use Options builder instead. See https://github.com/JuulLabs/kable/issues/723 for details." ,
60+ replaceWith = ReplaceWith (" Options { optionalServices = listOf() }" ),
61+ )
2062 val optionalServices : List <Uuid >? = null ,
2163
22- /* *
23- * Filters to apply when requesting devices. If predicates are non-empty, then only devices
24- * that match at least one of the predicates will appear in the `requestDevice` picker.
25- *
26- * Filtering on Service Data is not supported because it is not implemented:
27- * https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md
28- *
29- * Filtering on Manufacturer Data is supported and a good explanation can be found here:
30- * https://github.com/WebBluetoothCG/web-bluetooth/blob/main/data-filters-explainer.md
31- */
32- val filters : FiltersBuilder .() -> Unit = { },
64+ internal val filterPredicates : List <FilterPredicate >,
3365)
0 commit comments