Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR-17428 - Initialize observable after FronteggApp initialization #65

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions android/src/main/java/com/frontegg/android/FronteggApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager.MATCH_ALL
import android.os.Handler
import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand Down Expand Up @@ -37,7 +38,8 @@ class FronteggApp private constructor(
val packageName: String = context.packageName
var appInForeground = true

var lastJobStart:Long = Instant.now().toEpochMilli();
var lastJobStart: Long = Instant.now().toEpochMilli();

companion object {

@SuppressLint("StaticFieldLeak")
Expand Down Expand Up @@ -69,7 +71,7 @@ class FronteggApp private constructor(

val isEmbeddedMode = isActivityEnabled(context, EmbeddedAuthActivity::class.java.name)

ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleEventObserver)


instance = FronteggApp(
context = context,
Expand All @@ -81,6 +83,10 @@ class FronteggApp private constructor(
useChromeCustomTabs = useChromeCustomTabs,
mainActivityClass = mainActivityClass
)

Handler(context.mainLooper).post {
ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleEventObserver)
}
}

public fun initWithRegions(
Expand Down Expand Up @@ -135,11 +141,13 @@ class FronteggApp private constructor(
getInstance().appInForeground = false
getInstance().auth.refreshTokenWhenNeeded()
}

Lifecycle.Event.ON_START -> {
Log.d(TAG, "ON_START")
getInstance().appInForeground = true
getInstance().auth.refreshTokenWhenNeeded()
}

else -> {}
}
}
Expand Down
Loading