ScannerViewModel

open class ScannerViewModel(serviceRepository: ServiceRepository, radioController: RadioController, radioInterfaceService: RadioInterfaceService, radioPrefs: RadioPrefs, recentAddressesDataSource: RecentAddressesDataSource, getDiscoveredDevicesUseCase: GetDiscoveredDevicesUseCase, networkRepository: NetworkRepository, dispatchers: CoroutineDispatchers, uiPrefs: UiPrefs, bleScanner: BleScanner? = null) : ViewModel(source)

Platform-neutral ViewModel that drives the Connections screen: device discovery (BLE/USB/TCP), scan state, current selection, and connection-progress chatter.

Subclassed per-platform (see AndroidScannerViewModel, JvmScannerViewModel) to plug in platform-specific bonding / permission flows.

Inheritors

Constructors

Link copied to clipboard
constructor(serviceRepository: ServiceRepository, radioController: RadioController, radioInterfaceService: RadioInterfaceService, radioPrefs: RadioPrefs, recentAddressesDataSource: RecentAddressesDataSource, getDiscoveredDevicesUseCase: GetDiscoveredDevicesUseCase, networkRepository: NetworkRepository, dispatchers: CoroutineDispatchers, uiPrefs: UiPrefs, bleScanner: BleScanner? = null)

Properties

Link copied to clipboard
val bleAutoScan: StateFlow<Boolean>

User preference that controls whether BLE scanning auto-starts when the Connections screen opens.

Link copied to clipboard

Combined bonded + scanned BLE devices for the UI.

Link copied to clipboard

Transient, fine-grained status text emitted during connect/bonding (e.g. "Bonding…", "Requesting config…"). Nullable because serviceRepository.connectionProgress does not emit during steady-state.

Link copied to clipboard
Link copied to clipboard
val isBleScanning: StateFlow<Boolean>
Link copied to clipboard
val isNetworkScanning: StateFlow<Boolean>
Link copied to clipboard
val networkAutoScan: StateFlow<Boolean>

User preference that controls whether NSD network scanning auto-starts when the Connections screen opens.

Link copied to clipboard
val persistedDeviceName: StateFlow<String?>

The persisted device name from the last selection, for use as a UI fallback.

Link copied to clipboard
Link copied to clipboard
val selectedAddressFlow: StateFlow<String?>
Link copied to clipboard
val selectedNotNullFlow: StateFlow<String>

Non-null variant of selectedAddressFlow that substitutes NO_DEVICE_SELECTED for null.

Link copied to clipboard
val showBleTransport: StateFlow<Boolean>

Whether the BLE section is visible in the Connections device list. Defaults to true.

Link copied to clipboard
val showMockTransport: StateFlow<Boolean>
Link copied to clipboard

Whether the Network (TCP/NSD) section is visible in the Connections device list. Defaults to true.

Link copied to clipboard
val showUsbTransport: StateFlow<Boolean>

Whether the USB section is visible in the Connections device list. Defaults to true.

Link copied to clipboard

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun addRecentAddress(address: String, name: String)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard

Called by the UI when a device has been tapped. BLE and USB entries may still need bonding/permission — the concrete return value tells the caller whether the connection was initiated immediately.

Link copied to clipboard

Persist the user's intent to auto-scan the network on next screen entry without flipping the active scan flag. Used by the Connections screen when it must defer the actual scan start until after the system permission grant dialog resolves — the persisted intent ensures auto-start fires once permission is granted.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Convenience command: start scanning if idle, stop otherwise. Persists the resulting state to prefs.

Link copied to clipboard

Convenience command: start scanning if idle, stop otherwise. Persists the resulting state to prefs.