Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #8241: Fix Menu not updating when the private-mode changes (#8242)
Browse files Browse the repository at this point in the history
Fix menu not updating when the private-mode changes
  • Loading branch information
Brandon-T authored Oct 12, 2023
1 parent 6e9f9f4 commit f9d8243
Showing 1 changed file with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,17 @@ class TabsBarViewController: UIViewController {
make.right.equalTo(view).inset(UX.TabsBar.buttonWidth)
}

var newTabMenu: [UIAction] = []
let isPrivateBrowsing = tabManager?.privateBrowsingManager.isPrivateBrowsing == true

if !isPrivateBrowsing {
let openNewPrivateTab = UIAction(
title: Strings.Hotkey.newPrivateTabTitle,
image: UIImage(systemName: "plus.square.fill.on.square.fill"),
handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewTab(true)
})

newTabMenu.append(openNewPrivateTab)
}

let openNewTab = UIAction(
title: isPrivateBrowsing ? Strings.Hotkey.newPrivateTabTitle : Strings.Hotkey.newTabTitle,
image: isPrivateBrowsing ? UIImage(systemName: "plus.square.fill.on.square.fill") : UIImage(systemName: "plus.square.on.square"),
handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewTab(isPrivateBrowsing)
})

newTabMenu.append(openNewTab)

newTabMenu.append(UIAction(title: Strings.newWindowTitle, image: UIImage(braveSystemNamed: "leo.window"), handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewWindow(false)
}))

newTabMenu.append(UIAction(title: Strings.newPrivateWindowTitle, image: UIImage(braveSystemNamed: "leo.window.tab-private"), handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewWindow(true)
}))

updatePlusButtonMenu()
updateColors()

plusButton.menu = UIMenu(title: "", identifier: nil, children: newTabMenu)
privateModeCancellable = tabManager?.privateBrowsingManager
.$isPrivateBrowsing
.removeDuplicates()
.receive(on: RunLoop.main)
.sink(receiveValue: { [weak self] isPrivateBrowsing in
self?.updateColors()
guard let self = self else { return }
self.updatePlusButtonMenu()
self.updateColors()
})
}

Expand Down Expand Up @@ -211,6 +182,41 @@ class TabsBarViewController: UIViewController {
delegate?.tabsBarDidLongPressAddTab(self, button: plusButton)
}
}

func updatePlusButtonMenu() {
var newTabMenu: [UIAction] = []
let isPrivateBrowsing = tabManager?.privateBrowsingManager.isPrivateBrowsing == true

let openNewTab = UIAction(
title: isPrivateBrowsing ? Strings.Hotkey.newPrivateTabTitle : Strings.Hotkey.newTabTitle,
image: isPrivateBrowsing ? UIImage(systemName: "plus.square.fill.on.square.fill") : UIImage(systemName: "plus.square.on.square"),
handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewTab(isPrivateBrowsing)
})

newTabMenu.append(openNewTab)

if !isPrivateBrowsing {
let openNewPrivateTab = UIAction(
title: Strings.Hotkey.newPrivateTabTitle,
image: UIImage(systemName: "plus.square.fill.on.square.fill"),
handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewTab(true)
})

newTabMenu.append(openNewPrivateTab)
}

newTabMenu.append(UIAction(title: Strings.newWindowTitle, image: UIImage(braveSystemNamed: "leo.window"), handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewWindow(false)
}))

newTabMenu.append(UIAction(title: Strings.newPrivateWindowTitle, image: UIImage(braveSystemNamed: "leo.window.tab-private"), handler: UIAction.deferredActionHandler { [unowned self] _ in
self.delegate?.tabsBarDidSelectAddNewWindow(true)
}))

plusButton.menu = UIMenu(title: "", identifier: nil, children: newTabMenu)
}

func updateData(reloadingCollectionView: Bool = true) {
// Don't waste time/resources updating data when we're in the middle of a restore or bulk delete
Expand Down

0 comments on commit f9d8243

Please sign in to comment.