Skip to content

Commit

Permalink
Deprecate Bluetooth.availability
Browse files Browse the repository at this point in the history
  • Loading branch information
twyatt committed Oct 7, 2024
1 parent 8b85a59 commit abd9f43
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kable-core/src/androidMain/kotlin/Bluetooth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,38 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED as BLUETOOTH_STATE_CHANGED

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public actual enum class Reason {
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Off, // BluetoothAdapter.STATE_OFF

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
TurningOff, // BluetoothAdapter.STATE_TURNING_OFF or BluetoothAdapter.STATE_BLE_TURNING_OFF

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
TurningOn, // BluetoothAdapter.STATE_TURNING_ON or BluetoothAdapter.STATE_BLE_TURNING_ON

/**
* [BluetoothManager] unavailable or [BluetoothManager.getAdapter] returned `null` (indicating
* that Bluetooth is not available).
*/
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
AdapterNotAvailable,

/** Only applicable on Android 11 (API 30) and lower. */
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
LocationServicesDisabled,
}

Expand Down
22 changes: 22 additions & 0 deletions kable-core/src/appleMain/kotlin/Bluetooth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,33 @@ import platform.CoreBluetooth.CBCentralManagerStateUnauthorized
import platform.CoreBluetooth.CBCentralManagerStateUnsupported

/** https://developer.apple.com/documentation/corebluetooth/cbmanagerstate */
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public actual enum class Reason {
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Off, // CBManagerState.poweredOff

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Resetting, // CBManagerState.resetting

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Unauthorized, // CBManagerState.unauthorized

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Unsupported, // CBManagerState.unsupported

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
Unknown, // CBManagerState.unknown
}

Expand Down
16 changes: 16 additions & 0 deletions kable-core/src/commonMain/kotlin/Bluetooth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import kotlinx.coroutines.flow.Flow
import kotlin.jvm.JvmName
import com.juul.kable.bluetooth.isSupported as isBluetoothSupported

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public expect enum class Reason

public object Bluetooth {
Expand All @@ -30,11 +33,24 @@ public object Bluetooth {
override fun toString(): String = "00000000-0000-1000-8000-00805F9B34FB"
}

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public sealed class Availability {
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public data object Available : Availability()

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public data class Unavailable(val reason: Reason?) : Availability()
}

@Deprecated(
message = "Has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public val availability: Flow<Availability> = bluetoothAvailability

/**
Expand Down
6 changes: 6 additions & 0 deletions kable-core/src/jsMain/kotlin/BluetoothAvailability.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.onStart
import org.w3c.dom.events.Event

@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
public actual enum class Reason {
/** `window.navigator.bluetooth` is undefined. */
@Deprecated(
message = "`Bluetooth.availability` has inconsistent behavior across platforms. Will be removed in a future release. See https://github.com/JuulLabs/kable/issues/737 for more details.",
)
BluetoothUndefined,
}

Expand Down

0 comments on commit abd9f43

Please sign in to comment.