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
  • Loading branch information
Brandon-T committed Oct 13, 2023
1 parent 0f5db7f commit bb1e8b7
Showing 1 changed file with 40 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,43 +101,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)
updatePlusButtonMenu()
updateColors()

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)
privateModeCancellable = tabManager?.privateBrowsingManager
.$isPrivateBrowsing
.removeDuplicates()
.sink(receiveValue: { [weak self] isPrivateBrowsing in
self?.updateColors(isPrivateBrowsing)
guard let self = self else { return }
self.updatePlusButtonMenu()
self.updateColors(isPrivateBrowsing)
})

Preferences.General.nightModeEnabled.objectWillChange
Expand Down Expand Up @@ -218,6 +192,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() {
// 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 bb1e8b7

Please sign in to comment.