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

Commit

Permalink
Fix #1258: Added New Private Tab Quick Action. (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T authored and kylehickinson committed Jul 22, 2019
1 parent 9811303 commit 326b421
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
7 changes: 7 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,10 @@ extension Strings {
public static let AddToMenuItem = NSLocalizedString("AddToMenuItem", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Add to...", comment: "Title for adding new bookmark menu item")
public static let ShareWithMenuItem = NSLocalizedString("ShareWithMenuItem", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Share with...", comment: "Title for sharing url menu item")
}

// MARK: - Quick Actions
extension Strings {
public static let QuickActionNewTab = NSLocalizedString("ShortcutItemTitleNewTab", tableName: "BraveShared", bundle: Bundle.braveShared, value: "New Tab", comment: "Quick Action for 3D-Touch on the Application Icon")
public static let QuickActionNewPrivateTab = NSLocalizedString("ShortcutItemTitleNewPrivateTab", tableName: "BraveShared", bundle: Bundle.braveShared, value: "New Private Tab", comment: "Quick Action for 3D-Touch on the Application Icon")
public static let QuickActionScanQRCode = NSLocalizedString("ShortcutItemTitleQRCode", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Scan QR Code", comment: "Quick Action for 3D-Touch on the Application Icon")
}
18 changes: 18 additions & 0 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati

HttpsEverywhereStats.shared.startLoading()

updateShortcutItems(application)

// Passcode checking, must happen on immediate launch
if !DataController.shared.storeExists() {
// Since passcode is stored in keychain it persists between installations.
Expand Down Expand Up @@ -186,6 +188,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
self.profile = p
return p
}

func updateShortcutItems(_ application: UIApplication) {
let newTabItem = UIMutableApplicationShortcutItem(type: "\(Bundle.main.bundleIdentifier ?? "").NewTab",
localizedTitle: Strings.QuickActionNewTab,
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(templateImageName: "quick_action_new_tab"),
userInfo: [:])

let privateTabItem = UIMutableApplicationShortcutItem(type: "\(Bundle.main.bundleIdentifier ?? "").NewPrivateTab",
localizedTitle: Strings.QuickActionNewPrivateTab,
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(templateImageName: "quick_action_new_private_tab"),
userInfo: [:])

application.shortcutItems = Preferences.Privacy.privateBrowsingOnly.value ? [privateTabItem] : [newTabItem, privateTabItem]
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Expand Down
3 changes: 3 additions & 0 deletions Client/Application/QuickActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import XCGLogger

enum ShortcutType: String {
case newTab = "NewTab"
case newPrivateTab = "NewPrivateTab"

init?(fullType: String) {
guard let last = fullType.components(separatedBy: ".").last else { return nil }
Expand Down Expand Up @@ -57,6 +58,8 @@ class QuickActions: NSObject {
switch type {
case .newTab:
handleOpenNewTab(withBrowserViewController: browserViewController, isPrivate: false)
case .newPrivateTab:
handleOpenNewTab(withBrowserViewController: browserViewController, isPrivate: true)
}
}

Expand Down
7 changes: 7 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ class BrowserViewController: UIViewController {
tabsBar.view.isHidden = !shouldShow
}
}

private func updateApplicationShortcuts() {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.updateShortcutItems(UIApplication.shared)
}
}

fileprivate func hideSearchController() {
if let searchController = searchController {
Expand Down Expand Up @@ -2956,6 +2962,7 @@ extension BrowserViewController: PreferencesObserver {
PrivateBrowsingManager.shared.isPrivateBrowsing = isPrivate
setupTabs()
updateTabsBarVisibility()
updateApplicationShortcuts()
case Preferences.Shields.blockAdsAndTracking.key,
Preferences.Shields.httpsEverywhere.key,
Preferences.Shields.blockScripts.key,
Expand Down
7 changes: 7 additions & 0 deletions Client/Frontend/Browser/TabTrayController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,19 @@ class TabTrayController: UIViewController, Themeable {
func updatePrivateModeButtonVisibility() {
toolbar.privateModeButton.isHidden = Preferences.Privacy.privateBrowsingOnly.value
}

private func updateApplicationShortcuts() {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.updateShortcutItems(UIApplication.shared)
}
}
}

extension TabTrayController: PreferencesObserver {
func preferencesDidChange(for key: String) {
if key == Preferences.Privacy.privateBrowsingOnly.key {
updatePrivateModeButtonVisibility()
updateApplicationShortcuts()
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions Client/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@
<string>FiraSans-SemiBold.ttf</string>
<string>FiraSans-UltraLight.ttf</string>
</array>
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconFile</key>
<string>quick_action_new_tab</string>
<key>UIApplicationShortcutItemTitle</key>
<string>ShortcutItemTitleNewTab</string>
<key>UIApplicationShortcutItemType</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER).NewTab</string>
</dict>
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand Down

0 comments on commit 326b421

Please sign in to comment.