mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-03 16:41:26 +01:00
fix(core,app,android,cli,packaging): harden account sign-in and watch-history sync
- Desktop shows Proton's CAPTCHA instead of failing the sign-in: a wry webview in a child process of the app (`pstr-app::verify`), confined to https://*.proton.me, hands the token back and the sign-in is retried. Linux packages and CI gain WebKitGTK 4.1; the Windows zip and MSI ship WebView2Loader.dll, without which a -gnu build does not start. - The desktop keyring splits a secret too long for one entry across several, so a Proton session with many key salts survives Windows' 1280-unit cap. Short secrets stay one entry, so every existing secret still reads. - `WatchSync` runs against a small `HistoryDrive` trait and is tested end to end against an in-memory Drive: two devices, newer wins, no re-upload of an unchanged history, a missing file written again, an unreadable own file never overwritten, a newer-format file left alone. - An installation's file unwritten for 90 days is retired by the next device to sync, after its entries are merged and carried in that device's file. - Removing a share keeps its watch state: sync would bring it back from the other devices anyway, and re-adding the share picks up where it left off. - Watch history syncs once more on desktop exit (bounded to 3 s) and, on Android, through a WorkManager job enqueued when the app leaves the screen. - The second-factor prompts say security keys are not supported.
This commit is contained in:
1 parent
26cccd5c63
commit
d9ca8f8d60
28 files changed
+2475
-186
No files matched your search
@@ -33,6 +33,7 @@ import io.narl.protonstream.playback.MpvPlaybackState
|
||||
import io.narl.protonstream.playback.NativeMpvHost
|
||||
import io.narl.protonstream.playback.PlaybackService
|
||||
import io.narl.protonstream.settings.SettingsStore
|
||||
import io.narl.protonstream.sync.WatchSyncWorker
|
||||
import io.narl.protonstream.ui.ProtonStreamApp
|
||||
import io.narl.protonstream.ui.theme.AppearanceState
|
||||
import io.narl.protonstream.ui.theme.ProtonStreamTheme
|
||||
@@ -207,6 +208,9 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
// Where the viewer stopped is what their other devices want next, and
|
||||
// a process in the background may not live to the next timed sync.
|
||||
if (!isChangingConfigurations) WatchSyncWorker.enqueue(this)
|
||||
if (
|
||||
!isChangingConfigurations &&
|
||||
!isInPictureInPictureMode &&
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.narl.protonstream.sync
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.BackoffPolicy
|
||||
import androidx.work.Constraints
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.NetworkType
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import io.narl.protonstream.native.NativeRuntime
|
||||
import uniffi.pstr_android.AccountState
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* One watch-history sync after the app leaves the screen.
|
||||
*
|
||||
* The model's timer only runs while the app is alive, and Android is free to
|
||||
* kill a process in the background without notice — so the position the
|
||||
* viewer stopped at would wait for the next launch to reach their other
|
||||
* devices. Handed to WorkManager instead, it goes as soon as there is a
|
||||
* network, even if the process is gone by then.
|
||||
*/
|
||||
class WatchSyncWorker(
|
||||
appContext: Context,
|
||||
parameters: WorkerParameters,
|
||||
) : CoroutineWorker(appContext, parameters) {
|
||||
override suspend fun doWork(): Result {
|
||||
val engine = NativeRuntime.engine()
|
||||
return runCatching { engine.syncWatchHistory() }.fold(
|
||||
onSuccess = { Result.success() },
|
||||
onFailure = {
|
||||
// Signed out by the engine — the session ended — is not
|
||||
// something a retry fixes; a dropped connection is.
|
||||
val signedOut = runCatching { engine.accountState() }.getOrNull() == AccountState.SignedOut
|
||||
if (signedOut || runAttemptCount >= MAX_ATTEMPTS) Result.failure() else Result.retry()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val WORK_NAME = "watch-history-sync"
|
||||
private const val MAX_ATTEMPTS = 3
|
||||
|
||||
/** Replacing: one pending sync covers every position saved before it runs. */
|
||||
fun enqueue(context: Context) {
|
||||
val request = OneTimeWorkRequestBuilder<WatchSyncWorker>()
|
||||
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
|
||||
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 30, TimeUnit.SECONDS)
|
||||
.build()
|
||||
WorkManager.getInstance(context.applicationContext)
|
||||
.enqueueUniqueWork(WORK_NAME, ExistingWorkPolicy.REPLACE, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,13 +194,16 @@ internal fun SignInDialog(account: AccountUiState, actions: AccountActions, onDi
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
when (state) {
|
||||
AccountState.SecondFactor -> OutlinedTextField(
|
||||
code,
|
||||
{ code = it },
|
||||
label = { Text("Two-factor code") },
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
|
||||
)
|
||||
AccountState.SecondFactor -> {
|
||||
OutlinedTextField(
|
||||
code,
|
||||
{ code = it },
|
||||
label = { Text("Code from your authenticator app") },
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
|
||||
)
|
||||
Text(SECURITY_KEY_NOTE, style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
AccountState.MailboxPassword -> {
|
||||
Text(
|
||||
"This account has a separate mailbox password. It unlocks your files.",
|
||||
@@ -329,6 +332,11 @@ private fun VerificationDialog(url: String, onToken: (String) -> Unit, onDismiss
|
||||
}
|
||||
}
|
||||
|
||||
/** Security keys need WebAuthn, which the sign-in here does not speak. */
|
||||
private const val SECURITY_KEY_NOTE =
|
||||
"Security keys are not supported. If your account has only a security key, add an " +
|
||||
"authenticator app in your Proton account settings to sign in here."
|
||||
|
||||
/** Installed once per page, at start and again at finish in case the first ran too early. */
|
||||
private const val VERIFICATION_BRIDGE = """
|
||||
if (!window.__pstrVerification) {
|
||||
|
||||
@@ -136,15 +136,15 @@ internal fun SharesScreen(
|
||||
)
|
||||
}
|
||||
removing?.let { share ->
|
||||
// Asked, because it cannot be undone: the link's secret, its offline
|
||||
// files and its watch positions all go (`Catalog::remove_share`).
|
||||
// Asked, because it cannot be undone: the link's secret and its
|
||||
// offline files go. Watch positions stay (`Catalog::remove_share`).
|
||||
AlertDialog(
|
||||
onDismissRequest = { removing = null },
|
||||
title = { Text("Remove ${share.name}?") },
|
||||
text = {
|
||||
Text(
|
||||
"Its titles leave the library, and its offline episodes and watch " +
|
||||
"progress are deleted. Adding the link again starts it fresh.",
|
||||
"Its titles leave the library and its offline episodes are deleted. " +
|
||||
"Watch progress is kept, so adding the link again picks up where you left off.",
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
|
||||
Reference in new issue
Block a user