Version fetching API added
parent
d23d8f3b07
commit
35a9f9fbbe
@ -0,0 +1,44 @@
|
|||||||
|
package org.thoughtcrime.securesms.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
|
|
||||||
|
class VersionUtil(
|
||||||
|
private val context: Context,
|
||||||
|
private val prefs: TextSecurePreferences
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private val runnable: Runnable
|
||||||
|
|
||||||
|
init {
|
||||||
|
runnable = Runnable {
|
||||||
|
// Task to be executed every 4 hours
|
||||||
|
fetchVersionData()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-schedule the task
|
||||||
|
handler.postDelayed(runnable, FOUR_HOURS)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startTimedVersionCheck() {
|
||||||
|
handler.post(runnable)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopTimedVersionCheck() {
|
||||||
|
handler.removeCallbacks(runnable)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchVersionData() {
|
||||||
|
// only perform this if at least 4h has elapsed since th last successful check
|
||||||
|
if(prefs.getLastVersionCheck() < FOUR_HOURS) return
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val FOUR_HOURS = 4 * 60 * 60 * 1000L // 4 hours in milliseconds
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.session.libsession.messaging.file_server
|
||||||
|
|
||||||
|
data class VersionData(
|
||||||
|
val statusCode: Int, // The value 200. Included for backwards compatibility, and may be removed someday.
|
||||||
|
val version: String, // The Session version.
|
||||||
|
val updated: Double // The unix timestamp when this version was retrieved from Github; this can be up to 24 hours ago in case of consistent fetch errors, though normally will be within the last 30 minutes.
|
||||||
|
)
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.session.libsession.snode.utilities
|
||||||
|
|
||||||
|
import nl.komponents.kovenant.Promise
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.resumeWithException
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
suspend fun <T, E: Throwable> Promise<T, E>.await(): T {
|
||||||
|
return suspendCoroutine { cont ->
|
||||||
|
success { cont.resume(it) }
|
||||||
|
fail { cont.resumeWithException(it) }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue