Преглед изворни кода

Merge branch 'dev' of github.com:nightscout/Trio-dev into auto-vesion-action

Deniz Cengiz пре 1 година
родитељ
комит
530b4c6668

+ 1 - 0
Trio/Resources/Info.plist

@@ -103,6 +103,7 @@
 		<string>fetch</string>
 		<string>processing</string>
 		<string>remote-notification</string>
+		<string>audio</string>
 	</array>
 	<key>UIFileSharingEnabled</key>
 	<true/>

+ 2 - 0
Trio/Sources/Application/TrioApp.swift

@@ -86,6 +86,8 @@ extension Notification.Name {
     }
 
     init() {
+        FileProtectionFixer.fixFlagFileProtectionForPropertyPersistentFlags() // TODO: ‼️ REMOVE ME BEFORE PUBLIC BETA / RELEASE
+
         let notificationCenter = Foundation.NotificationCenter.default
         notificationCenter.addObserver(
             forName: .initializationCompleted,

+ 63 - 4
Trio/Sources/Helpers/PropertyWrappers/PersistedProperty.swift

@@ -76,24 +76,83 @@ import Foundation
 
                 guard let value = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? Value
                 else {
+                    debug(.storage, "[PersistedProperty:\(key)] Could not cast property list to expected type.")
                     return nil
                 }
                 return value
-            } catch {}
-            return nil
+            } catch {
+                debug(.storage, "❌ [PersistedProperty:\(key)] Failed to read value: \(error.localizedDescription)")
+                return nil
+            }
         }
         set {
             guard let newValue = newValue else {
                 do {
                     try FileManager.default.removeItem(at: storageURL)
-                } catch {}
+                    debug(.storage, "[PersistedProperty:\(key)] Removed value.")
+                } catch {
+                    debug(.storage, "❌ [PersistedProperty:\(key)] Failed to remove value: \(error.localizedDescription)")
+                }
                 return
             }
+
             do {
                 let data = try PropertyListSerialization.data(fromPropertyList: newValue, format: .binary, options: 0)
                 try data.write(to: storageURL, options: .atomic)
 
-            } catch {}
+                // Ensure appropriate protection level
+                try FileManager.default.setAttributes(
+                    [.protectionKey: FileProtectionType.none],
+                    ofItemAtPath: storageURL.path
+                )
+
+                debug(.storage, "✅ [PersistedProperty:\(key)] Saved value successfully.")
+            } catch {
+                debug(.storage, "❌ [PersistedProperty:\(key)] Failed to write value: \(error.localizedDescription)")
+            }
+        }
+    }
+}
+
+import Foundation
+
+enum FileProtectionFixer {
+    /// Ensures only critical persisted flags have safe file protection set.
+    static func fixFlagFileProtectionForPropertyPersistentFlags() {
+        let flagFiles = [
+            "onboardingCompleted.plist",
+            "diagnosticsSharing.plist",
+            "lastCleanupDate.plist"
+        ]
+
+        let fileManager = FileManager.default
+
+        guard let documentsURL = try? fileManager.url(
+            for: .documentDirectory,
+            in: .userDomainMask,
+            appropriateFor: nil,
+            create: false
+        ) else {
+            debug(.storage, "⚠️ Could not access the documents directory.")
+            return
+        }
+
+        for fileName in flagFiles {
+            let fileURL = documentsURL.appendingPathComponent(fileName)
+
+            guard fileManager.fileExists(atPath: fileURL.path) else {
+                continue // Skip if file doesn’t exist yet
+            }
+
+            do {
+                try fileManager.setAttributes(
+                    [.protectionKey: FileProtectionType.none],
+                    ofItemAtPath: fileURL.path
+                )
+                debug(.storage, "✅ Updated protection for \(fileName)")
+            } catch {
+                debug(.storage, "❌ Failed to update protection for \(fileName): \(error)")
+            }
         }
     }
 }

+ 2 - 2
Trio/Sources/Models/DecimalPickerSettings.swift

@@ -66,8 +66,8 @@ struct DecimalPickerSettings {
         max: 5,
         type: PickerSetting.PickerSettingType.factor
     )
-    var autosensMax = PickerSetting(value: 1.2, step: 0.1, min: 0.5, max: 2, type: PickerSetting.PickerSettingType.factor)
-    var autosensMin = PickerSetting(value: 0.7, step: 0.1, min: 0.5, max: 1, type: PickerSetting.PickerSettingType.factor)
+    var autosensMax = PickerSetting(value: 1.2, step: 0.05, min: 0.5, max: 2, type: PickerSetting.PickerSettingType.factor)
+    var autosensMin = PickerSetting(value: 0.7, step: 0.05, min: 0.5, max: 1, type: PickerSetting.PickerSettingType.factor)
     var smbDeliveryRatio = PickerSetting(value: 0.5, step: 0.05, min: 0.3, max: 0.7, type: PickerSetting.PickerSettingType.factor)
     var halfBasalExerciseTarget = PickerSetting(
         value: 160,

+ 7 - 2
Trio/Sources/Services/LiveActivity/LiveActivityManager.swift

@@ -305,7 +305,10 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
         if let currentActivity = currentActivity {
             if currentActivity.needsRecreation(), UIApplication.shared.applicationState == .active {
                 await endActivity()
-                await pushUpdate(state)
+                Task { @MainActor in
+                    await self.pushUpdate(state)
+                }
+                return
             } else {
                 let content = ActivityContent(
                     state: state,
@@ -408,7 +411,9 @@ final class LiveActivityManager: Injectable, ObservableObject, SettingsObserver
             try? await Task.sleep(nanoseconds: 200_000_000) // 0.2s sleep
         }
 
-        await pushUpdate(contentState)
+        Task { @MainActor in
+            await self.pushUpdate(contentState)
+        }
         debug(.default, "Restarted Live Activity from LiveActivityIntent (via iOS Shortcut)")
     }
 }