Skip to content

Commit 81a4ebd

Browse files
authored
fix: display version from manifest (#2634)
1 parent 5fc54eb commit 81a4ebd

File tree

10 files changed

+29
-27
lines changed

10 files changed

+29
-27
lines changed

app/src/main/java/app/revanced/manager/data/room/bundles/PatchBundleDao.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface PatchBundleDao {
1212
fun getPropsById(uid: Int): Flow<BundleProperties?>
1313

1414
@Query("UPDATE patch_bundles SET version = :patches WHERE uid = :uid")
15-
suspend fun updateVersion(uid: Int, patches: String?)
15+
suspend fun updateVersionHash(uid: Int, patches: String?)
1616

1717
@Query("UPDATE patch_bundles SET auto_update = :value WHERE uid = :uid")
1818
suspend fun setAutoUpdate(uid: Int, value: Boolean)
@@ -26,7 +26,7 @@ interface PatchBundleDao {
2626
@Transaction
2727
suspend fun reset() {
2828
purgeCustomBundles()
29-
updateVersion(0, null) // Reset the main source
29+
updateVersionHash(0, null) // Reset the main source
3030
}
3131

3232
@Query("DELETE FROM patch_bundles WHERE uid = :uid")

app/src/main/java/app/revanced/manager/data/room/bundles/PatchBundleEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ sealed class Source {
3333
data class PatchBundleEntity(
3434
@PrimaryKey val uid: Int,
3535
@ColumnInfo(name = "name") val name: String,
36-
@ColumnInfo(name = "version") val version: String? = null,
36+
@ColumnInfo(name = "version") val versionHash: String? = null,
3737
@ColumnInfo(name = "source") val source: Source,
3838
@ColumnInfo(name = "auto_update") val autoUpdate: Boolean
3939
)
4040

4141
data class BundleProperties(
42-
@ColumnInfo(name = "version") val version: String? = null,
42+
@ColumnInfo(name = "version") val versionHash: String? = null,
4343
@ColumnInfo(name = "auto_update") val autoUpdate: Boolean
4444
)

app/src/main/java/app/revanced/manager/domain/bundles/LocalPatchBundle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LocalPatchBundle(name: String, id: Int, directory: File) :
1515
}
1616

1717
reload()?.also {
18-
saveVersion(it.readManifestAttribute("Version"))
18+
saveVersionHash(it.readManifestAttribute("Version"))
1919
}
2020
}
2121
}

app/src/main/java/app/revanced/manager/domain/bundles/PatchBundleSource.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ sealed class PatchBundleSource(initialName: String, val uid: Int, directory: Fil
3838

3939
suspend fun getName() = nameFlow.first()
4040

41+
val versionFlow = state.map { it.patchBundleOrNull()?.readManifestAttribute("Version") }
42+
val patchCountFlow = state.map { it.patchBundleOrNull()?.patches?.size ?: 0 }
43+
4144
/**
4245
* Returns true if the bundle has been downloaded to local storage.
4346
*/
@@ -84,9 +87,9 @@ sealed class PatchBundleSource(initialName: String, val uid: Int, directory: Fil
8487
fun propsFlow() = configRepository.getProps(uid).flowOn(Dispatchers.Default)
8588
suspend fun getProps() = propsFlow().first()!!
8689

87-
suspend fun currentVersion() = getProps().version
88-
protected suspend fun saveVersion(version: String?) =
89-
configRepository.updateVersion(uid, version)
90+
suspend fun currentVersionHash() = getProps().versionHash
91+
protected suspend fun saveVersionHash(version: String?) =
92+
configRepository.updateVersionHash(uid, version)
9093

9194
suspend fun setName(name: String) {
9295
configRepository.setName(uid, name)

app/src/main/java/app/revanced/manager/domain/bundles/RemotePatchBundle.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sealed class RemotePatchBundle(name: String, id: Int, directory: File, val endpo
2525
}
2626
}
2727

28-
saveVersion(info.version)
28+
saveVersionHash(info.version)
2929
reload()
3030
}
3131

@@ -35,7 +35,7 @@ sealed class RemotePatchBundle(name: String, id: Int, directory: File, val endpo
3535

3636
suspend fun update(): Boolean = withContext(Dispatchers.IO) {
3737
val info = getLatestInfo()
38-
if (hasInstalled() && info.version == currentVersion())
38+
if (hasInstalled() && info.version == currentVersionHash())
3939
return@withContext false
4040

4141
download(info)

app/src/main/java/app/revanced/manager/domain/repository/PatchBundlePersistenceRepository.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PatchBundlePersistenceRepository(db: AppDatabase) {
2525
PatchBundleEntity(
2626
uid = generateUid(),
2727
name = name,
28-
version = null,
28+
versionHash = null,
2929
source = source,
3030
autoUpdate = autoUpdate
3131
).also {
@@ -34,8 +34,11 @@ class PatchBundlePersistenceRepository(db: AppDatabase) {
3434

3535
suspend fun delete(uid: Int) = dao.remove(uid)
3636

37-
suspend fun updateVersion(uid: Int, version: String?) =
38-
dao.updateVersion(uid, version)
37+
/**
38+
* Sets the version hash used for updates.
39+
*/
40+
suspend fun updateVersionHash(uid: Int, versionHash: String?) =
41+
dao.updateVersionHash(uid, versionHash)
3942

4043
suspend fun setAutoUpdate(uid: Int, value: Boolean) = dao.setAutoUpdate(uid, value)
4144

@@ -47,7 +50,7 @@ class PatchBundlePersistenceRepository(db: AppDatabase) {
4750
val defaultSource = PatchBundleEntity(
4851
uid = 0,
4952
name = "",
50-
version = null,
53+
versionHash = null,
5154
source = Source.API,
5255
autoUpdate = false
5356
)

app/src/main/java/app/revanced/manager/ui/component/bundle/BundleInformationDialog.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ fun BundleInformationDialog(
4242
val props by remember(bundle) {
4343
bundle.propsFlow()
4444
}.collectAsStateWithLifecycle(null)
45-
val patchCount = remember(state) {
46-
state.patchBundleOrNull()?.patches?.size ?: 0
47-
}
45+
val patchCount by bundle.patchCountFlow.collectAsStateWithLifecycle(0)
46+
val version by bundle.versionFlow.collectAsStateWithLifecycle(null)
4847

4948
if (viewCurrentBundlePatches) {
5049
BundlePatchesDialog(
@@ -98,8 +97,8 @@ fun BundleInformationDialog(
9897
name = bundleName,
9998
remoteUrl = bundle.asRemoteOrNull?.endpoint,
10099
patchCount = patchCount,
101-
version = props?.version,
102-
autoUpdate = props?.autoUpdate ?: false,
100+
version = version,
101+
autoUpdate = props?.autoUpdate == true,
103102
onAutoUpdateChange = {
104103
composableScope.launch {
105104
bundle.asRemoteOrNull?.setAutoUpdate(it)

app/src/main/java/app/revanced/manager/ui/component/bundle/BundleItem.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ fun BundleItem(
4747
var showDeleteConfirmationDialog by rememberSaveable { mutableStateOf(false) }
4848
val state by bundle.state.collectAsStateWithLifecycle()
4949

50-
val version by remember(bundle) {
51-
bundle.propsFlow().map { props -> props?.version }
52-
}.collectAsStateWithLifecycle(null)
50+
val version by bundle.versionFlow.collectAsStateWithLifecycle(null)
51+
val patchCount by bundle.patchCountFlow.collectAsStateWithLifecycle(0)
5352
val name by bundle.nameState
5453

5554
if (viewBundleDialogPage) {
@@ -93,7 +92,7 @@ fun BundleItem(
9392

9493
headlineContent = { Text(name) },
9594
supportingContent = {
96-
state.patchBundleOrNull()?.patches?.size?.let { patchCount ->
95+
if (state is PatchBundleSource.State.Loaded) {
9796
Text(pluralStringResource(R.plurals.patch_count, patchCount, patchCount))
9897
}
9998
},

app/src/main/java/app/revanced/manager/ui/component/bundle/BundleSelector.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ fun BundleSelector(bundles: List<PatchBundleSource>, onFinish: (PatchBundleSourc
5757
}
5858
bundles.forEach {
5959
val name by it.nameState
60-
val version by remember(it) {
61-
it.propsFlow().map { props -> props?.version }
62-
}.collectAsStateWithLifecycle(null)
60+
val version by it.versionFlow.collectAsStateWithLifecycle(null)
6361

6462
Row(
6563
verticalAlignment = Alignment.CenterVertically,

app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ data class BundleInfo(
7979
targetList.add(it)
8080
}
8181

82-
BundleInfo(source.getName(), source.currentVersion(), source.uid, compatible, incompatible, universal)
82+
BundleInfo(source.getName(), bundle.readManifestAttribute("Version"), source.uid, compatible, incompatible, universal)
8383
}
8484
}
8585

0 commit comments

Comments
 (0)