Skip to content

Commit

Permalink
Snooze 15 seconds instead of 60.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Jun 27, 2024
1 parent 68fab34 commit 6636459
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions Core/NetworkProtectionNotificationIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public enum NetworkProtectionNotificationIdentifier: String {
case superseded = "network-protection.notification.superseded"
case test = "network-protection.notification.test"
case entitlement = "network-protection.notification.entitlement"
case snoozeEnded = "network-protection.notification.snooze-ended"
}
2 changes: 1 addition & 1 deletion DuckDuckGo/NetworkProtectionDebugUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class NetworkProtectionDebugUtilities {
return
}

try? await activeSession.sendProviderMessage(.startSnooze(60))
try? await activeSession.sendProviderMessage(.startSnooze(15))
}
}

Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case shutDown
case showEntitlementMessaging
case resetEntitlementMessaging
case start60SecondSnooze
case start15SecondSnooze
}

enum NetworkPathRows: Int, CaseIterable {
Expand Down Expand Up @@ -388,8 +388,8 @@ final class NetworkProtectionDebugViewController: UITableViewController {
cell.textLabel?.text = "Show Entitlement Messaging"
case .resetEntitlementMessaging:
cell.textLabel?.text = "Reset Entitlement Messaging"
case .start60SecondSnooze:
cell.textLabel?.text = "Snooze For 60 Seconds"
case .start15SecondSnooze:
cell.textLabel?.text = "Snooze For 15 Seconds"
case .none:
break
}
Expand All @@ -409,9 +409,9 @@ final class NetworkProtectionDebugViewController: UITableViewController {
UserDefaults.networkProtectionGroupDefaults.enableEntitlementMessaging()
case .resetEntitlementMessaging:
UserDefaults.networkProtectionGroupDefaults.resetEntitlementMessaging()
case .start60SecondSnooze:
case .start15SecondSnooze:
Task {
try await NetworkProtectionDebugUtilities().startSnooze()
await NetworkProtectionDebugUtilities().startSnooze()
}
case .none:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ final class NetworkProtectionUNNotificationPresenter: NSObject, NetworkProtectio
}
}

func showSnoozeBeganNotification() {
let identifier = NetworkProtectionNotificationIdentifier.snoozeEnded.rawValue
let content = notificationContent(body: "Snooze mode has begun")
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: .none)

requestAlertAuthorization { authorized in
guard authorized else { return }
self.userNotificationCenter.removeDeliveredNotifications(withIdentifiers: [identifier])
self.userNotificationCenter.add(request)
}
}

func showSnoozeEndedNotification() {
let identifier = NetworkProtectionNotificationIdentifier.snoozeEnded.rawValue
let content = notificationContent(body: "Snooze mode has ended")
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: .none)

requestAlertAuthorization { authorized in
guard authorized else { return }
self.userNotificationCenter.removeDeliveredNotifications(withIdentifiers: [identifier])
self.userNotificationCenter.add(request)
}
}

private func showNotification(_ identifier: NetworkProtectionNotificationIdentifier, _ content: UNNotificationContent) {
let request = UNNotificationRequest(identifier: identifier.rawValue, content: content, trigger: .none)

Expand Down

0 comments on commit 6636459

Please sign in to comment.