Skip to content

Commit

Permalink
Bugfix FXIOS-8080 Favicon flicker on home (#21222)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin authored Jul 29, 2024
1 parent be3fe14 commit 44992f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Common
protocol JumpBackInDataAdaptor: Actor {
func hasSyncedTabFeatureEnabled() -> Bool
func getRecentTabData() -> [Tab]
func getGroupsData() -> [ASGroup<Tab>]?
func getSyncedTabData() -> JumpBackInSyncedTab?
}

Expand Down Expand Up @@ -76,10 +75,6 @@ actor JumpBackInDataAdaptorImplementation: JumpBackInDataAdaptor, FeatureFlaggab
return recentTabs
}

func getGroupsData() -> [ASGroup<Tab>]? {
return recentGroups
}

func getSyncedTabData() -> JumpBackInSyncedTab? {
return mostRecentSyncedTab
}
Expand All @@ -98,30 +93,22 @@ actor JumpBackInDataAdaptorImplementation: JumpBackInDataAdaptor, FeatureFlaggab
private func updateTabsData() async {
await withTaskGroup(of: Void.self) { group in
group.addTask {
await self.setRecentTabs(recentTabs: await self.updateRecentTabs())
await self.delegate?.didLoadNewData()
let recentTabs = await self.updateRecentTabs()
await self.setRecentTabs(recentTabs: recentTabs)
}
group.addTask {
if let remoteTabs = await self.updateRemoteTabs() {
await self.createMostRecentSyncedTab(from: remoteTabs)
await self.delegate?.didLoadNewData()
}
}
group.addTask {
await self.setRecentGroups(recentGroups: await self.updateGroupsData())
await self.delegate?.didLoadNewData()
}
}
delegate?.didLoadNewData()
}

private func setRecentTabs(recentTabs: [Tab]) {
self.recentTabs = recentTabs
}

private func setRecentGroups(recentGroups: [ASGroup<Tab>]?) {
self.recentGroups = recentGroups
}

private func updateRecentTabs() async -> [Tab] {
// Recent tabs need to be accessed from .main otherwise value isn't proper
return await withCheckedContinuation { continuation in
Expand All @@ -131,10 +118,6 @@ actor JumpBackInDataAdaptorImplementation: JumpBackInDataAdaptor, FeatureFlaggab
}
}

private func updateGroupsData() async -> [ASGroup<Tab>]? {
return nil
}

// MARK: Synced tab data

private func getHasSyncAccount() async -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,22 @@ extension JumpBackInViewModel: HomepageSectionHandler {
extension JumpBackInViewModel: JumpBackInDelegate {
func didLoadNewData() {
Task { @MainActor in
self.recentTabs = await self.jumpBackInDataAdaptor.getRecentTabData()
self.recentSyncedTab = await self.jumpBackInDataAdaptor.getSyncedTabData()
self.isSyncTabFeatureEnabled = await self.jumpBackInDataAdaptor.hasSyncedTabFeatureEnabled()
await self.updateJumpBackInData()
logger.log("JumpBack didLoadNewData and section shouldShow \(self.shouldShow)",
level: .debug,
category: .homepage)
guard self.isEnabled else { return }

self.delegate?.reloadView()
reloadView()
}
}

private func updateJumpBackInData() async {
self.recentTabs = await self.jumpBackInDataAdaptor.getRecentTabData()
self.recentSyncedTab = await self.jumpBackInDataAdaptor.getSyncedTabData()
self.isSyncTabFeatureEnabled = await self.jumpBackInDataAdaptor.hasSyncedTabFeatureEnabled()
}

private func reloadView() {
guard self.isEnabled else { return }
self.delegate?.reloadView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import XCTest
import WebKit
import Common

// NOTE:
// Tab groups not tested at the moment since it depends on RustPlaces concrete object.
// Need protocol to be able to fix this

class JumpBackInDataAdaptorTests: XCTestCase {
final class JumpBackInDataAdaptorTests: XCTestCase {
var mockTabManager: MockTabManager!
var mockProfile: MockProfile!
let sleepTime: UInt64 = 100_000_000
Expand All @@ -33,7 +29,7 @@ class JumpBackInDataAdaptorTests: XCTestCase {
mockTabManager = nil
}

func testEmptyData_tabTrayGroupsDisabled() async {
func testEmptyData() async {
let subject = createSubject()
try? await Task.sleep(nanoseconds: sleepTime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,6 @@ actor JumpBackInDataAdaptorMock: JumpBackInDataAdaptor {
return recentTabs
}

var recentGroups: [ASGroup<Tab>]?
func setRecentGroups(recentGroups: [ASGroup<Tab>]?) {
self.recentGroups = recentGroups
}

func getGroupsData() -> [ASGroup<Tab>]? {
return recentGroups
}

var mockHasSyncedTabFeatureEnabled = true
func setMockHasSyncedTabFeatureEnabled(enabled: Bool) {
mockHasSyncedTabFeatureEnabled = enabled
Expand Down

0 comments on commit 44992f1

Please sign in to comment.