diff --git a/CGMBLEKit b/CGMBLEKit index 15af9cf31..b786e8b55 160000 --- a/CGMBLEKit +++ b/CGMBLEKit @@ -1 +1 @@ -Subproject commit 15af9cf319bff2ac49c361da254ad667461d4687 +Subproject commit b786e8b5531cb08c259103c472dcd6a6752728f8 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index fe81f2198..7e89591ef 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -59,7 +59,7 @@ representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the Discord server admins. Please join our [Discord server](https://discord.gg/dbe5Twav8D) to contact +reported to the Discord server admins. Please join our [Discord server](http://discord.diy-trio.org) to contact them directly for any enforcement issues. All complaints will be reviewed and investigated promptly and fairly. diff --git a/Config.xcconfig b/Config.xcconfig index 5d125fdcb..50a431025 100644 --- a/Config.xcconfig +++ b/Config.xcconfig @@ -1,5 +1,5 @@ APP_DISPLAY_NAME = Trio -APP_VERSION = 0.2.1 +APP_VERSION = 0.2.2 APP_BUILD_NUMBER = 1 COPYRIGHT_NOTICE = DEVELOPER_TEAM = ##TEAM_ID## diff --git a/FreeAPS/Sources/APS/FetchGlucoseManager.swift b/FreeAPS/Sources/APS/FetchGlucoseManager.swift index 333b4ef71..7b6f44c78 100644 --- a/FreeAPS/Sources/APS/FetchGlucoseManager.swift +++ b/FreeAPS/Sources/APS/FetchGlucoseManager.swift @@ -1,5 +1,6 @@ import Combine import Foundation +import HealthKit import LoopKit import LoopKitUI import SwiftDate @@ -98,6 +99,14 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable { settingsManager.settings.uploadGlucose = cgmM.shouldSyncToRemoteService } + private func updateManagerUnits(_ manager: CGMManagerUI?) { + let units = settingsManager.settings.units + let managerName = cgmManager.map { "\(type(of: $0))" } ?? "nil" + let loopkitUnits: HKUnit = units == .mgdL ? .milligramsPerDeciliter : .millimolesPerLiter + print("manager: \(managerName) is changing units to: \(loopkitUnits.description) ") + manager?.unitDidChange(to: loopkitUnits) + } + func updateGlucoseSource(cgmGlucoseSourceType: CGMType, cgmGlucosePluginId: String, newManager: CGMManagerUI?) { // if changed, remove all calibrations if self.cgmGlucoseSourceType != cgmGlucoseSourceType || self.cgmGlucosePluginId != cgmGlucosePluginId { @@ -120,6 +129,8 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable { removeCalibrations() } else if self.cgmGlucoseSourceType == .plugin, cgmManager == nil, let rawCGMManager = rawCGMManager { cgmManager = cgmManagerFromRawValue(rawCGMManager) + updateManagerUnits(cgmManager) + } else { saveConfigManager() } @@ -151,7 +162,6 @@ final class BaseFetchGlucoseManager: FetchGlucoseManager, Injectable { else { return nil } - return Manager.init(rawState: rawState) } diff --git a/FreeAPS/Sources/APS/OpenAPS/JavaScriptWorker.swift b/FreeAPS/Sources/APS/OpenAPS/JavaScriptWorker.swift index 66991b2b6..d0829319e 100644 --- a/FreeAPS/Sources/APS/OpenAPS/JavaScriptWorker.swift +++ b/FreeAPS/Sources/APS/OpenAPS/JavaScriptWorker.swift @@ -3,10 +3,32 @@ import JavaScriptCore private let contextLock = NSRecursiveLock() +extension String { + var lowercasingFirst: String { prefix(1).lowercased() + dropFirst() } + var uppercasingFirst: String { prefix(1).uppercased() + dropFirst() } + var camelCased: String { + guard !isEmpty else { return "" } + let parts = components(separatedBy: .alphanumerics.inverted) + let first = parts.first!.lowercasingFirst + let rest = parts.dropFirst().map(\.uppercasingFirst) + return ([first] + rest).joined() + } + + var pascalCased: String { + guard !isEmpty else { return "" } + let parts = components(separatedBy: .alphanumerics.inverted) + let first = parts.first!.uppercasingFirst + let rest = parts.dropFirst().map(\.uppercasingFirst) + return ([first] + rest).joined() + } +} + final class JavaScriptWorker { private let processQueue = DispatchQueue(label: "DispatchQueue.JavaScriptWorker") private let virtualMachine: JSVirtualMachine @SyncAccess(lock: contextLock) private var commonContext: JSContext? = nil + private var consoleLogs: [String] = [] + private var logContext: String = "" init() { virtualMachine = processQueue.sync { JSVirtualMachine()! } @@ -20,9 +42,11 @@ final class JavaScriptWorker { } } let consoleLog: @convention(block) (String) -> Void = { message in - debug(.openAPS, "JavaScript log: \(message)") + let trimmedMessage = message.trimmingCharacters(in: .whitespacesAndNewlines) + if !trimmedMessage.isEmpty { + self.consoleLogs.append("\(trimmedMessage)") + } } - context.setObject( consoleLog, forKeyedSubscript: "_consoleLog" as NSString @@ -30,8 +54,37 @@ final class JavaScriptWorker { return context } + // New method to flush aggregated logs + private func outputLogs() { + var outputLogs = consoleLogs.joined(separator: "\n").trimmingCharacters(in: .whitespacesAndNewlines) + consoleLogs.removeAll() + + if outputLogs.isEmpty { return } + + if logContext == "autosens.js" { + outputLogs = outputLogs.split(separator: "\n").map { logLine in + logLine.replacingOccurrences( + of: "^[-+=x!]|u\\(|\\)|\\d{1,2}h$", + with: "", + options: .regularExpression + ) + }.joined(separator: "\n") + } + + if !outputLogs.isEmpty { + outputLogs.split(separator: "\n").forEach { logLine in + if !"\(logLine)".trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + debug(.openAPS, "\(logContext): \(logLine)") + } + } + } + } + @discardableResult func evaluate(script: Script) -> JSValue! { - evaluate(string: script.body) + logContext = URL(fileURLWithPath: script.name).lastPathComponent + let result = evaluate(string: script.body) + outputLogs() + return result } private func evaluate(string: String) -> JSValue! { @@ -52,6 +105,7 @@ final class JavaScriptWorker { commonContext = createContext() defer { commonContext = nil + outputLogs() } return execute(self) } diff --git a/FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift b/FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift index 5aefb7929..4d3c5e54e 100644 --- a/FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift +++ b/FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift @@ -635,11 +635,11 @@ final class OpenAPS { private func middlewareScript(name: String) -> Script? { if let body = storage.retrieveRaw(name) { - return Script(name: "Middleware", body: body) + return Script(name: name, body: body) } if let url = Foundation.Bundle.main.url(forResource: "javascript/\(name)", withExtension: "") { - return Script(name: "Middleware", body: try! String(contentsOf: url)) + return Script(name: name, body: try! String(contentsOf: url)) } return nil diff --git a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift index e57cc3633..09cfd99d8 100644 --- a/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift +++ b/FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift @@ -45,7 +45,7 @@ extension DataTable { formatter.minimumFractionDigits = 0 formatter.maximumFractionDigits = 1 } - formatter.roundingMode = .down + formatter.roundingMode = .halfUp return formatter } diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift index 1bbd54d6c..0915350f2 100644 --- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift +++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorDataFlow.swift @@ -109,6 +109,7 @@ protocol PreferencesEditorProvider: Provider { var preferences: Preferences { get } func savePreferences(_ preferences: Preferences) func migrateUnits() + func updateManagerUnits() } protocol PreferencesSettable: AnyObject { diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift index 7e8c63a04..f2a2765e1 100644 --- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift +++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorProvider.swift @@ -1,8 +1,10 @@ import Foundation +import HealthKit extension PreferencesEditor { final class Provider: BaseProvider, PreferencesEditorProvider { @Injected() private var settingsManager: SettingsManager! + @Injected() var fetchGlucoseManager: FetchGlucoseManager! private let processQueue = DispatchQueue(label: "PreferencesEditorProvider.processQueue") var preferences: Preferences { @@ -17,6 +19,15 @@ extension PreferencesEditor { } } + func updateManagerUnits() { + var manager = fetchGlucoseManager.cgmManager + let managerName = manager.map { "\(type(of: $0))" } ?? "nil" + let units = settingsManager.settings.units + let loopkitUnits: HKUnit = units == .mgdL ? .milligramsPerDeciliter : .millimolesPerLiter + print("manager: \(managerName) is changing units to: \(loopkitUnits.description) ") + manager?.unitDidChange(to: loopkitUnits) + } + func migrateUnits() { migrateTargets() migrateISF() diff --git a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift index d28869fb5..01175ffb7 100644 --- a/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift +++ b/FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift @@ -16,6 +16,7 @@ extension PreferencesEditor { subscribeSetting(\.units, on: $unitsIndex.map { $0 == 0 ? GlucoseUnits.mgdL : .mmolL }) { unitsIndex = $0 == .mgdL ? 0 : 1 } didSet: { [weak self] _ in + self?.provider.updateManagerUnits() self?.provider.migrateUnits() } diff --git a/G7SensorKit b/G7SensorKit index b5e992e21..2be3eb29b 160000 --- a/G7SensorKit +++ b/G7SensorKit @@ -1 +1 @@ -Subproject commit b5e992e211d2ac6224acb105dd97fb484767da72 +Subproject commit 2be3eb29b0a18aa89f8b60281341e46e07d024e5 diff --git a/LibreTransmitter b/LibreTransmitter index c01eba63e..a230b91a3 160000 --- a/LibreTransmitter +++ b/LibreTransmitter @@ -1 +1 @@ -Subproject commit c01eba63e94e9f6f2841a8835680c4e39c61b18d +Subproject commit a230b91a3d30c7b0d4ffbd240234b34cbaf354b1 diff --git a/LoopKit b/LoopKit index 6d9b19ab7..edb69560c 160000 --- a/LoopKit +++ b/LoopKit @@ -1 +1 @@ -Subproject commit 6d9b19ab7e9f749d573fd42f6bcd2ce4c302cf66 +Subproject commit edb69560cb921a8848ea0a450c89bd26cbe54046 diff --git a/OmniBLE b/OmniBLE index eacf06f78..4ad811774 160000 --- a/OmniBLE +++ b/OmniBLE @@ -1 +1 @@ -Subproject commit eacf06f7873e73d6cb8ccd0556b35f734b90df40 +Subproject commit 4ad811774c09cae208678552dbc20ee6cc9d4f59 diff --git a/OmniKit b/OmniKit index 03d3a1db5..01bc59889 160000 --- a/OmniKit +++ b/OmniKit @@ -1 +1 @@ -Subproject commit 03d3a1db5a4da9b218a60254fa1b0ea72ee808ed +Subproject commit 01bc59889b9216737942ea3f0cab22f6a6c4a0e8 diff --git a/README.md b/README.md index 56af6b2fb..28dd24a03 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Instructions in greater detail, but not Trio-specific: # Documentation -[Discord Trio - Server ](https://discord.gg/KepAG6RdYZ) +[Discord Trio - Server ](http://discord.diy-trio.org) [Trio documentation](https://docs.diy-trio.org/en/latest/) diff --git a/TidepoolService b/TidepoolService index a2ccad72a..b28625628 160000 --- a/TidepoolService +++ b/TidepoolService @@ -1 +1 @@ -Subproject commit a2ccad72a55600c28549ab86ab1964c0d6558868 +Subproject commit b28625628e181b96f0db7ec3739d920a3c92465b