mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Close the app first before sending the bunker response
This commit is contained in:
@@ -253,4 +253,6 @@ dependencies {
|
||||
|
||||
implementation libs.datastore.preferences
|
||||
implementation libs.security.crypto
|
||||
|
||||
implementation libs.lifecycle.process
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ import android.content.Intent
|
||||
import android.net.NetworkCapabilities
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.work.Data
|
||||
import androidx.work.ExistingPeriodicWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
@@ -47,7 +51,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class Amber : Application() {
|
||||
class Amber : Application(), LifecycleObserver {
|
||||
private var mainActivityRef: WeakReference<MainActivity?>? = null
|
||||
|
||||
fun setMainActivity(activity: MainActivity?) {
|
||||
@@ -143,6 +147,17 @@ class Amber : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
Log.d("ProcessLifecycleOwner", "App in foreground")
|
||||
isAppInForeground = true
|
||||
}
|
||||
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
Log.d("ProcessLifecycleOwner", "App in background")
|
||||
isAppInForeground = false
|
||||
}
|
||||
})
|
||||
|
||||
isStartingApp.value = true
|
||||
|
||||
@@ -404,6 +419,7 @@ class Amber : Application() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
var isAppInForeground = false
|
||||
const val TAG = "Amber"
|
||||
|
||||
@Volatile
|
||||
|
||||
@@ -61,6 +61,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Log.d(Amber.TAG, "onCreate MainActivity")
|
||||
Amber.instance.startService()
|
||||
Amber.isAppInForeground = true
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
Amber.instance.setMainActivity(this)
|
||||
|
||||
@@ -290,6 +290,14 @@ object BunkerRequestUtils {
|
||||
)
|
||||
application.application.isConnected = true
|
||||
|
||||
val activity = Amber.instance.getMainActivity()
|
||||
activity?.intent = null
|
||||
if (application.application.closeApplication) {
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
delay(500)
|
||||
|
||||
if (signPolicy != null) {
|
||||
AmberUtils.configureSignPolicy(application, signPolicy, key, permissions)
|
||||
}
|
||||
@@ -344,7 +352,6 @@ object BunkerRequestUtils {
|
||||
),
|
||||
)
|
||||
|
||||
EventNotificationConsumer(context).notificationManager().cancelAll()
|
||||
sendBunkerResponse(
|
||||
context,
|
||||
account,
|
||||
@@ -367,12 +374,6 @@ object BunkerRequestUtils {
|
||||
|
||||
onLoading(false)
|
||||
addRequest(localBunkerRequest)
|
||||
} else {
|
||||
val activity = Amber.instance.getMainActivity()
|
||||
activity?.intent = null
|
||||
if (application.application.closeApplication) {
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.greenart7c3.nostrsigner.service
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
|
||||
class BunkerResponseWorker(appContext: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(appContext, workerParams) {
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ junit = { module = "junit:junit", version.ref = "junit" }
|
||||
lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle_version" }
|
||||
lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle_version" }
|
||||
lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle_version" }
|
||||
lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version.ref = "lifecycle_version" }
|
||||
material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "materialIconsExtended" }
|
||||
material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
|
||||
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
|
||||
|
||||
Reference in New Issue
Block a user