mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-06 09:09:44 -06:00
feat: auto lock on app pause (#1073)
This commit is contained in:
committed by
GitHub
parent
2b38a9d0bc
commit
312f05304e
@@ -1,6 +1,7 @@
|
||||
package com.yogeshpaliyal.keypass
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.SystemClock
|
||||
import com.yogeshpaliyal.common.CommonMyApplication
|
||||
import com.yogeshpaliyal.keypass.ui.CrashActivity
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
@@ -14,6 +15,18 @@ import dagger.hilt.android.HiltAndroidApp
|
||||
@HiltAndroidApp
|
||||
class MyApplication : CommonMyApplication() {
|
||||
|
||||
private var timeToLaunchActivity : Long? = null
|
||||
|
||||
fun activityLaunchTriggered() {
|
||||
timeToLaunchActivity = SystemClock.uptimeMillis()
|
||||
}
|
||||
|
||||
fun isActivityLaunchTriggered() : Boolean {
|
||||
val mTimeToLaunchActivity = timeToLaunchActivity ?: return false
|
||||
timeToLaunchActivity = null
|
||||
return SystemClock.uptimeMillis() - mTimeToLaunchActivity < 1000
|
||||
}
|
||||
|
||||
override fun getCrashActivityIntent(throwable: Throwable): Intent {
|
||||
return CrashActivity.getIntent(this, throwable.stackTraceToString())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.yogeshpaliyal.keypass.ui.backup
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import com.yogeshpaliyal.keypass.MyApplication
|
||||
|
||||
class KeyPassBackupDirectoryPick : ActivityResultContracts.OpenDocument() {
|
||||
override fun createIntent(context: Context, input: Array<String>): Intent {
|
||||
@@ -14,6 +15,8 @@ class KeyPassBackupDirectoryPick : ActivityResultContracts.OpenDocument() {
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
(context.applicationContext as? MyApplication)?.activityLaunchTriggered()
|
||||
return intent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,15 @@ import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import com.yogeshpaliyal.common.data.UserSettings
|
||||
import com.yogeshpaliyal.common.utils.getUserSettings
|
||||
import com.yogeshpaliyal.common.utils.getUserSettingsFlow
|
||||
import com.yogeshpaliyal.common.utils.migrateOldDataToNewerDataStore
|
||||
import com.yogeshpaliyal.common.utils.setUserSettings
|
||||
import com.yogeshpaliyal.keypass.BuildConfig
|
||||
import com.yogeshpaliyal.keypass.MyApplication
|
||||
import com.yogeshpaliyal.keypass.ui.about.AboutScreen
|
||||
import com.yogeshpaliyal.keypass.ui.auth.AuthScreen
|
||||
import com.yogeshpaliyal.keypass.ui.backup.BackupScreen
|
||||
@@ -45,6 +48,7 @@ import com.yogeshpaliyal.keypass.ui.nav.components.KeyPassBottomBar
|
||||
import com.yogeshpaliyal.keypass.ui.passwordHint.PasswordHintScreen
|
||||
import com.yogeshpaliyal.keypass.ui.redux.KeyPassRedux
|
||||
import com.yogeshpaliyal.keypass.ui.redux.actions.GoBackAction
|
||||
import com.yogeshpaliyal.keypass.ui.redux.actions.NavigationAction
|
||||
import com.yogeshpaliyal.keypass.ui.redux.actions.UpdateContextAction
|
||||
import com.yogeshpaliyal.keypass.ui.redux.states.AboutState
|
||||
import com.yogeshpaliyal.keypass.ui.redux.states.AccountDetailState
|
||||
@@ -126,9 +130,11 @@ fun Dashboard() {
|
||||
}
|
||||
|
||||
// Call this like any other SideEffect in your composable
|
||||
// LifecycleEventEffect(Lifecycle.Event.ON_PAUSE) {
|
||||
// dispatch(NavigationAction(AuthState.Login))
|
||||
// }
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_PAUSE) {
|
||||
if((context.applicationContext as? MyApplication)?.isActivityLaunchTriggered() == false) {
|
||||
dispatch(NavigationAction(AuthState.Login))
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(key1 = systemBackPress, block = {
|
||||
if (systemBackPress) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.yogeshpaliyal.keypass.ui.settings
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import com.yogeshpaliyal.keypass.MyApplication
|
||||
import com.yogeshpaliyal.keypass.importer.AccountsImporter
|
||||
|
||||
class OpenKeyPassBackup<T : AccountsImporter>(val importer: T?) : ActivityResultContracts.OpenDocument() {
|
||||
@@ -16,6 +17,9 @@ class OpenKeyPassBackup<T : AccountsImporter>(val importer: T?) : ActivityResult
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
|
||||
(context.applicationContext as? MyApplication)?.activityLaunchTriggered()
|
||||
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user