@@ -30,6 +30,31 @@ class UpdateManager(val app: App) : CoroutineScope {
30
30
override val coroutineContext: CoroutineContext
31
31
get() = job + Dispatchers .Default
32
32
33
+ fun isApplicable (update : Update ): Boolean {
34
+ if (app.buildManager.isDebug)
35
+ return false // no updates on debug
36
+ if (update.versionCode > BuildConfig .VERSION_CODE )
37
+ return true
38
+ if (update.versionCode < BuildConfig .VERSION_CODE )
39
+ return false
40
+ if (update.versionName == BuildConfig .VERSION_NAME )
41
+ return false
42
+ if (app.buildManager.isNightly || app.buildManager.isDaily) {
43
+ val updateDate =
44
+ update.versionName
45
+ .replace(""" \D""" .toRegex(), " " )
46
+ .padEnd(12 , ' 9' )
47
+ .toIntOrNull() ? : return false
48
+ val buildDate =
49
+ BuildConfig .VERSION_NAME
50
+ .replace(""" \D""" .toRegex(), " " )
51
+ .padEnd(12 , ' 9' )
52
+ .toIntOrNull() ? : return false
53
+ return updateDate > buildDate
54
+ }
55
+ return false
56
+ }
57
+
33
58
/* *
34
59
* Check for updates on the specified [maxChannel].
35
60
* If the running build is of "more-unstable" type,
@@ -75,7 +100,7 @@ class UpdateManager(val app: App) : CoroutineScope {
75
100
* @return [update] if it's a newer version, null otherwise
76
101
*/
77
102
fun process (update : Update ? , notify : Boolean ): Update ? {
78
- if (update == null || update.versionCode <= BuildConfig . VERSION_CODE ) {
103
+ if (update == null || ! isApplicable( update) ) {
79
104
app.config.update = null
80
105
return null
81
106
}
0 commit comments