Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package io.github.openflocon.flocon.qrscanner

import android.content.Context
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
import io.github.openflocon.flocon.Flocon
import io.github.openflocon.flocon.FloconConnectResult
import io.github.openflocon.flocon.connect
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume

/**
* Opens the Google code scanner, then connects to the desktop app at the address held by the QR code
* it reads, see [connectWithQrCode].
* it reads. The QR code of Flocon Desktop holds only the IP address of the computer, the same value as
* `Flocon.connect(address)`.
*
* The scanner is a screen of Google Play Services: the app needs no camera permission. It requires
* Google Play Services on the device, otherwise the result is [FloconConnectResult.Failed].
* Google Play Services on the device, otherwise the result is [FloconConnectResult.Failed]: connect with
* `Flocon.connect(address)` instead.
*
* ```
* val result = Flocon.scanQrCodeAndConnect(context)
Expand All @@ -23,12 +28,16 @@ import kotlin.coroutines.resume
* @param context preferably an `Activity`.
* @return the result of the connection, or `null` if the user closed the scanner without scanning.
*/
suspend fun Flocon.Companion.scanQrCodeAndConnect(context: Context): FloconConnectResult? =
when (val scan = scanQrCode(context)) {
suspend fun Flocon.Companion.scanQrCodeAndConnect(context: Context): FloconConnectResult? {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) != ConnectionResult.SUCCESS) {
return FloconConnectResult.Failed("Google Play Services is required to scan a QR code: connect with the IP address instead")
}
return when (val scan = scanQrCode(context)) {
ScanQrCodeResult.Cancelled -> null
is ScanQrCodeResult.Failed -> FloconConnectResult.Failed(scan.reason)
is ScanQrCodeResult.Code -> connectWithQrCode(scan.content)
is ScanQrCodeResult.Code -> connect(scan.content)
}
}

private sealed interface ScanQrCodeResult {
data class Code(val content: String) : ScanQrCodeResult
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ Until a desktop is reachable, everything the plugins log is kept in memory. `Flo

### Connecting with a QR code

The desktop app has a **Connect** button in the top bar (QR code icon). It opens a dialog listing the IP addresses of the computer on the local network (one per network interface) and, for each one, a button that shows the address as a QR code. The QR code contains only the IP address, the same value as `Flocon.connect("192.168.1.20")`. Scanning it from the SDK is not available yet.
The desktop app has a **Connect** button in the top bar (QR code icon). It opens a dialog listing the IP addresses of the computer on the local network (one per network interface) and, for each one, a button that shows the address as a QR code. The QR code contains only the IP address, the same value as `Flocon.connect("192.168.1.20")`.

To scan it from the app, add the optional `flocon-qr-scanner` module (and `flocon-qr-scanner-no-op` for release builds). `Flocon.scanQrCodeAndConnect(context)` opens the Google code scanner (a Google Play Services screen, no camera permission needed), then connects. It returns the `FloconConnectResult`, or `null` if the user closes the scanner. Without Google Play Services (an AOSP emulator, a Huawei device) it returns `Failed`: use `Flocon.connect("192.168.1.20")` instead. To use your own camera screen, pass the text it reads to `Flocon.connect(address)`.

Up to 5000 messages are kept: above that, the oldest are dropped. `connect { bufferCapacity = ... }` changes this size.

Expand Down
Loading