Harden the Skysparkle key exchange

Turn unexpected errors during the exchange into a sign-in error instead
of a crash, and keep the progress shown when a second callback arrives
while the first code is still being exchanged.
This commit is contained in:
2026-11-18 14:42:22 +02:00
parent 430d7b8d59
commit 7f02ec606c
@@ -85,8 +85,9 @@ object SkysparkleSignIn {
val verifier = p.getString(P_VERIFIER, null) val verifier = p.getString(P_VERIFIER, null)
val fresh = System.currentTimeMillis() - p.getLong(P_AT, 0) < PENDING_TTL_MS val fresh = System.currentTimeMillis() - p.getLong(P_AT, 0) < PENDING_TTL_MS
if (state == null || verifier == null || !fresh || uri.getQueryParameter("state") != state) { if (state == null || verifier == null || !fresh || uri.getQueryParameter("state") != state) {
// A link that this app did not start, or an old one: ignore it // A link that this app did not start, an old one, or a second tap on "Open SparkleDNS"
if (state == null || !fresh) _state.value = State.Idle // while the first code is still being exchanged: ignore it, keep any progress shown
cancelWaiting()
return return
} }
p.edit().clear().apply() p.edit().clear().apply()
@@ -149,6 +150,10 @@ object SkysparkleSignIn {
} catch (e: IOException) { } catch (e: IOException) {
Log.w("SparkleDNS", "Key exchange failed", e) Log.w("SparkleDNS", "Key exchange failed", e)
Result.Error(R.string.sign_in_network) Result.Error(R.string.sign_in_network)
} catch (e: RuntimeException) {
// Runs in a scope without an exception handler: anything that escaped would crash the app
Log.w("SparkleDNS", "Key exchange failed", e)
Result.Error(R.string.sign_in_failed)
} }
} }