mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-22 08:42:38 +00:00
ratelimit update checking
This commit is contained in:
5 files changed
+41
-6
No files matched your search
@@ -7,6 +7,7 @@ import android.content.Intent
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
|
import android.text.format.DateUtils
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -58,6 +59,7 @@ import com.geode.launcher.utils.PreferenceUtils
|
|||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.time.Clock
|
||||||
|
|
||||||
class SettingsActivity : ComponentActivity() {
|
class SettingsActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -435,6 +437,22 @@ fun SettingsScreen(
|
|||||||
title = stringResource(R.string.preference_update_automatically_name),
|
title = stringResource(R.string.preference_update_automatically_name),
|
||||||
preferenceKey = PreferenceUtils.Key.UPDATE_AUTOMATICALLY,
|
preferenceKey = PreferenceUtils.Key.UPDATE_AUTOMATICALLY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val lastUpdateCheck by PreferenceUtils.useLongPreference(PreferenceUtils.Key.LAST_UPDATE_CHECK_TIME)
|
||||||
|
val checkAgoString = remember(lastUpdateCheck) {
|
||||||
|
if (lastUpdateCheck != 0L) {
|
||||||
|
val now = Clock.System.now().toEpochMilliseconds()
|
||||||
|
DateUtils.getRelativeTimeSpanString(
|
||||||
|
lastUpdateCheck,
|
||||||
|
now,
|
||||||
|
DateUtils.MINUTE_IN_MILLIS,
|
||||||
|
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
"never"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OptionsCard(
|
OptionsCard(
|
||||||
title = {
|
title = {
|
||||||
OptionsTitle(
|
OptionsTitle(
|
||||||
@@ -444,7 +462,9 @@ fun SettingsScreen(
|
|||||||
painterResource(R.drawable.icon_update),
|
painterResource(R.drawable.icon_update),
|
||||||
contentDescription = null
|
contentDescription = null
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
description = stringResource(R.string.preference_check_for_updates_description, checkAgoString)
|
||||||
|
.takeIf { lastUpdateCheck != 0L }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -957,7 +957,7 @@ fun SettingsCard(title: String, description: String? = null, icon: (@Composable
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OptionsTitle(modifier: Modifier = Modifier, title: String, description: String? = null, icon: (@Composable () -> Unit)? = null) {
|
fun OptionsTitle(modifier: Modifier = Modifier, title: String, description: String? = null, icon: (@Composable () -> Unit)? = null) {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
icon()
|
icon()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import okio.buffer
|
|||||||
import okio.source
|
import okio.source
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InterruptedIOException
|
import java.io.InterruptedIOException
|
||||||
|
import kotlin.time.Clock
|
||||||
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
|
||||||
private const val TAG_LATEST = "latest"
|
private const val TAG_LATEST = "latest"
|
||||||
private const val TAG_BETA = "prerelease"
|
private const val TAG_BETA = "prerelease"
|
||||||
@@ -245,6 +247,16 @@ class ReleaseManager private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun checkForNewRelease(isManual: Boolean = false) {
|
private suspend fun checkForNewRelease(isManual: Boolean = false) {
|
||||||
|
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
||||||
|
val lastCheckTime = sharedPreferences.getLong(PreferenceUtils.Key.LAST_UPDATE_CHECK_TIME)
|
||||||
|
|
||||||
|
// only check for updates if it's been over 30 minutes since last check
|
||||||
|
val checkMinTime = Clock.System.now().minus(30.minutes).toEpochMilliseconds()
|
||||||
|
if (!isManual && lastCheckTime > checkMinTime) {
|
||||||
|
_uiState.value = ReleaseManagerState.Finished()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val release = try {
|
val release = try {
|
||||||
getLatestRelease()
|
getLatestRelease()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -263,6 +275,9 @@ class ReleaseManager private constructor(
|
|||||||
checkLauncherUpdate(launcherRelease)
|
checkLauncherUpdate(launcherRelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val currentTime = Clock.System.now().toEpochMilliseconds()
|
||||||
|
sharedPreferences.setLong(PreferenceUtils.Key.LAST_UPDATE_CHECK_TIME, currentTime)
|
||||||
|
|
||||||
if (release == null) {
|
if (release == null) {
|
||||||
downloadLauncherUpdateIfNecessary()
|
downloadLauncherUpdateIfNecessary()
|
||||||
|
|
||||||
@@ -270,8 +285,6 @@ class ReleaseManager private constructor(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val sharedPreferences = PreferenceUtils.get(applicationContext)
|
|
||||||
|
|
||||||
val currentVersion = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_VERSION_TIMESTAMP)
|
val currentVersion = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_VERSION_TIMESTAMP)
|
||||||
val latestVersion = release.getDescriptor()
|
val latestVersion = release.getDescriptor()
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
DISABLE_USER_THEME,
|
DISABLE_USER_THEME,
|
||||||
SELECTED_ICON,
|
SELECTED_ICON,
|
||||||
DISABLE_REDESIGN,
|
DISABLE_REDESIGN,
|
||||||
WAIT_PERIOD
|
WAIT_PERIOD,
|
||||||
|
LAST_UPDATE_CHECK_TIME
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
||||||
@@ -203,6 +204,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
Key.DISABLE_USER_THEME -> "PreferenceDisableUserTheme"
|
Key.DISABLE_USER_THEME -> "PreferenceDisableUserTheme"
|
||||||
Key.SELECTED_ICON -> "PreferenceSelectedIcon"
|
Key.SELECTED_ICON -> "PreferenceSelectedIcon"
|
||||||
Key.WAIT_PERIOD -> "PreferenceWaitPeriod"
|
Key.WAIT_PERIOD -> "PreferenceWaitPeriod"
|
||||||
|
Key.LAST_UPDATE_CHECK_TIME -> "PreferenceLastUpdateCheckTime"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -227,7 +227,7 @@
|
|||||||
<string name="preference_architecture">%1$s (%2$s)</string>
|
<string name="preference_architecture">%1$s (%2$s)</string>
|
||||||
|
|
||||||
<string name="preference_check_for_updates_button">Check for updates</string>
|
<string name="preference_check_for_updates_button">Check for updates</string>
|
||||||
<string name="preference_check_for_updates_description">Current loader version: %1$s</string>
|
<string name="preference_check_for_updates_description">Last checked %1$s</string>
|
||||||
<string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string>
|
<string name="preference_check_for_updates_failed">Update failed. See logs for more details.</string>
|
||||||
<string name="preference_check_for_updates_none_found">No updates found.</string>
|
<string name="preference_check_for_updates_none_found">No updates found.</string>
|
||||||
<string name="preference_check_for_updates_success">Geode has been updated!</string>
|
<string name="preference_check_for_updates_success">Geode has been updated!</string>
|
||||||
|
|||||||
Reference in new issue
Block a user