Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix FXIOS-8105 [v121] Fix Send to Device failing intermittently (backport #18042) #18049

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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
61 changes: 47 additions & 14 deletions Extensions/ShareTo/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ShareViewController: UIViewController {
var shareItem: ExtensionUtils.ExtractedShareItem?
private var viewsShownDuringDoneAnimation = [UIView]()
private var stackView: UIStackView!
private var spinner: UIActivityIndicatorView?
private var actionDoneRow: (row: UIStackView, label: UILabel)!
private var sendToDevice: SendToDevice?
private var pageInfoHeight: NSLayoutConstraint?
Expand All @@ -93,6 +94,25 @@ class ShareViewController: UIViewController {

setupNavBar()
setupStackView()

if RustFirefoxAccounts.shared.accountManager == nil {
// Show brief spinner in UI while startup is finishing
showProgressIndicator()

let profile = BrowserProfile(localName: "profile")
Viaduct.shared.useReqwestBackend()
RustFirefoxAccounts.startup(prefs: profile.prefs) { [weak self] _ in
// Hide spinner and finish UI setup (Note: this completion
// block is currently guaranteed to arrive on main thread.)
self?.hideProgressIndicator()
self?.finalizeUISetup()
}
} else {
finalizeUISetup()
}
}

private func finalizeUISetup() {
setupRows()

guard let shareItem = shareItem else { return }
Expand All @@ -104,10 +124,6 @@ class ShareViewController: UIViewController {
case .rawText(let text):
self.pageInfoRowTitleLabel?.text = text.quoted
}

let profile = BrowserProfile(localName: "profile")
Viaduct.shared.useReqwestBackend()
RustFirefoxAccounts.startup(prefs: profile.prefs) { _ in }
}

private func setupRows() {
Expand Down Expand Up @@ -320,6 +336,27 @@ class ShareViewController: UIViewController {
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}

private func showProgressIndicator() {
let indicator = UIActivityIndicatorView(style: .large)
let defaultSize = CGSize(width: 40.0, height: 40.0)
view.addSubview(indicator)
indicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
indicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
indicator.centerYAnchor.constraint(equalTo: view.centerYAnchor),
indicator.widthAnchor.constraint(equalToConstant: defaultSize.width),
indicator.heightAnchor.constraint(equalToConstant: defaultSize.height),
])
indicator.startAnimating()
spinner = indicator
}

private func hideProgressIndicator() {
spinner?.stopAnimating()
spinner?.removeFromSuperview()
spinner = nil
}
}

extension ShareViewController {
Expand Down Expand Up @@ -385,16 +422,12 @@ extension ShareViewController {
guard let shareItem = shareItem, case .shareItem(let item) = shareItem else { return }

gesture.isEnabled = false
view.isUserInteractionEnabled = false
if RustFirefoxAccounts.shared.accountManager != nil {
self.view.isUserInteractionEnabled = true
self.sendToDevice = SendToDevice()
guard let sendToDevice = self.sendToDevice else { return }
sendToDevice.sharedItem = item
sendToDevice.delegate = self.delegate
let vc = sendToDevice.initialViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
self.sendToDevice = SendToDevice()
guard let sendToDevice = self.sendToDevice else { return }
sendToDevice.sharedItem = item
sendToDevice.delegate = self.delegate
let vc = sendToDevice.initialViewController()
navigationController?.pushViewController(vc, animated: true)
}

func openFirefox(withUrl url: String, isSearch: Bool) {
Expand Down