... |
... |
@@ -10,6 +10,7 @@ import androidx.lifecycle.AndroidViewModel |
10
|
10
|
import androidx.lifecycle.MutableLiveData
|
11
|
11
|
import kotlinx.coroutines.flow.MutableStateFlow
|
12
|
12
|
import kotlinx.coroutines.flow.StateFlow
|
|
13
|
+import mozilla.components.browser.state.ext.getUrl
|
13
|
14
|
import org.mozilla.fenix.HomeActivity
|
14
|
15
|
import org.mozilla.fenix.R
|
15
|
16
|
import org.mozilla.fenix.ext.components
|
... |
... |
@@ -23,11 +24,27 @@ class TorConnectionAssistViewModel( |
23
|
24
|
) : AndroidViewModel(application), BootstrapStateChangeListener {
|
24
|
25
|
|
25
|
26
|
private val TAG = "torConnectionAssistVM"
|
|
27
|
+ private val components = application.components
|
26
|
28
|
private val torAndroidIntegration =
|
27
|
|
- application.components.core.geckoRuntime.torIntegrationController
|
|
29
|
+ components.core.geckoRuntime.torIntegrationController
|
28
|
30
|
|
29
|
31
|
init {
|
30
|
32
|
torAndroidIntegration.registerBootstrapStateChangeListener(this)
|
|
33
|
+ loadDummyPage()
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ private fun loadDummyPage() {
|
|
37
|
+ // Load local url (it just needs to begin with "about:" to get past filter) to initialize the browser,
|
|
38
|
+ // Domain fronting needs Services.io.getProtocolHandler("http")... to actually work, and it
|
|
39
|
+ // does not till the browser/engine is initialized, and this is so far the easiest way to do that.
|
|
40
|
+ // Load early here so that it is ready when needed if we get to the step where DF is invoked
|
|
41
|
+ // Then later remove it in onCleared so it doesn't show for the user
|
|
42
|
+ components.useCases.tabsUseCases.addTab.invoke("about:")
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ private fun clearDummyPage() {
|
|
46
|
+ // Remove loaded URL so it doesn't show up
|
|
47
|
+ components.useCases.tabsUseCases.removeTab.invoke(components.core.store.state.tabs.find {it.getUrl() == "about:"}?.id ?: "")
|
31
|
48
|
}
|
32
|
49
|
|
33
|
50
|
fun fetchCountryNamesGet() {
|
... |
... |
@@ -45,6 +62,7 @@ class TorConnectionAssistViewModel( |
45
|
62
|
|
46
|
63
|
override fun onCleared() {
|
47
|
64
|
torAndroidIntegration.unregisterBootstrapStateChangeListener(this)
|
|
65
|
+ clearDummyPage()
|
48
|
66
|
super.onCleared()
|
49
|
67
|
}
|
50
|
68
|
|