forked from geode-sdk/android-launcher
cache launcher update check
This commit is contained in:
3 files changed
+32
-5
No files matched your search
@@ -279,6 +279,15 @@ fun LauncherUpdateInformation(onDismiss: () -> Unit) {
|
||||
})
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (nextReleaseName != null && nextRelease == null) {
|
||||
coroutineScope.launch { withContext(Dispatchers.IO) {
|
||||
ReleaseManager.get(context)
|
||||
.checkLauncherUpdate()
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
val nextReleaseNameSaved = nextReleaseName
|
||||
if (nextReleaseNameSaved != null) {
|
||||
ModalBottomSheet(onDismissRequest = { onDismiss() }, sheetState = sheetState) {
|
||||
|
||||
@@ -251,12 +251,27 @@ class ReleaseManager private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkLauncherUpdate() {
|
||||
suspend fun checkLauncherUpdate() {
|
||||
val launcherRelease = getLatestLauncherUpdate() ?: return
|
||||
|
||||
if (launcherRelease.release.tagName != BuildConfig.VERSION_NAME) {
|
||||
_availableLauncherUpdateTag.value = launcherRelease.getDescription()
|
||||
_availableLauncherUpdateDetails.value = launcherRelease
|
||||
// unconditionally track it, we're not using it for checks and it might be good to have
|
||||
_availableLauncherUpdateDetails.value = launcherRelease
|
||||
|
||||
val launcherTag = launcherRelease.release.tagName
|
||||
if (launcherTag != BuildConfig.VERSION_NAME) {
|
||||
_availableLauncherUpdateTag.value = launcherTag
|
||||
|
||||
PreferenceUtils.get(applicationContext)
|
||||
.setString(PreferenceUtils.Key.LAST_LAUNCHER_UPDATE, launcherTag)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkCachedLauncherUpdate() {
|
||||
val lastUpdate = PreferenceUtils.get(applicationContext)
|
||||
.getString(PreferenceUtils.Key.LAST_LAUNCHER_UPDATE) ?: return
|
||||
|
||||
if (lastUpdate != BuildConfig.VERSION_NAME) {
|
||||
_availableLauncherUpdateTag.value = lastUpdate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +290,7 @@ class ReleaseManager private constructor(
|
||||
// only check for updates if it's been over 15 minutes since last check
|
||||
val checkMinTime = Clock.System.now().minus(15.minutes).toEpochMilliseconds()
|
||||
if (!isManual && lastCheckTime > checkMinTime && !fileWasExternallyModified()) {
|
||||
checkCachedLauncherUpdate()
|
||||
_uiState.value = ReleaseManagerState.Finished()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -151,7 +151,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
||||
SELECTED_ICON,
|
||||
DISABLE_REDESIGN,
|
||||
WAIT_PERIOD,
|
||||
LAST_UPDATE_CHECK_TIME
|
||||
LAST_UPDATE_CHECK_TIME,
|
||||
LAST_LAUNCHER_UPDATE,
|
||||
}
|
||||
|
||||
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
||||
@@ -205,6 +206,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
||||
Key.SELECTED_ICON -> "PreferenceSelectedIcon"
|
||||
Key.WAIT_PERIOD -> "PreferenceWaitPeriod"
|
||||
Key.LAST_UPDATE_CHECK_TIME -> "PreferenceLastUpdateCheckTime"
|
||||
Key.LAST_LAUNCHER_UPDATE -> "PreferenceLastLauncherUpdate"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user