Procházet zdrojové kódy

Only display the expiration date when accessible

And refactor deprecated code.
Jon B.M před 2 roky
rodič
revize
a1266a427f

+ 5 - 5
FreeAPS/Sources/Helpers/Bundle+Extensions.swift

@@ -19,7 +19,7 @@ extension Bundle {
         return Date()
     }
 
-    var profileExpiration: String {
+    var profileExpiration: String? {
         guard
             let profilePath = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision"),
             let profileData = try? Data(contentsOf: URL(fileURLWithPath: profilePath)),
@@ -29,14 +29,14 @@ extension Bundle {
             print(
                 "WARNING: Could not find or read `embedded.mobileprovision`. If running on Simulator, there are no provisioning profiles."
             )
-            return "N/A"
+            return nil
         }
 
         // NOTE: We have the `[\\W]*?` check to make sure that variations in number of tabs or new lines in the future does not influence the result.
         guard let regex = try? NSRegularExpression(pattern: "<key>ExpirationDate</key>[\\W]*?<date>(.*?)</date>", options: [])
         else {
             print("Warning: Could not create regex.")
-            return "N/A"
+            return nil
         }
 
         let regExMatches = regex.matches(
@@ -48,13 +48,13 @@ extension Bundle {
         // NOTE: range `0` corresponds to the full regex match, so to get the first capture group, we use range `1`
         guard let rangeOfCapturedGroupForDate = regExMatches.first?.range(at: 1) else {
             print("Warning: Could not find regex match or capture group.")
-            return "N/A"
+            return nil
         }
 
         let dateWithTimeAsString = profileNSString.substring(with: rangeOfCapturedGroupForDate)
         
         guard let dateAsStringIndex = dateWithTimeAsString.firstIndex(of: "T") else {
-            return ""
+            return nil
         }
         return String(dateWithTimeAsString[..<dateAsStringIndex])
     }

+ 21 - 13
FreeAPS/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -10,21 +10,29 @@ extension Settings {
 
         var body: some View {
             Form {
-                Section(
-                    header: Text(
-                        "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice)\nBuild Expires: \(Bundle.main.profileExpiration)"
-                    ).textCase(nil)
-                ) {
+                Section {
                     Toggle("Closed loop", isOn: $state.closedLoop)
                 }
+                header: {
+                    if let expirationDate = Bundle.main.profileExpiration {
+                        Text(
+                            "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice)" +
+                                "\nBuild Expires: " + expirationDate
+                        ).textCase(nil)
+                    } else {
+                        Text(
+                            "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice)"
+                        )
+                    }
+                }
 
-                Section(header: Text("Devices")) {
+                Section {
                     Text("Pump").navigationLink(to: .pumpConfig, from: self)
                     Text("CGM").navigationLink(to: .cgm, from: self)
                     Text("Watch").navigationLink(to: .watch, from: self)
-                }
+                } header: { Text("Devices" }
 
-                Section(header: Text("Services")) {
+                Section {
                     Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
                     if HKHealthStore.isHealthDataAvailable() {
                         Text("Apple Health").navigationLink(to: .healthkit, from: self)
@@ -33,9 +41,9 @@ extension Settings {
                     Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
                     Text("App Icons").navigationLink(to: .iconConfig, from: self)
                     Text("Statistics and Home View").navigationLink(to: .statisticsConfig, from: self)
-                }
+                } header: { Text("Services" }
 
-                Section(header: Text("Configuration")) {
+                Section {
                     Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
                     Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
                     Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
@@ -43,9 +51,9 @@ extension Settings {
                     Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
                     Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
                     Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
-                }
+                } header: { Text("Configuration" }
 
-                Section(header: Text("Developer")) {
+                Section {
                     Toggle("Debug options", isOn: $state.debugOptions)
                     if state.debugOptions {
                         Group {
@@ -107,7 +115,7 @@ extension Settings {
                                 .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
                         }
                     }
-                }
+                } header: { Text("Developer" }
 
                 Section {
                     Toggle("Animated Background", isOn: $state.animatedBackground)