update comment

This commit is contained in:
Aria Moradi 2021-04-02 03:24:12 +04:30
parent 2b2601aa4a
commit c960cc1ee5

View File

@ -27,8 +27,8 @@ object ExtensionsList {
var lastUpdateCheck: Long = 0 var lastUpdateCheck: Long = 0
var updateMap = ConcurrentHashMap<String, Extension.Available>() var updateMap = ConcurrentHashMap<String, Extension.Available>()
// const val ExtensionUpdateDelayTime = 60 * 1000 // 60,000 milliseconds = 60 seconds /** 60,000 milliseconds = 60 seconds */
const val ExtensionUpdateDelayTime = 60 * 1000 private const val ExtensionUpdateDelayTime = 60 * 1000
suspend fun getExtensionList(): List<ExtensionDataClass> { suspend fun getExtensionList(): List<ExtensionDataClass> {
// update if {ExtensionUpdateDelayTime} seconds has passed or requested offline and database is empty // update if {ExtensionUpdateDelayTime} seconds has passed or requested offline and database is empty
@ -69,20 +69,20 @@ object ExtensionsList {
val extensionRecord = ExtensionTable.select { ExtensionTable.pkgName eq foundExtension.pkgName }.firstOrNull() val extensionRecord = ExtensionTable.select { ExtensionTable.pkgName eq foundExtension.pkgName }.firstOrNull()
if (extensionRecord != null) { if (extensionRecord != null) {
if (extensionRecord[ExtensionTable.isInstalled]) { if (extensionRecord[ExtensionTable.isInstalled]) {
if (foundExtension.versionCode > extensionRecord[ExtensionTable.versionCode]) { when {
foundExtension.versionCode > extensionRecord[ExtensionTable.versionCode] -> {
// there is an update // there is an update
ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) { ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) {
it[hasUpdate] = true it[hasUpdate] = true
} }
updateMap.putIfAbsent(foundExtension.pkgName, foundExtension) updateMap.putIfAbsent(foundExtension.pkgName, foundExtension)
} else if (foundExtension.versionCode < extensionRecord[ExtensionTable.versionCode]) { }
foundExtension.versionCode < extensionRecord[ExtensionTable.versionCode] -> {
// some how the user installed an invalid version // some how the user installed an invalid version
ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) { ExtensionTable.update({ ExtensionTable.pkgName eq foundExtension.pkgName }) {
it[isObsolete] = true it[isObsolete] = true
} }
} else { }
// the two are equal
// NOOP
} }
} else { } else {
// extension is not installed so we can overwrite the data without a care // extension is not installed so we can overwrite the data without a care
@ -115,7 +115,7 @@ object ExtensionsList {
ExtensionTable.selectAll().forEach { extensionRecord -> ExtensionTable.selectAll().forEach { extensionRecord ->
val foundExtension = foundExtensions.find { it.pkgName == extensionRecord[ExtensionTable.pkgName] } val foundExtension = foundExtensions.find { it.pkgName == extensionRecord[ExtensionTable.pkgName] }
if (foundExtension == null) { if (foundExtension == null) {
// this extensions is obsolete // not in the repo, so this extensions is obsolete
if (extensionRecord[ExtensionTable.isInstalled]) { if (extensionRecord[ExtensionTable.isInstalled]) {
// is installed so we should mark it as obsolete // is installed so we should mark it as obsolete
ExtensionTable.update({ ExtensionTable.pkgName eq extensionRecord[ExtensionTable.pkgName] }) { ExtensionTable.update({ ExtensionTable.pkgName eq extensionRecord[ExtensionTable.pkgName] }) {