@@ -25,6 +25,7 @@ import kotlin.coroutines.resume
2525import kotlin.coroutines.suspendCoroutine
2626
2727private const val VPN_START_TIME_PREF = " vpn-start-time"
28+ private const val LAST_UPDATE_CHECK_TIME_PREF = " update-check-time"
2829private const val APP_CRASHED_PREF = " app-crashed"
2930private const val FIRST_RUN_PREF = " is-first-run"
3031
@@ -212,18 +213,21 @@ class HttpToolkitApplication : Application() {
212213
213214 suspend fun isUpdateRequired (): Boolean {
214215 return withContext(Dispatchers .IO ) {
215- if (isVpnActive()) {
216- Log .i(TAG , " VPN currently active, so not checking for updates for now" )
217- return @withContext false
218- }
219-
220216 if (wasInstalledFromStore(this @HttpToolkitApplication)) {
221217 // We only check for updates for side-loaded/ADB-loaded versions. This is useful
222218 // because otherwise anything outside the play store gets no updates.
223219 Log .i(TAG , " Installed from play store, no update prompting required" )
224220 return @withContext false
225221 }
226222
223+ val lastUpdateTime = prefs.getLong(LAST_UPDATE_CHECK_TIME_PREF ,
224+ firstInstallTime(this @HttpToolkitApplication)
225+ )
226+
227+ if (System .currentTimeMillis() - lastUpdateTime < 1000 * 60 ) {
228+ return @withContext false ;
229+ }
230+
227231 val httpClient = OkHttpClient ()
228232 val request = Request .Builder ()
229233 .url(" https://api.github.com/repos/httptoolkit/httptoolkit-android/releases/latest" )
@@ -258,6 +262,8 @@ class HttpToolkitApplication : Application() {
258262 else
259263 " App is up to date"
260264 )
265+
266+ prefs.edit().putLong(LAST_UPDATE_CHECK_TIME_PREF , System .currentTimeMillis()).apply ()
261267 return @withContext updateAvailable && updateNotTooRecent
262268 } catch (e: Exception ) {
263269 Log .w(TAG , e)
@@ -272,6 +278,10 @@ private fun wasInstalledFromStore(context: Context): Boolean {
272278 return context.packageManager.getInstallerPackageName(context.packageName) != null
273279}
274280
281+ private fun firstInstallTime (context : Context ): Long {
282+ return context.packageManager.getPackageInfo(context.packageName, 0 ).firstInstallTime
283+ }
284+
275285private data class GithubRelease (
276286 val tag_name : String? ,
277287 val name : String? ,
0 commit comments