mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
[fenix] Close https://github.com/mozilla-mobile/fenix/issues/26150: Do not show sync tabs in home when sync open tabs setting is disabled
This commit is contained in:
parent
5bceed7dbd
commit
d6a0336b23
@ -300,6 +300,15 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
|
||||
}
|
||||
}
|
||||
|
||||
components.backgroundServices.accountManagerAvailableQueue.runIfReadyOrQueue {
|
||||
lifecycleScope.launch(IO) {
|
||||
// If we're authenticated, kick-off a sync and a device state refresh.
|
||||
components.backgroundServices.accountManager.authenticatedAccount()?.let {
|
||||
components.backgroundServices.accountManager.syncNow(reason = SyncReason.Startup)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
components.core.engine.profiler?.addMarker(
|
||||
MarkersActivityLifecycleCallbacks.MARKER_NAME, startTimeProfiler, "HomeActivity.onCreate"
|
||||
)
|
||||
@ -336,23 +345,6 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
|
||||
message = "onResume()"
|
||||
)
|
||||
|
||||
components.backgroundServices.accountManagerAvailableQueue.runIfReadyOrQueue {
|
||||
lifecycleScope.launch {
|
||||
// If we're authenticated, kick-off a sync and a device state refresh.
|
||||
components.backgroundServices.accountManager.authenticatedAccount()?.let {
|
||||
val syncReason = when (isVisuallyComplete) {
|
||||
true -> SyncReason.User
|
||||
false -> SyncReason.Startup
|
||||
}
|
||||
|
||||
components.backgroundServices.accountManager.syncNow(
|
||||
reason = syncReason,
|
||||
debounce = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch(IO) {
|
||||
try {
|
||||
if (settings().showContileFeature) {
|
||||
|
@ -281,6 +281,7 @@ class HomeFragment : Fragment() {
|
||||
if (requireContext().settings().enableTaskContinuityEnhancements) {
|
||||
recentSyncedTabFeature.set(
|
||||
feature = RecentSyncedTabFeature(
|
||||
context = requireContext(),
|
||||
appStore = requireComponents.appStore,
|
||||
syncStore = requireComponents.backgroundServices.syncStore,
|
||||
storage = requireComponents.backgroundServices.syncedTabsStorage,
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package org.mozilla.fenix.home.recentsyncedtabs
|
||||
|
||||
import android.content.Context
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@ -12,6 +13,7 @@ import mozilla.components.feature.syncedtabs.storage.SyncedTabsStorage
|
||||
import mozilla.components.lib.state.ext.flow
|
||||
import mozilla.components.service.fxa.SyncEngine
|
||||
import mozilla.components.service.fxa.manager.FxaAccountManager
|
||||
import mozilla.components.service.fxa.manager.SyncEnginesStorage
|
||||
import mozilla.components.service.fxa.manager.ext.withConstellation
|
||||
import mozilla.components.service.fxa.store.SyncStatus
|
||||
import mozilla.components.service.fxa.store.SyncStore
|
||||
@ -33,6 +35,7 @@ import org.mozilla.fenix.GleanMetrics.RecentSyncedTabs
|
||||
* @property coroutineScope The scope to collect Sync state Flow updates in.
|
||||
*/
|
||||
class RecentSyncedTabFeature(
|
||||
private val context: Context,
|
||||
private val appStore: AppStore,
|
||||
private val syncStore: SyncStore,
|
||||
private val storage: SyncedTabsStorage,
|
||||
@ -62,7 +65,6 @@ class RecentSyncedTabFeature(
|
||||
accountManager.withConstellation { refreshDevices() }
|
||||
accountManager.syncNow(
|
||||
reason = SyncReason.User,
|
||||
debounce = true,
|
||||
customEngineSubset = listOf(SyncEngine.Tabs),
|
||||
)
|
||||
}
|
||||
@ -94,6 +96,14 @@ class RecentSyncedTabFeature(
|
||||
}
|
||||
|
||||
private suspend fun dispatchSyncedTabs() {
|
||||
if (!isSyncedTabsEngineEnabled()) {
|
||||
appStore.dispatch(
|
||||
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.None)
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
val syncedTab = storage.getSyncedDeviceTabs()
|
||||
.filterNot { it.device.isCurrentDevice || it.tabs.isEmpty() }
|
||||
.maxByOrNull { it.device.lastAccessTime ?: 0 }
|
||||
@ -106,13 +116,20 @@ class RecentSyncedTabFeature(
|
||||
url = tab.url,
|
||||
iconUrl = tab.iconUrl
|
||||
)
|
||||
} ?: return
|
||||
}
|
||||
|
||||
if (syncedTab == null) {
|
||||
appStore.dispatch(
|
||||
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.None)
|
||||
)
|
||||
} else {
|
||||
recordMetrics(syncedTab, lastSyncedTab, syncStartId)
|
||||
appStore.dispatch(
|
||||
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.Success(syncedTab))
|
||||
)
|
||||
lastSyncedTab = syncedTab
|
||||
}
|
||||
}
|
||||
|
||||
private fun onError() {
|
||||
if (appStore.state.recentSyncedTabState == RecentSyncedTabState.Loading) {
|
||||
@ -131,6 +148,10 @@ class RecentSyncedTabFeature(
|
||||
RecentSyncedTabs.latestSyncedTabIsStale.add()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSyncedTabsEngineEnabled(): Boolean {
|
||||
return SyncEnginesStorage(context).getStatus()[SyncEngine.Tabs] ?: true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,16 +67,11 @@ class RecentTabViewHolder(
|
||||
)
|
||||
|
||||
recentSyncedTabState.value?.let {
|
||||
if (components.settings.enableTaskContinuityEnhancements && it != RecentSyncedTabState.None) {
|
||||
if (components.settings.enableTaskContinuityEnhancements && it is RecentSyncedTabState.Success) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
val syncedTab = when (it) {
|
||||
RecentSyncedTabState.None,
|
||||
RecentSyncedTabState.Loading -> null
|
||||
is RecentSyncedTabState.Success -> it.tab
|
||||
}
|
||||
RecentSyncedTab(
|
||||
tab = syncedTab,
|
||||
tab = it.tab,
|
||||
onRecentSyncedTabClick = { tab ->
|
||||
recentSyncedTabInteractor.onRecentSyncedTabClicked(tab)
|
||||
},
|
||||
|
@ -9,6 +9,7 @@ import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkConstructor
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||
@ -24,6 +25,7 @@ import mozilla.components.concept.sync.DeviceType
|
||||
import mozilla.components.feature.syncedtabs.storage.SyncedTabsStorage
|
||||
import mozilla.components.service.fxa.SyncEngine
|
||||
import mozilla.components.service.fxa.manager.FxaAccountManager
|
||||
import mozilla.components.service.fxa.manager.SyncEnginesStorage
|
||||
import mozilla.components.service.fxa.manager.ext.withConstellation
|
||||
import mozilla.components.service.fxa.store.Account
|
||||
import mozilla.components.service.fxa.store.SyncAction
|
||||
@ -97,8 +99,13 @@ class RecentSyncedTabFeatureTest {
|
||||
Dispatchers.setMain(StandardTestDispatcher())
|
||||
|
||||
every { appStore.dispatch(any()) } returns mockk()
|
||||
mockkConstructor(SyncEnginesStorage::class)
|
||||
every { anyConstructed<SyncEnginesStorage>().getStatus() } returns mapOf(
|
||||
SyncEngine.Tabs to true
|
||||
)
|
||||
|
||||
feature = RecentSyncedTabFeature(
|
||||
context = testContext,
|
||||
appStore = appStore,
|
||||
syncStore = syncStore,
|
||||
accountManager = accountManager,
|
||||
@ -128,7 +135,7 @@ class RecentSyncedTabFeatureTest {
|
||||
|
||||
verify { appStore.dispatch(AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.Loading)) }
|
||||
coVerify { accountManager.withConstellation { refreshDevices() } }
|
||||
coVerify { accountManager.syncNow(reason = SyncReason.User, debounce = true, customEngineSubset = listOf(SyncEngine.Tabs)) }
|
||||
coVerify { accountManager.syncNow(reason = SyncReason.User, customEngineSubset = listOf(SyncEngine.Tabs)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -249,6 +256,34 @@ class RecentSyncedTabFeatureTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN sync tabs are disabled WHEN dispatching recent synced tab THEN dispatch none`() = runTest {
|
||||
val account = mockk<Account>()
|
||||
syncStore.setState(account = account)
|
||||
every { appStore.state } returns mockk {
|
||||
every { recentSyncedTabState } returns RecentSyncedTabState.Loading
|
||||
}
|
||||
every { anyConstructed<SyncEnginesStorage>().getStatus() } returns mapOf(
|
||||
SyncEngine.Tabs to false
|
||||
)
|
||||
|
||||
val firstTab = createActiveTab("remote", "https://mozilla.org", null)
|
||||
val syncedTabs = listOf(
|
||||
SyncedDeviceTabs(deviceAccessed1, listOf(firstTab)),
|
||||
)
|
||||
coEvery { storage.getSyncedDeviceTabs() } returns syncedTabs
|
||||
|
||||
feature.start()
|
||||
syncStore.setState(status = SyncStatus.Idle)
|
||||
runCurrent()
|
||||
|
||||
verify {
|
||||
appStore.dispatch(
|
||||
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.None)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN synced tab dispatched THEN labeled counter metric recorded with device type`() = runTest {
|
||||
val account = mockk<Account>()
|
||||
|
Loading…
Reference in New Issue
Block a user