Skip to content

Commit

Permalink
Latest Live Activity changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Jul 22, 2024
1 parent a983776 commit bf5efec
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 6 deletions.
26 changes: 26 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@
4BCBE4602BA7E87100FC75A1 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 4BCBE45F2BA7E87100FC75A1 /* PrivacyInfo.xcprivacy */; };
4BCD14672B05B682000B1E4C /* NetworkProtectionTermsAndConditionsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCD14662B05B682000B1E4C /* NetworkProtectionTermsAndConditionsStore.swift */; };
4BCD146D2B05DB09000B1E4C /* NetworkProtectionAccessControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCD146C2B05DB09000B1E4C /* NetworkProtectionAccessControllerTests.swift */; };
4BD96E062C4DBC93003BC32C /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02025663298818B100E694E7 /* NetworkExtension.framework */; };
4BD96E092C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD96E082C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift */; };
4BD96E0B2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD96E0A2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift */; };
4BD96E0E2C4DCFD7003BC32C /* VPNSnoozeLiveActivityWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD96E0C2C4DCEAA003BC32C /* VPNSnoozeLiveActivityWidget.swift */; };
4BD96E0F2C4DCFEB003BC32C /* VPNSnoozeLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD96E082C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift */; };
4BD96E102C4DF329003BC32C /* VPNSnoozeLiveActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD96E0A2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift */; };
4BE2756827304F57006B20B0 /* URLRequestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE27566272F878F006B20B0 /* URLRequestExtension.swift */; };
4BE67B012B96B741007335F7 /* Common in Frameworks */ = {isa = PBXBuildFile; productRef = 4BE67B002B96B741007335F7 /* Common */; };
4BE67B032B96B864007335F7 /* ContentBlocking in Frameworks */ = {isa = PBXBuildFile; productRef = 4BE67B022B96B864007335F7 /* ContentBlocking */; };
Expand Down Expand Up @@ -1381,6 +1387,9 @@
4BCBE45F2BA7E87100FC75A1 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4BCD14662B05B682000B1E4C /* NetworkProtectionTermsAndConditionsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionTermsAndConditionsStore.swift; sourceTree = "<group>"; };
4BCD146C2B05DB09000B1E4C /* NetworkProtectionAccessControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkProtectionAccessControllerTests.swift; sourceTree = "<group>"; };
4BD96E082C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNSnoozeLiveActivity.swift; sourceTree = "<group>"; };
4BD96E0A2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNSnoozeLiveActivityManager.swift; sourceTree = "<group>"; };
4BD96E0C2C4DCEAA003BC32C /* VPNSnoozeLiveActivityWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNSnoozeLiveActivityWidget.swift; sourceTree = "<group>"; };
4BE27566272F878F006B20B0 /* URLRequestExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = URLRequestExtension.swift; path = ../DuckDuckGo/URLRequestExtension.swift; sourceTree = "<group>"; };
4BF3E4AE2C06A85200ED5D57 /* VPNRedditSessionWorkaround.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNRedditSessionWorkaround.swift; sourceTree = "<group>"; };
560E990E2BEE2CB800507CE0 /* SyncErrorMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncErrorMessage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2810,6 +2819,7 @@
buildActionMask = 2147483647;
files = (
8512EA5124ED30D20073EE19 /* SwiftUI.framework in Frameworks */,
4BD96E062C4DBC93003BC32C /* NetworkExtension.framework in Frameworks */,
85DF714624F7FE6100C89288 /* Core.framework in Frameworks */,
8512EA4F24ED30D20073EE19 /* WidgetKit.framework in Frameworks */,
4BBBBA872B02E85400D965DA /* DesignResourcesKit in Frameworks */,
Expand Down Expand Up @@ -3437,6 +3447,16 @@
name = VPN;
sourceTree = "<group>";
};
4BD96E072C4DCCD1003BC32C /* LiveActivity */ = {
isa = PBXGroup;
children = (
4BD96E082C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift */,
4BD96E0A2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift */,
4BD96E0C2C4DCEAA003BC32C /* VPNSnoozeLiveActivityWidget.swift */,
);
name = LiveActivity;
sourceTree = "<group>";
};
566B736E2BECD3DC00FF1959 /* Utilities */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4972,6 +4992,7 @@
EECD94B22A28B8580085C66E /* NetworkProtection */ = {
isa = PBXGroup;
children = (
4BD96E072C4DCCD1003BC32C /* LiveActivity */,
4B37E04E2B928C91009E81CA /* Resources */,
EE01EB412AFC1DE10096AAC9 /* PreferredLocation */,
EE9D68CF2AE00CE000B55EF4 /* VPNSettings */,
Expand Down Expand Up @@ -6927,6 +6948,7 @@
D62EC3C22C248AF800FC9D04 /* DuckNavigationHandling.swift in Sources */,
9FB027142C252E0C009EA190 /* OnboardingView+BrowsersComparisonContent.swift in Sources */,
D664C7B62B289AA200CBFA76 /* SubscriptionFlowViewModel.swift in Sources */,
4BD96E0B2C4DCE55003BC32C /* VPNSnoozeLiveActivityManager.swift in Sources */,
1EFDCBC127D2393C00916BC5 /* DownloadsDeleteHelper.swift in Sources */,
85374D3C21AC41E700FF5A1E /* FavoritesHomeViewSectionRenderer.swift in Sources */,
85DFEDF124C7EEA400973FE7 /* LargeOmniBarState.swift in Sources */,
Expand Down Expand Up @@ -7162,6 +7184,7 @@
9865DFF922A8220D00D27829 /* FavoritesOverlay.swift in Sources */,
1E4DCF4627B6A33600961E25 /* DownloadsListViewModel.swift in Sources */,
37C696772C4957940073E131 /* RemoteMessagingDebugViewController.swift in Sources */,
4BD96E092C4DCDD2003BC32C /* VPNSnoozeLiveActivity.swift in Sources */,
F4F6DFB626E6B71300ED7E12 /* BookmarkFoldersTableViewController.swift in Sources */,
8586A11024CCCD040049720E /* TabsBarViewController.swift in Sources */,
F1D796F41E7C2A410019D451 /* BookmarksDelegate.swift in Sources */,
Expand Down Expand Up @@ -7359,14 +7382,17 @@
buildActionMask = 2147483647;
files = (
853273AE24FEF49600E3C778 /* ColorExtension.swift in Sources */,
4BD96E0F2C4DCFEB003BC32C /* VPNSnoozeLiveActivity.swift in Sources */,
373608932ABB432600629E7F /* FavoritesDisplayMode+UserDefaults.swift in Sources */,
4BD96E102C4DF329003BC32C /* VPNSnoozeLiveActivityManager.swift in Sources */,
853273B324FF114700E3C778 /* DeepLinks.swift in Sources */,
853273B424FFB36100E3C778 /* UIColorExtension.swift in Sources */,
853273AB24FEF27500E3C778 /* WidgetViews.swift in Sources */,
4B5C462B2AF2BDC4002A4432 /* VPNIntents.swift in Sources */,
4BB7CBB02AF59C310014A35F /* VPNWidget.swift in Sources */,
8512EA5424ED30D20073EE19 /* Widgets.swift in Sources */,
85DB12EB2A1FE2A4000A4A72 /* LockScreenWidgets.swift in Sources */,
4BD96E0E2C4DCFD7003BC32C /* VPNSnoozeLiveActivityWidget.swift in Sources */,
8544C37C250B827300A0FE73 /* UserText.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"branch" : "sam/vpn-snooze-initial-support",
"revision" : "4a270336dc0d200f608c2b0244048e7a5c569125"
"revision" : "ebd1e571cb02f1e7ffa5c485f9ea1c58ccda251b"
}
},
{
Expand Down
5 changes: 3 additions & 2 deletions DuckDuckGo/VPNIntents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct EnableVPNIntent: AppIntent {
// MARK: - Snooze

@available(iOS 17.0, *)
struct StartSnoozeVPNIntent: AppIntent {
struct StartSnoozeVPNIntent: LiveActivityIntent {

static let title: LocalizedStringResource = "Snooze VPN"
static let description: LocalizedStringResource = "Snoozes the DuckDuckGo VPN"
Expand All @@ -136,9 +136,10 @@ struct StartSnoozeVPNIntent: AppIntent {
return .result()
}

let defaultDuration: TimeInterval = .minutes(1) + .seconds(1) // TODO: Change to 20 mins, 1 min is only used for testing
let defaultDuration: TimeInterval = .minutes(2) + .seconds(1) // TODO: Change to 20 mins, 1 min is only used for testing
try? await session.sendProviderMessage(.startSnooze(defaultDuration))

await VPNSnoozeLiveActivityManager().start(endDate: Date().addingTimeInterval(defaultDuration))
WidgetCenter.shared.reloadTimelines(ofKind: "VPNStatusWidget")

return .result()
Expand Down
14 changes: 13 additions & 1 deletion DuckDuckGo/VPNSnoozeLiveActivityWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct VPNSnoozeLiveActivity: Widget {
Button(intent: CancelSnoozeLiveActivityAppIntent(), label: {
Text("Dismiss")
})
.buttonStyle(.borderedProminent)
.tint(Color("WidgetLiveActivityButtonColor"))
}
} else if let range = self.range(from: context.state.endDate) {
HStack {
Expand All @@ -53,6 +55,8 @@ struct VPNSnoozeLiveActivity: Widget {
Button(intent: CancelSnoozeLiveActivityAppIntent(), label: {
Text("Resume")
})
.buttonStyle(.borderedProminent)
.tint(Color("WidgetLiveActivityButtonColor"))
}
}
}
Expand All @@ -69,7 +73,7 @@ struct VPNSnoozeLiveActivity: Widget {

return DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Image("vpn-off")
Image("vpn-off-live-activity")
}

DynamicIslandExpandedRegion(.center) {
Expand All @@ -89,13 +93,21 @@ struct VPNSnoozeLiveActivity: Widget {
if context.isStale {
Button(intent: CancelSnoozeLiveActivityAppIntent(), label: {
Text("Dismiss")
.font(Font.system(size: 18, weight: .semibold))
.foregroundColor(Color.white)
.frame(maxWidth: .infinity)
})
.buttonStyle(.borderedProminent)
.tint(Color("WidgetLiveActivityButtonColor"))
} else {
Button(intent: CancelSnoozeLiveActivityAppIntent(), label: {
Text("Resume VPN")
.font(Font.system(size: 18, weight: .semibold))
.foregroundColor(Color.white)
.frame(maxWidth: .infinity)
})
.buttonStyle(.borderedProminent)
.tint(Color("WidgetLiveActivityButtonColor"))
}
}
} compactLeading: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2D",
"green" : "0x2C",
"red" : "0x2C"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x2D",
"green" : "0x2C",
"red" : "0x2C"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "vpn-off-live-activity.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
4 changes: 2 additions & 2 deletions Widgets/VPNWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ struct VPNStatusView: View {

switch status {
case .connected:
let buttonTitle = snoozeTimingStore.isSnoozing ? "Resume" : UserText.vpnWidgetDisconnectButton
let intent: any AppIntent = snoozeTimingStore.isSnoozing ? CancelSnoozeVPNIntent() : DisableVPNIntent()
let buttonTitle = snoozeTimingStore.isSnoozing ? "Resume" : "Snooze"
let intent: any AppIntent = snoozeTimingStore.isSnoozing ? CancelSnoozeVPNIntent() : StartSnoozeVPNIntent()

Button(buttonTitle, intent: intent)
.font(.system(size: 14, weight: .semibold))
Expand Down

0 comments on commit bf5efec

Please sign in to comment.