Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions BrowserKit/Sources/TabDataStore/TabSessionStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public protocol TabSessionStore: Sendable {
/// - Parameters:
/// - tabID: an ID that uniquely identifies the tab
/// - sessionData: the data associated with a session, encoded as a Data object
@MainActor
func saveTabSession(tabID: UUID, sessionData: Data)

/// Fetches the session data associated with a tab
/// - Parameter tabID: an ID that uniquely identifies the tab
/// - Returns: the data associated with a session, encoded as a Data object
@MainActor
Comment on lines +13 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this work should probably be asynchronous but it will require more thought since we need the tab session to load the webview

func fetchTabSession(tabID: UUID) -> Data?

/// Cleans up any tab session data files for tabs that are no longer open.
Expand Down Expand Up @@ -47,8 +49,6 @@ public final class DefaultTabSessionStore: TabSessionStore {

let path = directory.appendingPathComponent(filePrefix + tabID.uuidString)
do {
lock.lock()
defer { lock.unlock() }
try sessionData.write(to: path, options: .atomicWrite)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to lock if this work is isolated to the main actor

} catch {
logger.log("Failed to save session data with error: \(error.localizedDescription)",
Expand All @@ -67,8 +67,6 @@ public final class DefaultTabSessionStore: TabSessionStore {
}

do {
lock.lock()
defer { lock.unlock() }
return try Data(contentsOf: path)
} catch {
logger.log("Failed to decode session data with error: \(error.localizedDescription)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,6 @@ class BrowserViewController: UIViewController,
}

updateTabCountUsingTabManager(tabManager, animated: false)
updateToolbarStateForTraitCollection(traitCollection)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually know if we can remove this call from the viewWillAppear but we are calling this in traitCollectionDidChange as well so maybe we don't need it here?

updateAddressToolbarContainerPosition(for: traitCollection)
}

Expand Down Expand Up @@ -4483,8 +4482,6 @@ extension BrowserViewController: TabManagerDelegate {
/// If we are on iPad we need to trigger `willNavigateAway` when switching tabs
willNavigateAway(from: previousTab)
topTabsDidChangeTab()
} else if isSwipingTabsEnabled {
addressToolbarContainer.updateSkeletonAddressBarsVisibility(tabManager: tabManager)
Comment on lines -4486 to -4487
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traitCollectionDidChange gets triggered every time we open a tab which calls updateSkeletonAddressBarsVisibility so maybe we don't need this here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that this code was added here to help us keep track of the previous and next tab to be able to pre configure the skeleton bars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PARAIPAN9 Maybe you could help me figure out the right way to clean up this code since you understand the functionality that updateSkeletonAddressBarsVisibility was trying to solve. We have a common pattern in the code of just calling something everywhere so that we can guarantee it was called. We shouldn't need to recalculate this 4 times for each webview though. Prior to this change this function is called:

  • Browser View Controller viewWillAppear
  • Browser View Controller traitCollectionDidChange (this gets called twice when we select a tab)
  • Browser View Controller delegate completion for selecting a tab.

When we select a tab all of these are called.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will take a look as soon as possible.

}

/// If the selectedTab is showing an error page trigger a reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ final class AddressToolbarContainer: UIView,
return
}
let tabs = selectedTab.isPrivate ? tabManager.privateTabs : tabManager.normalTabs
guard let index = tabs.firstIndex(where: { $0 === selectedTab }) else { return }
guard tabManager.selectedIndex != -1 else { return }

let previousTab = tabs[safe: index-1]
let forwardTab = tabs[safe: index+1]
let previousTab = tabs[safe: tabManager.selectedIndex - 1]
let forwardTab = tabs[safe: tabManager.selectedIndex + 1]

configureSkeletonAddressBars(previousTab: previousTab, forwardTab: forwardTab)
leftSkeletonAddressBar.isHidden = previousTab == nil
Expand Down
1 change: 1 addition & 0 deletions firefox-ios/Client/TabManagement/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protocol TabManager: AnyObject {
var count: Int { get }

var selectedTab: Tab? { get }
var selectedIndex: Int { get }
var backupCloseTab: BackupCloseTab? { get set }

var tabs: [Tab] { get }
Expand Down