Skip to content

Commit fd02ce9

Browse files
committed
refactor(details): Improve version comparison and download logging
This commit introduces a more robust semantic version comparison algorithm and corrects the download size logging for cancelled downloads. The version comparison logic now properly handles pre-release identifiers (e.g., `-alpha`, `-beta`), ensuring that stable releases are correctly prioritized over pre-releases. Additionally, when a download is cancelled, the log now correctly records the total expected size of the asset rather than the partially downloaded bytes. - **refactor(versioning)**: Updated `compareSemanticVersions` to correctly handle pre-release suffixes. - **fix(logging)**: Corrected `appendLog` to use the asset's total size instead of downloaded bytes when a download is cancelled. - **chore(proguard)**: Removed redundant `-keep` rules for AndroidX Compose and Navigation, as these are now bundled with the respective libraries.
1 parent b9b5335 commit fd02ce9

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

composeApp/proguard-rules.pro

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@
123123

124124
# ── Compose / AndroidX ────────────────────────────────────────────────────
125125
# Compose runtime and navigation (most rules come bundled with the library)
126-
-keep class androidx.compose.** { *; }
127126
-dontwarn androidx.compose.**
128-
-keep class androidx.navigation.** { *; }
129-
-keep class androidx.lifecycle.** { *; }
130127
-dontwarn androidx.lifecycle.**
131128

132129
# ── DataStore ──────────────────────────────────────────────────────────────
@@ -182,7 +179,7 @@
182179
public static final ** CREATOR;
183180
}
184181

185-
# ── ServiceLoader (used by Ktor, Koin, etc.) ──────────────────────────────
182+
# ── Java Serializable Compatibility ───────────────────────────────────────
186183
-keepnames class * implements java.io.Serializable
187184
-keepclassmembers class * implements java.io.Serializable {
188185
static final long serialVersionUID;

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ class DetailsViewModel(
368368
if (assetName != null) {
369369
cachedDownloadAssetName = assetName
370370
val releaseTag = _state.value.selectedRelease?.tagName ?: ""
371+
val totalSize = _state.value.totalBytes ?: _state.value.downloadedBytes
371372
appendLog(
372373
assetName = assetName,
373-
size = _state.value.downloadedBytes,
374374
tag = releaseTag,
375+
size = totalSize,
375376
result = LogResult.Cancelled
376377
)
377378
logger.debug("Download cancelled – keeping file for potential reuse: $assetName")
@@ -1052,14 +1053,22 @@ class DetailsViewModel(
10521053
* Compares two semantic version strings. Returns positive if a > b, negative if a < b, 0 if equal.
10531054
*/
10541055
private fun compareSemanticVersions(a: String, b: String): Int {
1055-
val aParts = a.split("[.\\-]".toRegex())
1056-
val bParts = b.split("[.\\-]".toRegex())
1056+
val aCore = a.split("-", limit = 2)
1057+
val bCore = b.split("-", limit = 2)
1058+
val aParts = aCore[0].split(".")
1059+
val bParts = bCore[0].split(".")
1060+
10571061
val maxLen = maxOf(aParts.size, bParts.size)
10581062
for (i in 0 until maxLen) {
10591063
val aPart = aParts.getOrNull(i)?.filter { it.isDigit() }?.toLongOrNull() ?: 0L
10601064
val bPart = bParts.getOrNull(i)?.filter { it.isDigit() }?.toLongOrNull() ?: 0L
10611065
if (aPart != bPart) return aPart.compareTo(bPart)
10621066
}
1067+
1068+
val aHasPre = aCore.size > 1
1069+
val bHasPre = bCore.size > 1
1070+
if (aHasPre != bHasPre) return if (aHasPre) -1 else 1
1071+
10631072
return 0
10641073
}
10651074

0 commit comments

Comments
 (0)