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)
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)

View file

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

View file

@ -296,6 +296,7 @@ class StateSync {
Logger.i(TAG, "Sync key pair initialized (public key = ${publicKey})")
if (Settings.instance.synchronization.localConnections) {
_serverStarted = true
_thread = Thread {
try {
@ -319,6 +320,7 @@ class StateSync {
_serverStarted = false
}
}.apply { start() }
}
if (Settings.instance.synchronization.connectLast) {
_connectThread = Thread {
@ -490,7 +492,7 @@ class StateSync {
}
fun showFailedToBindDialogIfNecessary(context: Context) {
if (!_serverStarted) {
if (!_serverStarted && Settings.instance.synchronization.localConnections) {
try {
UIDialogs.showDialogOk(context, R.drawable.ic_warning, "Local discovery unavailable, port was in use")
} catch (e: Throwable) {

View file

@ -57,15 +57,15 @@
<ImageView
android:id="@+id/image_clear"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_width="36dp"
android:layout_height="36dp"
app:srcCompat="@drawable/ic_clear_16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:padding="2dp" />
android:padding="12dp" />
<TextView
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_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="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="volume_slider">Volume slider</string>
<string name="volume_slider_descr">Enable slide gesture to change volume</string>