@@ -9,14 +9,22 @@ import androidx.activity.ComponentActivity
99import androidx.activity.compose.setContent
1010import androidx.activity.enableEdgeToEdge
1111import androidx.compose.runtime.mutableStateOf
12+ import androidx.lifecycle.Lifecycle
13+ import androidx.lifecycle.lifecycleScope
14+ import androidx.lifecycle.repeatOnLifecycle
1215import androidx.navigation.NavHostController
1316import androidx.navigation.compose.rememberNavController
1417import com.darkrockstudios.app.securecamera.auth.AuthorizationRepository
1518import com.darkrockstudios.app.securecamera.navigation.AppDestinations
1619import com.darkrockstudios.app.securecamera.preferences.AppPreferencesDataSource
20+ import kotlinx.coroutines.delay
1721import kotlinx.coroutines.flow.firstOrNull
22+ import kotlinx.coroutines.isActive
23+ import kotlinx.coroutines.launch
1824import kotlinx.coroutines.runBlocking
1925import org.koin.android.ext.android.inject
26+ import timber.log.Timber
27+ import kotlin.time.Duration.Companion.seconds
2028
2129class MainActivity : ComponentActivity () {
2230 private var capturePhoto = mutableStateOf<Boolean ?>(null )
@@ -42,6 +50,8 @@ class MainActivity : ComponentActivity() {
4250 navController = rememberNavController()
4351 App (capturePhoto, startDestination, navController)
4452 }
53+
54+ startKeepAliveWatcher()
4555 }
4656
4757 private fun determineStartRoute (): String {
@@ -85,6 +95,24 @@ class MainActivity : ComponentActivity() {
8595 locationRepository.refreshPermissionStatus()
8696 }
8797
98+ private fun startKeepAliveWatcher () {
99+ lifecycleScope.launch {
100+ repeatOnLifecycle(Lifecycle .State .RESUMED ) {
101+ Timber .d(" Starting session keep-alive watcher" )
102+ while (isActive) {
103+ if (authorizationRepository.checkSessionValidity()) {
104+ authorizationRepository.keepAliveSession()
105+ Timber .d(" Session keep-alive ping sent" )
106+ } else {
107+ Timber .d(" No valid session, do not send keep-alive" )
108+ }
109+ delay(30 .seconds)
110+ }
111+ Timber .d(" Stopping session keep-alive watcher" )
112+ }
113+ }
114+ }
115+
88116 private fun receiveFiles (): List <Uri > {
89117 val intent = getIntent()
90118
0 commit comments