From 09cebf20f3ee150629fe3c62d3974180fec6f8a2 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 5 Dec 2022 17:16:16 -0500 Subject: [PATCH] Handle intent after navigator is initialized Fixes crash if opening from widget or notification when activity isn't already launched. --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index e47d6544db..becb5507d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -86,8 +86,6 @@ class MainActivity : BaseActivity() { private val uiPreferences: UiPreferences by injectLazy() private val preferences: BasePreferences by injectLazy() - private var isHandlingShortcut: Boolean = false - private val chapterCache: ChapterCache by injectLazy() // To be checked by splash screen. If true then splash screen will be removed. @@ -98,9 +96,16 @@ class MainActivity : BaseActivity() { */ private var settingsSheet: LibrarySettingsSheet? = null + private var isHandlingShortcut: Boolean = false private lateinit var navigator: Navigator override fun onCreate(savedInstanceState: Bundle?) { + // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 + if (!isTaskRoot) { + finish() + return + } + // Prevent splash screen showing up on configuration changes val splashScreen = if (savedInstanceState == null) installSplashScreen() else null @@ -128,12 +133,6 @@ class MainActivity : BaseActivity() { false } - // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 - if (!isTaskRoot) { - finish() - return - } - // Draw edge-to-edge WindowCompat.setDecorFitsSystemWindows(window, false) @@ -151,6 +150,18 @@ class MainActivity : BaseActivity() { ConfirmExit() } + LaunchedEffect(navigator) { + this@MainActivity.navigator = navigator + + if (savedInstanceState == null) { + // Set start screen + handleIntentAction(intent) + + // Reset Incognito Mode on relaunch + preferences.incognitoMode().set(false) + } + } + // Shows current screen ScreenTransition(navigator = navigator, transition = { Transition.OneWayFade }) @@ -171,10 +182,6 @@ class MainActivity : BaseActivity() { .launchIn(this) } - LaunchedEffect(navigator) { - this@MainActivity.navigator = navigator - } - CheckForUpdate() } @@ -203,14 +210,6 @@ class MainActivity : BaseActivity() { elapsed <= SPLASH_MIN_DURATION || (!ready && elapsed <= SPLASH_MAX_DURATION) } setSplashScreenExitAnimation(splashScreen) - - if (savedInstanceState == null) { - // Set start screen - lifecycleScope.launch { handleIntentAction(intent) } - - // Reset Incognito Mode on relaunch - preferences.incognitoMode().set(false) - } } private fun showSettingsSheet(category: Category? = null) {