@@ -25,6 +25,7 @@ import kotlin.coroutines.resume
25
25
import kotlin.coroutines.suspendCoroutine
26
26
27
27
private const val VPN_START_TIME_PREF = " vpn-start-time"
28
+ private const val LAST_UPDATE_CHECK_TIME_PREF = " update-check-time"
28
29
private const val APP_CRASHED_PREF = " app-crashed"
29
30
private const val FIRST_RUN_PREF = " is-first-run"
30
31
@@ -212,18 +213,21 @@ class HttpToolkitApplication : Application() {
212
213
213
214
suspend fun isUpdateRequired (): Boolean {
214
215
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
-
220
216
if (wasInstalledFromStore(this @HttpToolkitApplication)) {
221
217
// We only check for updates for side-loaded/ADB-loaded versions. This is useful
222
218
// because otherwise anything outside the play store gets no updates.
223
219
Log .i(TAG , " Installed from play store, no update prompting required" )
224
220
return @withContext false
225
221
}
226
222
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
+
227
231
val httpClient = OkHttpClient ()
228
232
val request = Request .Builder ()
229
233
.url(" https://api.github.com/repos/httptoolkit/httptoolkit-android/releases/latest" )
@@ -258,6 +262,8 @@ class HttpToolkitApplication : Application() {
258
262
else
259
263
" App is up to date"
260
264
)
265
+
266
+ prefs.edit().putLong(LAST_UPDATE_CHECK_TIME_PREF , System .currentTimeMillis()).apply ()
261
267
return @withContext updateAvailable && updateNotTooRecent
262
268
} catch (e: Exception ) {
263
269
Log .w(TAG , e)
@@ -272,6 +278,10 @@ private fun wasInstalledFromStore(context: Context): Boolean {
272
278
return context.packageManager.getInstallerPackageName(context.packageName) != null
273
279
}
274
280
281
+ private fun firstInstallTime (context : Context ): Long {
282
+ return context.packageManager.getPackageInfo(context.packageName, 0 ).firstInstallTime
283
+ }
284
+
275
285
private data class GithubRelease (
276
286
val tag_name : String? ,
277
287
val name : String? ,
0 commit comments