Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ atomicfu = "0.29.0"
coroutines = "1.10.2"
jna = "5.18.1"
jvm-toolchain = "17"
kotlin = "2.2.20"
kotlin = "2.2.21"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, just curious if this bump was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.2.21 contained some fixes around exception handling for WASM in Safari based browsers

tuulbox = "8.1.0"

[libraries]
Expand All @@ -16,6 +16,7 @@ equalsverifier = { module = "nl.jqno.equalsverifier:equalsverifier", version = "
jna = { module = "net.java.dev.jna:jna", version.ref = "jna" }
khronicle = { module = "com.juul.khronicle:khronicle-core", version = "0.6.0" }
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version = "0.5.0" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
Expand All @@ -26,6 +27,7 @@ tomlkt = { module = "net.peanuuutz.tomlkt:tomlkt", version = "0.5.0" }
tuulbox-collections = { module = "com.juul.tuulbox:collections", version.ref = "tuulbox" }
tuulbox-coroutines = { module = "com.juul.tuulbox:coroutines", version.ref = "tuulbox" }
wrappers-bom = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom", version = "2025.12.6" }
wrappers-browser = { module = "org.jetbrains.kotlin-wrappers:kotlin-browser" }
wrappers-web = { module = "org.jetbrains.kotlin-wrappers:kotlin-web" }

[plugins]
Expand Down
7 changes: 5 additions & 2 deletions kable-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ kotlin {
macosArm64()
macosX64()
jvm()
wasmJs().browser()

sourceSets {
all {
languageSettings {
optIn("kotlin.js.ExperimentalWasmJsInterop")
optIn("kotlin.uuid.ExperimentalUuidApi")
}
}

commonMain.dependencies {
api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.io)
implementation(libs.tuulbox.collections)
}

commonTest.dependencies {
Expand Down Expand Up @@ -59,7 +60,9 @@ kotlin {
implementation(libs.robolectric)
}

jsMain.dependencies {
webMain.dependencies {
api(libs.kotlinx.browser)
api(libs.wrappers.browser)
api(libs.wrappers.web)
api(project.dependencies.platform(libs.wrappers.bom))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.juul.kable.logs.Logger
import com.juul.kable.logs.Logging
import com.juul.kable.logs.Logging.DataProcessor.Operation
import com.juul.kable.logs.detail
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
Expand All @@ -41,7 +42,6 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Duration

// Number of service discovery attempts to make if no services are discovered.
Expand Down Expand Up @@ -154,7 +154,7 @@ internal class BluetoothDeviceAndroidPeripheral(

override suspend fun disconnect() {
connectAction.cancelAndJoin(
CancellationException(NotConnectedException("Disconnect requested")),
CancellationException(null, NotConnectedException("Disconnect requested")),
)
}

Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/androidMain/kotlin/Connection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.juul.kable.gatt.Response
import com.juul.kable.gatt.Response.OnServicesDiscovered
import com.juul.kable.logs.Logger
import com.juul.kable.logs.Logging
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineName
Expand All @@ -36,7 +37,6 @@ import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.cancellation.CancellationException
import kotlin.coroutines.coroutineContext
import kotlin.reflect.KClass
import kotlin.time.Duration
Expand Down
4 changes: 2 additions & 2 deletions kable-core/src/androidMain/kotlin/ThreadingStrategy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.juul.kable.OnDemandThreadingStrategy.release
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.locks.reentrantLock
import kotlinx.atomicfu.locks.withLock
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
import kotlin.time.TimeMark
Expand Down Expand Up @@ -72,7 +72,7 @@ public class PooledThreadingStrategy(
"PooledThreadStrategy must complete with an empty pool, but had ${pool.count()} threads in pool"
}
}
throw CancellationException(e)
throw CancellationException(null, e)
}
}

Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/appleMain/kotlin/Connection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.juul.kable.State.Disconnected
import com.juul.kable.coroutines.childSupervisor
import com.juul.kable.logs.Logger
import com.juul.kable.logs.Logging
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -36,7 +37,6 @@ import platform.CoreBluetooth.CBPeripheral
import platform.CoreBluetooth.CBService
import platform.CoreBluetooth.CBUUID
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.cancellation.CancellationException
import kotlin.coroutines.coroutineContext
import kotlin.reflect.KClass
import kotlin.time.Duration
Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/appleMain/kotlin/CoreBluetoothPeripheral.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.juul.kable

import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.Flow
import kotlinx.io.IOException
import platform.Foundation.NSData
import kotlin.coroutines.cancellation.CancellationException

public interface CoreBluetoothPeripheral : Peripheral {

Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/appleMain/kotlin/PeripheralBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.juul.kable

import com.juul.kable.logs.Logging
import com.juul.kable.logs.LoggingBuilder
import kotlinx.coroutines.CancellationException
import kotlinx.io.IOException
import kotlin.coroutines.cancellation.CancellationException
import kotlin.time.Duration

public actual class ServicesDiscoveredPeripheral internal constructor(
Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/commonMain/kotlin/Observers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.juul.kable.ObservationEvent.Error
import com.juul.kable.logs.Logging
import kotlinx.atomicfu.locks.SynchronizedObject
import kotlinx.atomicfu.locks.synchronized
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.Flow
Expand All @@ -16,7 +17,6 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onSubscription
import kotlinx.coroutines.withContext
import kotlinx.io.IOException
import kotlin.coroutines.cancellation.CancellationException
import kotlin.coroutines.coroutineContext

internal expect fun Peripheral.observationHandler(): Observation.Handler
Expand Down
2 changes: 1 addition & 1 deletion kable-core/src/commonMain/kotlin/Peripheral.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package com.juul.kable

import com.juul.kable.State.Disconnecting
import com.juul.kable.WriteType.WithoutResponse
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onEach
import kotlinx.io.IOException
import kotlin.coroutines.cancellation.CancellationException
import kotlin.jvm.JvmName

internal typealias OnSubscriptionAction = suspend () -> Unit
Expand Down
36 changes: 0 additions & 36 deletions kable-core/src/jsMain/kotlin/Bluetooth.kt

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions kable-core/src/jsMain/kotlin/external/Navigator.kt

This file was deleted.

6 changes: 6 additions & 0 deletions kable-core/src/jsMain/kotlin/interop/Await.js.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.juul.kable.interop

import kotlin.js.Promise
import kotlinx.coroutines.await as kotlinxAwait

internal actual suspend fun <T : JsAny?> Promise<T>.await(): T = kotlinxAwait()
48 changes: 0 additions & 48 deletions kable-core/src/jsMain/kotlin/logs/SystemLogEngine.kt

This file was deleted.

9 changes: 0 additions & 9 deletions kable-core/src/jsTest/kotlin/Environment.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.juul.kable.suspendUntil
import com.juul.kable.unwrapCancellationException
import jdk.internal.joptsimple.internal.Messages.message
import jdk.internal.org.objectweb.asm.Type.getDescriptor
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
Expand All @@ -45,7 +46,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.io.IOException
import kotlin.coroutines.cancellation.CancellationException
import com.juul.kable.btleplug.ffi.Uuid as FfiUuid

private const val DEFAULT_ATT_MTU = 23
Expand Down Expand Up @@ -75,7 +75,7 @@ internal class BtleplugPeripheral(
override fun disconnected() {
logger.verbose { message = "Received disconnect" }
runBlocking {
connectAction.cancelAndJoin(CancellationException(NotConnectedException("Disconnected")))
connectAction.cancelAndJoin(CancellationException(null, NotConnectedException("Disconnected")))
}
}

Expand Down Expand Up @@ -182,7 +182,7 @@ internal class BtleplugPeripheral(

override suspend fun disconnect() {
logger.verbose { message = "Disconnect request" }
connectAction.cancelAndJoin(CancellationException(NotConnectedException("Disconnect requested")))
connectAction.cancelAndJoin(CancellationException(null, NotConnectedException("Disconnect requested")))
}

override suspend fun maximumWriteValueLengthForType(writeType: WriteType): Int =
Expand Down
6 changes: 6 additions & 0 deletions kable-core/src/wasmJsMain/kotlin/interop/Await.wasmJs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.juul.kable.interop

import kotlin.js.Promise
import kotlinx.coroutines.await as kotlinxAwait

internal actual suspend fun <T : JsAny?> Promise<T>.await(): T = kotlinxAwait()
27 changes: 27 additions & 0 deletions kable-core/src/webMain/kotlin/Bluetooth.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.juul.kable

import com.juul.kable.external.Bluetooth
import com.juul.kable.external.getBluetooth
import web.navigator.Navigator
import kotlin.js.js
import kotlin.js.undefined

private val navigator: Navigator =
js("window.navigator")

/**
* @return [Bluetooth] object or `null` if bluetooth is [unavailable](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth#browser_compatibility).
*/
internal fun bluetoothOrNull(): Bluetooth? =
getBluetooth(navigator).takeIf { it !== undefined }

/**
* @throws IllegalStateException If bluetooth is [unavailable](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth#browser_compatibility).
*/
internal fun bluetoothOrThrow(): Bluetooth {
val bluetooth = getBluetooth(navigator)
if (bluetooth === undefined) {
error("Bluetooth unavailable")
}
return bluetooth
}
Loading
Loading