mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Fix setLastVersion called onException
This commit is contained in:
parent
7fa3d9f3ff
commit
40db23d341
@ -297,7 +297,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
public void onTerminate() {
|
||||
stopKovenant(); // Loki
|
||||
OpenGroupManager.INSTANCE.stopPolling();
|
||||
versionDataFetcher.clear();
|
||||
versionDataFetcher.stopTimedVersionCheck();
|
||||
super.onTerminate();
|
||||
}
|
||||
|
||||
|
@ -20,43 +20,36 @@ class VersionDataFetcher @Inject constructor(
|
||||
private val prefs: TextSecurePreferences
|
||||
) {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val runnable = Runnable {
|
||||
fetchVersionData()
|
||||
}
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
fun startTimedVersionCheck() {
|
||||
stopTimedVersionCheck()
|
||||
|
||||
// Call immediately if 4h or more has elapsed since the last successful check else schedule.
|
||||
handler.postDelayed(
|
||||
runnable,
|
||||
REFRESH_TIME_MS + prefs.getLastVersionCheck() - System.currentTimeMillis()
|
||||
)
|
||||
}
|
||||
|
||||
fun stopTimedVersionCheck() {
|
||||
handler.removeCallbacks(runnable)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
stopTimedVersionCheck()
|
||||
}
|
||||
|
||||
private fun fetchVersionData() {
|
||||
private val fetchVersionData = Runnable {
|
||||
scope.launch {
|
||||
try {
|
||||
// Perform the version check
|
||||
val clientVersion = FileServerApi.getClientVersion()
|
||||
Log.i(TAG, "Fetched version data: $clientVersion")
|
||||
prefs.setLastVersionCheck()
|
||||
startTimedVersionCheck()
|
||||
} catch (e: Exception) {
|
||||
// We can silently ignore the error
|
||||
Log.e(TAG, "Error fetching version data", e)
|
||||
// Schedule the next check for 4 hours from now, but do not setLastVersionCheck
|
||||
// so the app will retry when the app is next foregrounded.
|
||||
startTimedVersionCheck(REFRESH_TIME_MS)
|
||||
}
|
||||
|
||||
prefs.setLastVersionCheck()
|
||||
startTimedVersionCheck()
|
||||
}
|
||||
}
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
fun startTimedVersionCheck(
|
||||
delayMillis: Long = REFRESH_TIME_MS + prefs.getLastVersionCheck() - System.currentTimeMillis()
|
||||
) {
|
||||
stopTimedVersionCheck()
|
||||
|
||||
// Call immediately if 4h or more has elapsed since the last successful check else schedule.
|
||||
handler.postDelayed(fetchVersionData, delayMillis)
|
||||
}
|
||||
|
||||
fun stopTimedVersionCheck() {
|
||||
handler.removeCallbacks(fetchVersionData)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user