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

Commit

Permalink
Handling Private to Standard mode cases for swtiching related with sh…
Browse files Browse the repository at this point in the history
…ortcuts
  • Loading branch information
soner-yuksel committed Jul 7, 2021
1 parent 5df5996 commit b404660
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
31 changes: 22 additions & 9 deletions Client/Application/Shortcuts/ActivityShortcutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,44 @@ class ActivityShortcutManager: NSObject {
// MARK: Activity Action Methods

public func performShortcutActivity(type: ActivityType, using bvc: BrowserViewController) {
// Adding a slight delay to overcome concurency issues with bvc setup
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
self.handleActivityDetails(type: type, using: bvc)
}
}

private func handleActivityDetails(type: ActivityType, using bvc: BrowserViewController) {
switch type {
case .newTab:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)
bvc.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: false)
case .newPrivateTab:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: true)
bvc.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: true)
case .clearBrowsingHistory:
bvc.clearHistoryAndOpenNewTab()
case .enableBraveVPN:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)

bvc.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: false)
switch BraveVPN.vpnState {
case .notPurchased, .purchased, .expired:
guard let enableVPNController = BraveVPN.vpnState.enableVPNDestinationVC else { return }

bvc.openInsideSettingsNavigation(with: enableVPNController)
case .installed(let connected):
if !connected {
BraveVPN.reconnect()
}
}
case .openBraveNews:
bvc.openBlankNewTab(attemptLocationFieldFocus: true, isPrivate: false)

guard let newTabPageController = bvc.tabManager.selectedTab?.newTabPageViewController else { return }
newTabPageController.scrollToBraveNews()
if Preferences.BraveNews.isEnabled.value {
bvc.openBlankNewTab(attemptLocationFieldFocus: false, isPrivate: false)

guard let newTabPageController = bvc.tabManager.selectedTab?.newTabPageViewController else { return }
newTabPageController.scrollToBraveNews()
} else {
let controller = BraveNewsSettingsViewController(dataSource: bvc.feedDataSource)
let container = UINavigationController(rootViewController: controller)
bvc.present(container, animated: true)
}
case .openPlayList:
let playlistController = (UIApplication.shared.delegate as? AppDelegate)?.playlistRestorationController ?? PlaylistViewController()
playlistController.modalPresentationStyle = .fullScreen
Expand Down
12 changes: 9 additions & 3 deletions Client/Frontend/Browser/Tab Tray/TabTrayController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class TabTrayController: UIViewController {
tabManager.addDelegate(self)

Preferences.Privacy.privateBrowsingOnly.observe(from: self)

setPrivateMode()
}

convenience init(tabManager: TabManager, profile: Profile, tabTrayDelegate: TabTrayDelegate) {
Expand Down Expand Up @@ -152,9 +154,7 @@ class TabTrayController: UIViewController {
make.bottom.equalTo(self.toolbar.snp.top)
}

if let tab = tabManager.selectedTab, tab.isPrivate {
privateMode = true
}
setPrivateMode()

// XXX: Bug 1447726 - Temporarily disable 3DT in tabs tray
// register for previewing delegate to enable peek and pop if force touch feature available
Expand Down Expand Up @@ -374,6 +374,12 @@ class TabTrayController: UIViewController {
delegate.updateShortcutItems(UIApplication.shared)
}
}

private func setPrivateMode() {
if let tab = tabManager.selectedTab, tab.isPrivate {
privateMode = true
}
}
}

extension TabTrayController: PreferencesObserver {
Expand Down

0 comments on commit b404660

Please sign in to comment.