Runtime setup helpers for Bluetooth and WiFi functionality.
This module provides functions that can be called from your app's startup code to ensure Bluetooth and WiFi are properly configured and available.
Usage
In your app's Dala.App module or in a screen's mount/3:
def mount(_params, _session, socket) do
# Check and request permissions at startup
Dala.Setup.ensure_bluetooth_permissions(socket)
Dala.Setup.ensure_wifi_permissions(socket)
{:ok, socket}
endPlatform Notes
- iOS: Requires usage descriptions in Info.plist (see
mix dala.setup_bluetooth_wifi) - Android: Requires permissions in AndroidManifest.xml and runtime permission requests
Summary
Functions
Check if Bluetooth is available and properly configured.
Check if WiFi is available and properly configured.
Run a full diagnostic of Bluetooth and WiFi setup.
Ensure Bluetooth permissions are granted.
Ensure WiFi permissions are granted (Android only).
Print a human-readable diagnostic report to the console.
Functions
@spec check_bluetooth() :: {:ok, Dala.Bluetooth.state()} | {:error, term()}
Check if Bluetooth is available and properly configured.
Returns:
{:ok, state} - Bluetooth is available, returns current state
{:error, reason} - Bluetooth is not available or not configured
Check if WiFi is available and properly configured.
Returns:
{:ok, info} - WiFi is available, returns current network info
{:error, reason} - WiFi is not available or not configured
@spec diagnostic() :: map()
Run a full diagnostic of Bluetooth and WiFi setup.
Returns a map with the status of each component.
Example:
Dala.Setup.diagnostic()
# => %{
# bluetooth: %{available: true, state: :powered_on, permission: :granted},
# wifi: %{available: true, connected: true, ssid: "MyNetwork"}
# }
@spec ensure_bluetooth_permissions(Dala.Ui.Socket.t()) :: Dala.Ui.Socket.t()
Ensure Bluetooth permissions are granted.
On Android, this will trigger a runtime permission request if needed. On iOS, this checks if the permission is granted (must be configured in Info.plist).
Returns the updated socket.
@spec ensure_wifi_permissions(Dala.Ui.Socket.t()) :: Dala.Ui.Socket.t()
Ensure WiFi permissions are granted (Android only).
On Android, WiFi scanning requires location permission. On iOS, WiFi info access is limited and may not require explicit permission.
Returns the updated socket.
Print a human-readable diagnostic report to the console.
Useful for debugging during development.