fix manual app addition regression, v1 release

This commit is contained in:
lone-cloud 2026-03-04 21:08:52 -08:00
parent c4e603cbc5
commit 07924d5b35
4 changed files with 17 additions and 6 deletions

View file

@ -1 +1 @@
0.5.0 1.0.0

View file

@ -169,13 +169,13 @@ class PrismPreferences(private val context: Context) :
} }
fun setVapidPrivateKey(connectorToken: String, privateKey: String) { fun setVapidPrivateKey(connectorToken: String, privateKey: String) {
securePreferences.edit { putString("vapid_private_$connectorToken", privateKey) } securePreferences.edit(commit = true) { putString("vapid_private_$connectorToken", privateKey) }
} }
fun getVapidPrivateKey(connectorToken: String): String? = securePreferences.getString("vapid_private_$connectorToken", null) fun getVapidPrivateKey(connectorToken: String): String? = securePreferences.getString("vapid_private_$connectorToken", null)
fun removeVapidPrivateKey(connectorToken: String) { fun removeVapidPrivateKey(connectorToken: String) {
securePreferences.edit { remove("vapid_private_$connectorToken") } securePreferences.edit(commit = true) { remove("vapid_private_$connectorToken") }
} }
fun addPendingChannelDeletion(channelId: String) { fun addPendingChannelDeletion(channelId: String) {

View file

@ -215,6 +215,7 @@ class MainViewModel(
val descriptionParts = mutableListOf("target:$targetPackageName") val descriptionParts = mutableListOf("target:$targetPackageName")
description?.takeIf { it.isNotBlank() }?.let { descriptionParts.add(it) } description?.takeIf { it.isNotBlank() }?.let { descriptionParts.add(it) }
descriptionParts.add("${DescriptionParser.VAPID_PRIVATE_KEY_PREFIX}${vapidKeys.privateKey}")
val fullDescription = descriptionParts.joinToString("|") val fullDescription = descriptionParts.joinToString("|")
val keyStore = EncryptionKeyStore(app) val keyStore = EncryptionKeyStore(app)

View file

@ -39,8 +39,8 @@ class ManualAppRegistrationHandler(private val context: Context) {
} }
Log.d(TAG, "Auto-registering manual app '${app.title}' with Prism server") Log.d(TAG, "Auto-registering manual app '${app.title}' with Prism server")
val vapidPrivateKey = PrismPreferences(context).getVapidPrivateKey(app.connectorToken) val vapidPrivateKey = DescriptionParser.extractValue(app.description, DescriptionParser.VAPID_PRIVATE_KEY_PREFIX)
?: DescriptionParser.extractValue(app.description, DescriptionParser.VAPID_PRIVATE_KEY_PREFIX) ?: PrismPreferences(context).getVapidPrivateKey(app.connectorToken)
if (vapidPrivateKey.isNullOrBlank()) { if (vapidPrivateKey.isNullOrBlank()) {
handleFailure( handleFailure(
@ -113,8 +113,10 @@ class ManualAppRegistrationHandler(private val context: Context) {
val preferences = PrismPreferences(context) val preferences = PrismPreferences(context)
val isInitialPendingRegistration = preferences.isPendingManualToken(connectorToken) val isInitialPendingRegistration = preferences.isPendingManualToken(connectorToken)
val isLikelyNewManualApp = isLikelyNewManualApp(connectorToken)
val shouldRollback = isInitialPendingRegistration || isLikelyNewManualApp
if (isInitialPendingRegistration) { if (shouldRollback) {
Log.w(TAG, "Rolling back pending manual app '$appTitle' after registration failure") Log.w(TAG, "Rolling back pending manual app '$appTitle' after registration failure")
rollback(connectorToken) rollback(connectorToken)
} }
@ -133,6 +135,14 @@ class ManualAppRegistrationHandler(private val context: Context) {
sendUiAction(context, UiActions.RefreshRegistrations) sendUiAction(context, UiActions.RefreshRegistrations)
} }
private fun isLikelyNewManualApp(connectorToken: String): Boolean {
val app = DatabaseFactory.getDb(context)
.listApps()
.find { it.connectorToken == connectorToken }
?: return false
return DescriptionParser.isManualApp(app.description) && app.endpoint.isNullOrBlank()
}
private fun rollback(connectorToken: String) { private fun rollback(connectorToken: String) {
val db = DatabaseFactory.getDb(context) val db = DatabaseFactory.getDb(context)
val app = db.listApps().find { it.connectorToken == connectorToken } val app = db.listApps().find { it.connectorToken == connectorToken }