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

Add an “Open VPN Settings” quick action #2089

Merged
merged 9 commits into from
Oct 27, 2023
39 changes: 38 additions & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import Networking
import DDGSync
import SyncDataProviders

#if NETWORK_PROTECTION
import NetworkProtection
#endif

// swiftlint:disable file_length
// swiftlint:disable type_body_length

Expand All @@ -45,6 +49,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private struct ShortcutKey {
static let clipboard = "com.duckduckgo.mobile.ios.clipboard"

#if NETWORK_PROTECTION
static let openVPNSettings = "com.duckduckgo.mobile.ios.vpn.open-settings"
#endif
}

private var testing = false
Expand Down Expand Up @@ -328,6 +336,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

syncService.scheduler.notifyAppLifecycleEvent()
fireFailedCompilationsPixelIfNeeded()
refreshShortcuts()
}

private func fireAppLaunchPixel() {
Expand Down Expand Up @@ -590,11 +599,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) {
os_log("Handling shortcut item: %s", log: .generalLog, type: .debug, shortcutItem.type)

mainViewController?.clearNavigationStack()
autoClear?.applicationWillMoveToForeground()
if shortcutItem.type == ShortcutKey.clipboard, let query = UIPasteboard.general.string {

if shortcutItem.type == ShortcutKey.clipboard, let query = UIPasteboard.general.string {
mainViewController?.loadQueryInNewTab(query)
return
}

#if NETWORK_PROTECTION
if shortcutItem.type == ShortcutKey.openVPNSettings {
presentNetworkProtectionStatusSettingsModal()
}
#endif
}

private func removeEmailWaitlistState() {
Expand Down Expand Up @@ -622,6 +640,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private var mainViewController: MainViewController? {
return window?.rootViewController as? MainViewController
}

func refreshShortcuts() {
#if NETWORK_PROTECTION
guard NetworkProtectionKeychainTokenStore().isFeatureActivated else {
return
}

let items = [
UIApplicationShortcutItem(type: ShortcutKey.openVPNSettings,
localizedTitle: "Open VPN Settings",
samsymons marked this conversation as resolved.
Show resolved Hide resolved
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(templateImageName: "VPN-16"),
userInfo: nil)
]

UIApplication.shared.shortcutItems = items
#endif
}

}

extension AppDelegate: BlankSnapshotViewRecoveringDelegate {
Expand Down
15 changes: 15 additions & 0 deletions DuckDuckGo/Assets.xcassets/VPN-16.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "VPN-16.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.