mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
No Issue: Close the web extension popup when we can't get the popup of the session.
This commit is contained in:
parent
fa854f511b
commit
6191fec0d8
@ -9,6 +9,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
import kotlinx.android.synthetic.main.fragment_add_on_internal_settings.*
|
import kotlinx.android.synthetic.main.fragment_add_on_internal_settings.*
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import mozilla.components.browser.state.action.WebExtensionAction
|
import mozilla.components.browser.state.action.WebExtensionAction
|
||||||
@ -32,6 +33,12 @@ class WebExtensionActionPopupFragment : Fragment(), EngineSession.Observer {
|
|||||||
}
|
}
|
||||||
private var engineSession: EngineSession? = null
|
private var engineSession: EngineSession? = null
|
||||||
private val coreComponents by lazy { requireComponents.core }
|
private val coreComponents by lazy { requireComponents.core }
|
||||||
|
private val safeArguments get() = requireNotNull(arguments)
|
||||||
|
private var sessionConsumed
|
||||||
|
get() = safeArguments.getBoolean("isSessionConsumed", false)
|
||||||
|
set(value) {
|
||||||
|
safeArguments.putBoolean("isSessionConsumed", value)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@ -80,13 +87,16 @@ class WebExtensionActionPopupFragment : Fragment(), EngineSession.Observer {
|
|||||||
} else {
|
} else {
|
||||||
consumeFrom(coreComponents.store) { state ->
|
consumeFrom(coreComponents.store) { state ->
|
||||||
state.extensions[webExtensionId]?.let { extState ->
|
state.extensions[webExtensionId]?.let { extState ->
|
||||||
extState.popupSession?.let {
|
val popupSession = extState.popupSession
|
||||||
if (engineSession == null) {
|
if (popupSession != null) {
|
||||||
addonSettingsEngineView.render(it)
|
addonSettingsEngineView.render(popupSession)
|
||||||
it.register(this)
|
popupSession.register(this)
|
||||||
consumePopupSession()
|
consumePopupSession()
|
||||||
engineSession = it
|
engineSession = popupSession
|
||||||
}
|
} else if (sessionConsumed) {
|
||||||
|
// In case we can't retrieve the popup session lets close the fragment,
|
||||||
|
// this can happen when Android recreates the activity.
|
||||||
|
findNavController().popBackStack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,5 +107,6 @@ class WebExtensionActionPopupFragment : Fragment(), EngineSession.Observer {
|
|||||||
coreComponents.store.dispatch(
|
coreComponents.store.dispatch(
|
||||||
WebExtensionAction.UpdatePopupSessionAction(webExtensionId, popupSession = null)
|
WebExtensionAction.UpdatePopupSessionAction(webExtensionId, popupSession = null)
|
||||||
)
|
)
|
||||||
|
sessionConsumed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user