Added toggle to be able to disable local functionality for sync. Sync now automatically closes when pairing is successful. Pairing in progress layouts now properly show again.

This commit is contained in:
Koen J 2025-05-05 13:34:52 +02:00
commit 1e790d1aa9
5 changed files with 41 additions and 29 deletions

View file

@ -948,6 +948,9 @@ class Settings : FragmentedStorageFileJson() {
@FormField(R.string.connect_local_direct_through_relay, FieldForm.TOGGLE, R.string.connect_local_direct_through_relay_description, 3) @FormField(R.string.connect_local_direct_through_relay, FieldForm.TOGGLE, R.string.connect_local_direct_through_relay_description, 3)
var connectLocalDirectThroughRelay: Boolean = true; var connectLocalDirectThroughRelay: Boolean = true;
@FormField(R.string.local_connections, FieldForm.TOGGLE, R.string.local_connections_description, 3)
var localConnections: Boolean = true;
} }
@FormField(R.string.info, FieldForm.GROUP, -1, 21) @FormField(R.string.info, FieldForm.GROUP, -1, 21)

View file

@ -83,6 +83,7 @@ class SyncPairActivity : AppCompatActivity() {
_layoutPairingSuccess.setOnClickListener { _layoutPairingSuccess.setOnClickListener {
_layoutPairingSuccess.visibility = View.GONE _layoutPairingSuccess.visibility = View.GONE
finish()
} }
_layoutPairingError.setOnClickListener { _layoutPairingError.setOnClickListener {
_layoutPairingError.visibility = View.GONE _layoutPairingError.visibility = View.GONE
@ -111,9 +112,15 @@ class SyncPairActivity : AppCompatActivity() {
try { try {
StateSync.instance.connect(deviceInfo) { complete, message -> StateSync.instance.connect(deviceInfo) { complete, message ->
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
if (complete != null && complete) { if (complete != null) {
_layoutPairingSuccess.visibility = View.VISIBLE if (complete) {
_layoutPairing.visibility = View.GONE _layoutPairingSuccess.visibility = View.VISIBLE
_layoutPairing.visibility = View.GONE
} else {
_textError.text = message
_layoutPairingError.visibility = View.VISIBLE
_layoutPairing.visibility = View.GONE
}
} else { } else {
_textPairingStatus.text = message _textPairingStatus.text = message
} }
@ -137,8 +144,6 @@ class SyncPairActivity : AppCompatActivity() {
_textError.text = e.message _textError.text = e.message
_layoutPairing.visibility = View.GONE _layoutPairing.visibility = View.GONE
Logger.e(TAG, "Failed to pair", e) Logger.e(TAG, "Failed to pair", e)
} finally {
_layoutPairing.visibility = View.GONE
} }
} }

View file

@ -296,29 +296,31 @@ class StateSync {
Logger.i(TAG, "Sync key pair initialized (public key = ${publicKey})") Logger.i(TAG, "Sync key pair initialized (public key = ${publicKey})")
_serverStarted = true if (Settings.instance.synchronization.localConnections) {
_thread = Thread { _serverStarted = true
try { _thread = Thread {
val serverSocket = ServerSocket(PORT) try {
_serverSocket = serverSocket val serverSocket = ServerSocket(PORT)
_serverSocket = serverSocket
Log.i(TAG, "Running on port ${PORT} (TCP)") Log.i(TAG, "Running on port ${PORT} (TCP)")
while (_started) { while (_started) {
val socket = serverSocket.accept() val socket = serverSocket.accept()
val session = createSocketSession(socket, true) val session = createSocketSession(socket, true)
session.startAsResponder() session.startAsResponder()
}
} catch (e: Throwable) {
_serverStarted = false
Logger.e(TAG, "Failed to bind server socket to port ${PORT}", e)
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {
onServerBindFail.invoke()
}
} finally {
_serverStarted = false
} }
} catch (e: Throwable) { }.apply { start() }
_serverStarted = false }
Logger.e(TAG, "Failed to bind server socket to port ${PORT}", e)
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {
onServerBindFail.invoke()
}
} finally {
_serverStarted = false
}
}.apply { start() }
if (Settings.instance.synchronization.connectLast) { if (Settings.instance.synchronization.connectLast) {
_connectThread = Thread { _connectThread = Thread {
@ -490,7 +492,7 @@ class StateSync {
} }
fun showFailedToBindDialogIfNecessary(context: Context) { fun showFailedToBindDialogIfNecessary(context: Context) {
if (!_serverStarted) { if (!_serverStarted && Settings.instance.synchronization.localConnections) {
try { try {
UIDialogs.showDialogOk(context, R.drawable.ic_warning, "Local discovery unavailable, port was in use") UIDialogs.showDialogOk(context, R.drawable.ic_warning, "Local discovery unavailable, port was in use")
} catch (e: Throwable) { } catch (e: Throwable) {

View file

@ -57,15 +57,15 @@
<ImageView <ImageView
android:id="@+id/image_clear" android:id="@+id/image_clear"
android:layout_width="16dp" android:layout_width="36dp"
android:layout_height="16dp" android:layout_height="36dp"
app:srcCompat="@drawable/ic_clear_16dp" app:srcCompat="@drawable/ic_clear_16dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="6dp" android:layout_marginEnd="6dp"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:padding="2dp" /> android:padding="12dp" />
<TextView <TextView
android:id="@+id/text_name" android:id="@+id/text_name"

View file

@ -384,6 +384,8 @@
<string name="connect_through_relay_description">Allow devices to be connected to through the relay</string> <string name="connect_through_relay_description">Allow devices to be connected to through the relay</string>
<string name="connect_local_direct_through_relay">Connect direct through relay</string> <string name="connect_local_direct_through_relay">Connect direct through relay</string>
<string name="connect_local_direct_through_relay_description">Allow devices to be directly locally connected to through information discovered from the relay</string> <string name="connect_local_direct_through_relay_description">Allow devices to be directly locally connected to through information discovered from the relay</string>
<string name="local_connections">Local connections</string>
<string name="local_connections_description">Allow device to be directly locally connected</string>
<string name="gesture_controls">Gesture controls</string> <string name="gesture_controls">Gesture controls</string>
<string name="volume_slider">Volume slider</string> <string name="volume_slider">Volume slider</string>
<string name="volume_slider_descr">Enable slide gesture to change volume</string> <string name="volume_slider_descr">Enable slide gesture to change volume</string>