Skip to content

Commit 8a3fee3

Browse files
committed
leave whitespace alone, avoid errors
1 parent 6605276 commit 8a3fee3

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

testflight_expiration_warning/main_tf_alert.patch

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
Submodule Loop contains modified content
22
diff --git a/Loop/Loop/Managers/ProfileExpirationAlerter.swift b/Loop/Loop/Managers/ProfileExpirationAlerter.swift
3-
index a28d4527..62f458fb 100644
3+
index 3aa74273..fb33b1cb 100644
44
--- a/Loop/Loop/Managers/ProfileExpirationAlerter.swift
55
+++ b/Loop/Loop/Managers/ProfileExpirationAlerter.swift
6-
@@ -19,13 +19,19 @@ class ProfileExpirationAlerter {
6+
@@ -15,16 +15,20 @@ class ProfileExpirationAlerter {
7+
8+
static let expirationAlertWindow: TimeInterval = .days(20)
9+
static let settingsPageExpirationWarningModeWindow: TimeInterval = .days(3)
10+
-
11+
+
712
static func alertIfNeeded(viewControllerToPresentFrom: UIViewController) {
813

914
let now = Date()
10-
-
11-
- guard let profileExpiration = Bundle.main.profileExpiration, now > profileExpiration - expirationAlertWindow else {
12-
+
13-
+ guard let profileExpiration = Bundle.main.profileExpiration else {
15+
16+
- guard let profileExpiration = BuildDetails.default.profileExpiration, now > profileExpiration - expirationAlertWindow else {
17+
+ guard let profileExpiration = BuildDetails.default.profileExpiration else {
1418
return
1519
}
1620

1721
- let timeUntilExpiration = profileExpiration.timeIntervalSince(now)
1822
+ let expirationDate = calculateExpirationDate(profileExpiration: profileExpiration)
19-
+
2023
+ let timeUntilExpiration = expirationDate.timeIntervalSince(now)
21-
2224
+ if timeUntilExpiration > expirationAlertWindow {
2325
+ return
2426
+ }
25-
+
27+
2628
let minimumTimeBetweenAlerts: TimeInterval = timeUntilExpiration > .hours(24) ? .days(2) : .hours(1)
2729

28-
if let lastAlertDate = UserDefaults.appGroup?.lastProfileExpirationAlertDate {
29-
@@ -43,31 +49,48 @@ class ProfileExpirationAlerter {
30+
@@ -43,31 +47,48 @@ class ProfileExpirationAlerter {
3031

3132
let alertMessage = createVerboseAlertMessage(timeUntilExpirationStr: timeUntilExpirationStr!)
3233

@@ -48,7 +49,7 @@ index a28d4527..62f458fb 100644
4849
+ dialog.addAction(UIAlertAction(title: NSLocalizedString("More Info", comment: "Text for more info action on notification of upcoming TestFlight expiration"), style: .default, handler: { (_) in
4950
+ UIApplication.shared.open(URL(string: "https://loopkit.github.io/loopdocs/gh-actions/gh-update/")!)
5051
+ }))
51-
+
52+
+
5253
+ } else {
5354
+ dialog = UIAlertController(
5455
+ title: NSLocalizedString("Profile Expires Soon", comment: "The title for notification of upcoming profile expiration"),
@@ -89,69 +90,70 @@ index a28d4527..62f458fb 100644
8990
let relativeTimeRemaining: String = readableRelativeTime ?? NSLocalizedString("Unknown time", comment: "Unknown amount of time in settings' profile expiration section")
9091
let verboseMessage = createVerboseAlertMessage(timeUntilExpirationStr: relativeTimeRemaining)
9192
let conciseMessage = relativeTimeRemaining + NSLocalizedString(" remaining", comment: "remaining time in setting's profile expiration section")
92-
@@ -81,6 +104,56 @@ class ProfileExpirationAlerter {
93+
@@ -81,6 +102,57 @@ class ProfileExpirationAlerter {
9394
formatter.unitsStyle = .full
9495
formatter.zeroFormattingBehavior = .dropLeading
9596
formatter.maximumUnitCount = maxUnitCount
9697
- return formatter;
9798
+ return formatter
9899
+ }
99-
+
100+
+
100101
+ static func buildDate() -> Date? {
101102
+ let dateFormatter = DateFormatter()
102103
+ dateFormatter.dateFormat = "EEE MMM d HH:mm:ss 'UTC' yyyy"
103104
+ dateFormatter.locale = Locale(identifier: "en_US_POSIX") // Set locale to ensure parsing works
104105
+ dateFormatter.timeZone = TimeZone(identifier: "UTC")
105-
+
106-
+ guard let dateString = Bundle.main.buildDateString,
106+
+
107+
+ guard let dateString = BuildDetails.default.buildDateString,
107108
+ let date = dateFormatter.date(from: dateString) else {
108109
+ return nil
109110
+ }
110-
+
111+
+
111112
+ return date
112113
+ }
113-
+
114+
+
114115
+ static func isTestFlightBuild() -> Bool {
115116
+ // If the target environment is a simulator, then
116117
+ // this is not a TestFlight distribution. Return false.
117-
+ #if targetEnvironment(simulator)
118-
+ return false
119-
+ #endif
120-
+
118+
+#if targetEnvironment(simulator)
119+
+ return false
120+
+#else
121+
+
121122
+ // If an "embedded.mobileprovision" is present in the main bundle, then
122123
+ // this is an Xcode, Ad-Hoc, or Enterprise distribution. Return false.
123124
+ if Bundle.main.url(forResource: "embedded", withExtension: "mobileprovision") != nil {
124125
+ return false
125126
+ }
126-
+
127+
+
127128
+ // If an app store receipt is not present in the main bundle, then we cannot
128129
+ // say whether this is a TestFlight or App Store distribution. Return false.
129130
+ guard let receiptName = Bundle.main.appStoreReceiptURL?.lastPathComponent else {
130131
+ return false
131132
+ }
132-
+
133+
+
133134
+ // A TestFlight distribution presents a "sandboxReceipt", while an App Store
134135
+ // distribution presents a "receipt". Return true if we have a TestFlight receipt.
135136
+ return "sandboxReceipt".caseInsensitiveCompare(receiptName) == .orderedSame
137+
+#endif
136138
+ }
137-
+
139+
+
138140
+ static func calculateExpirationDate(profileExpiration: Date) -> Date {
139141
+ let isTestFlight = isTestFlightBuild()
140-
+
142+
+
141143
+ if isTestFlight, let buildDate = buildDate() {
142144
+ let testflightExpiration = Calendar.current.date(byAdding: .day, value: 90, to: buildDate)!
143-
+
145+
+
144146
+ return profileExpiration < testflightExpiration ? profileExpiration : testflightExpiration
145147
+ } else {
146148
+ return profileExpiration
147149
+ }
148150
}
149151
}
150152
diff --git a/Loop/Loop/Views/SettingsView.swift b/Loop/Loop/Views/SettingsView.swift
151-
index 90859273..4021e5d4 100644
153+
index 8fca5668..a0b131ef 100644
152154
--- a/Loop/Loop/Views/SettingsView.swift
153155
+++ b/Loop/Loop/Views/SettingsView.swift
154-
@@ -343,23 +343,50 @@ extension SettingsView {
156+
@@ -343,23 +343,49 @@ extension SettingsView {
155157
DIY loop specific component to show users the amount of time remaining on their build before a rebuild is necessary.
156158
*/
157159
private func profileExpirationSection(profileExpiration:Date) -> some View {
@@ -160,15 +162,14 @@ index 90859273..4021e5d4 100644
160162
- let readableExpirationTime = Self.dateFormatter.string(from: profileExpiration)
161163
+ let expirationDate = ProfileExpirationAlerter.calculateExpirationDate(profileExpiration: profileExpiration)
162164
+ let isTestFlight = ProfileExpirationAlerter.isTestFlightBuild()
165+
+ let nearExpiration = ProfileExpirationAlerter.isNearExpiration(expirationDate: expirationDate)
166+
+ let profileExpirationMsg = ProfileExpirationAlerter.createProfileExpirationSettingsMessage(expirationDate: expirationDate)
167+
+ let readableExpirationTime = Self.dateFormatter.string(from: expirationDate)
163168

164169
- return Section(header: SectionHeader(label: NSLocalizedString("App Profile", comment: "Settings app profile section")),
165170
- footer: Text(NSLocalizedString("Profile expires ", comment: "Time that profile expires") + readableExpirationTime)) {
166171
- if(nearExpiration) {
167172
- Text(profileExpirationMsg).foregroundColor(.red)
168-
+ let nearExpiration : Bool = ProfileExpirationAlerter.isNearExpiration(expirationDate: expirationDate)
169-
+ let profileExpirationMsg = ProfileExpirationAlerter.createProfileExpirationSettingsMessage(expirationDate: expirationDate)
170-
+ let readableExpirationTime = Self.dateFormatter.string(from: expirationDate)
171-
+
172173
+ if isTestFlight {
173174
+ return createAppExpirationSection(
174175
+ headerLabel: NSLocalizedString("TestFlight", comment: "Settings app TestFlight section"),

0 commit comments

Comments
 (0)