Skip to content

Commit c788285

Browse files
authored
Merge pull request #572 from tidepool-org/ps2/CPA-89/reduce-healthkit-coupling
CPA-89 Reduce HealthKit Coupling
2 parents 7f9abb8 + 447cce7 commit c788285

23 files changed

+332
-434
lines changed

Loop Status Extension/StatusViewController.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,12 @@ class StatusViewController: UIViewController, NCWidgetProviding {
8484
expireAfter: localCacheDuration)
8585

8686
lazy var glucoseStore = GlucoseStore(
87-
healthStore: healthStore,
88-
observeHealthKitSamplesFromOtherApps: FeatureFlags.observeHealthKitGlucoseSamplesFromOtherApps,
89-
storeSamplesToHealthKit: false,
9087
cacheStore: cacheStore,
91-
observationEnabled: false,
9288
provenanceIdentifier: HKSource.default().bundleIdentifier
9389
)
9490

9591
lazy var doseStore = DoseStore(
96-
healthStore: healthStore,
97-
observeHealthKitSamplesFromOtherApps: FeatureFlags.observeHealthKitDoseSamplesFromOtherApps,
98-
storeSamplesToHealthKit: false,
9992
cacheStore: cacheStore,
100-
observationEnabled: false,
10193
insulinModelProvider: PresetInsulinModelProvider(defaultRapidActingModel: settingsStore.latestSettings?.defaultRapidActingModel?.presetForRapidActingInsulin),
10294
longestEffectDuration: ExponentialInsulinModelPreset.rapidActingAdult.effectDuration,
10395
basalProfile: settingsStore.latestSettings?.basalRateSchedule,

Loop.xcodeproj/project.pbxproj

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@
460460
C16B983E26B4893300256B05 /* DoseEnactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16B983D26B4893300256B05 /* DoseEnactor.swift */; };
461461
C16B984026B4898800256B05 /* DoseEnactorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16B983F26B4898800256B05 /* DoseEnactorTests.swift */; };
462462
C16DA84222E8E112008624C2 /* PluginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16DA84122E8E112008624C2 /* PluginManager.swift */; };
463+
C1735B1E2A0809830082BB8A /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = C1735B1D2A0809830082BB8A /* ZIPFoundation */; };
463464
C1742332259BEADC00399C9D /* ManualEntryDoseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1742331259BEADC00399C9D /* ManualEntryDoseView.swift */; };
464465
C174233C259BEB0F00399C9D /* ManualEntryDoseViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C174233B259BEB0F00399C9D /* ManualEntryDoseViewModel.swift */; };
465466
C1777A6625A125F100595963 /* ManualEntryDoseViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1777A6525A125F100595963 /* ManualEntryDoseViewModelTests.swift */; };
@@ -476,14 +477,10 @@
476477
C191D2A125B3ACAA00C26C0B /* DosingStrategySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C191D2A025B3ACAA00C26C0B /* DosingStrategySelectionView.swift */; };
477478
C19C8BBA28651DFB0056D5E4 /* TrueTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BB928651DFB0056D5E4 /* TrueTime.framework */; };
478479
C19C8BBB28651DFB0056D5E4 /* TrueTime.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BB928651DFB0056D5E4 /* TrueTime.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
479-
C19C8BBC28651E1C0056D5E4 /* Minizip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1750AEB255B013300B8011C /* Minizip.framework */; };
480-
C19C8BBD28651E1C0056D5E4 /* Minizip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C1750AEB255B013300B8011C /* Minizip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
481480
C19C8BBE28651E3D0056D5E4 /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; };
482481
C19C8BBF28651E3D0056D5E4 /* LoopKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
483482
C19C8BC328651EAE0056D5E4 /* LoopTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BC228651EAE0056D5E4 /* LoopTestingKit.framework */; };
484483
C19C8BC428651EAE0056D5E4 /* LoopTestingKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C19C8BC228651EAE0056D5E4 /* LoopTestingKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
485-
C19C8BC528651EE50056D5E4 /* MKRingProgressView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1E2774722433D7A00354103 /* MKRingProgressView.framework */; };
486-
C19C8BC628651EE50056D5E4 /* MKRingProgressView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C1E2774722433D7A00354103 /* MKRingProgressView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
487484
C19C8BCE28651F520056D5E4 /* LoopKitUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 437AFEE6203688CF008C4892 /* LoopKitUI.framework */; };
488485
C19C8BCF28651F520056D5E4 /* LoopKitUI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 437AFEE6203688CF008C4892 /* LoopKitUI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
489486
C19C8C1E28663B040056D5E4 /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4344628320A7A3BE00C4BE6F /* LoopKit.framework */; };
@@ -502,6 +499,7 @@
502499
C1D0B6302986D4D90098D215 /* LocalizedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D0B62F2986D4D90098D215 /* LocalizedString.swift */; };
503500
C1D0B6312986D4D90098D215 /* LocalizedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D0B62F2986D4D90098D215 /* LocalizedString.swift */; };
504501
C1D289B522F90A52003FFBD9 /* BasalDeliveryState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D289B422F90A52003FFBD9 /* BasalDeliveryState.swift */; };
502+
C1D6EEA02A06C7270047DE5C /* MKRingProgressView in Frameworks */ = {isa = PBXBuildFile; productRef = C1D6EE9F2A06C7270047DE5C /* MKRingProgressView */; };
505503
C1DE5D23251BFC4D00439E49 /* SimpleBolusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1DE5D22251BFC4D00439E49 /* SimpleBolusView.swift */; };
506504
C1E2773E224177C000354103 /* ClockKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1E2773D224177C000354103 /* ClockKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
507505
C1E3862628247C6100F561A4 /* StoredLoopNotRunningNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1E3862428247B7100F561A4 /* StoredLoopNotRunningNotification.swift */; };
@@ -727,13 +725,11 @@
727725
4F2C159A1E0C9E5600E160D4 /* LoopUI.framework in Embed Frameworks */,
728726
C19C8BCF28651F520056D5E4 /* LoopKitUI.framework in Embed Frameworks */,
729727
C11B9D63286779C000500CF8 /* MockKit.framework in Embed Frameworks */,
730-
C19C8BBD28651E1C0056D5E4 /* Minizip.framework in Embed Frameworks */,
731728
C19C8BBB28651DFB0056D5E4 /* TrueTime.framework in Embed Frameworks */,
732729
C11B9D65286779C000500CF8 /* MockKitUI.framework in Embed Frameworks */,
733730
C1F00C78285A8256006302C5 /* SwiftCharts in Embed Frameworks */,
734731
C19C8BBF28651E3D0056D5E4 /* LoopKit.framework in Embed Frameworks */,
735732
43D9FFD721EAE05D00AF44BF /* LoopCore.framework in Embed Frameworks */,
736-
C19C8BC628651EE50056D5E4 /* MKRingProgressView.framework in Embed Frameworks */,
737733
);
738734
name = "Embed Frameworks";
739735
runOnlyForDeploymentPostprocessing = 0;
@@ -1820,17 +1816,17 @@
18201816
isa = PBXFrameworksBuildPhase;
18211817
buildActionMask = 2147483647;
18221818
files = (
1819+
C1D6EEA02A06C7270047DE5C /* MKRingProgressView in Frameworks */,
18231820
43F5C2C91B929C09003EB13D /* HealthKit.framework in Frameworks */,
18241821
43D9FFD621EAE05D00AF44BF /* LoopCore.framework in Frameworks */,
1825-
C19C8BBC28651E1C0056D5E4 /* Minizip.framework in Frameworks */,
18261822
C11B9D64286779C000500CF8 /* MockKitUI.framework in Frameworks */,
18271823
4F7528941DFE1E9500C322D6 /* LoopUI.framework in Frameworks */,
18281824
C11B9D62286779C000500CF8 /* MockKit.framework in Frameworks */,
18291825
C19C8BBE28651E3D0056D5E4 /* LoopKit.framework in Frameworks */,
18301826
C19C8BBA28651DFB0056D5E4 /* TrueTime.framework in Frameworks */,
18311827
C1F00C60285A802A006302C5 /* SwiftCharts in Frameworks */,
1832-
C19C8BC528651EE50056D5E4 /* MKRingProgressView.framework in Frameworks */,
18331828
C19C8BC328651EAE0056D5E4 /* LoopTestingKit.framework in Frameworks */,
1829+
C1735B1E2A0809830082BB8A /* ZIPFoundation in Frameworks */,
18341830
C19C8BCE28651F520056D5E4 /* LoopKitUI.framework in Frameworks */,
18351831
);
18361832
runOnlyForDeploymentPostprocessing = 0;
@@ -3141,6 +3137,8 @@
31413137
name = Loop;
31423138
packageProductDependencies = (
31433139
C1F00C5F285A802A006302C5 /* SwiftCharts */,
3140+
C1D6EE9F2A06C7270047DE5C /* MKRingProgressView */,
3141+
C1735B1D2A0809830082BB8A /* ZIPFoundation */,
31443142
);
31453143
productName = Loop;
31463144
productReference = 43776F8C1B8022E90074EA36 /* Loop.app */;
@@ -3464,6 +3462,8 @@
34643462
mainGroup = 43776F831B8022E90074EA36;
34653463
packageReferences = (
34663464
C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */,
3465+
C1D6EE9E2A06C7270047DE5C /* XCRemoteSwiftPackageReference "MKRingProgressView" */,
3466+
C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
34673467
);
34683468
productRefGroup = 43776F8D1B8022E90074EA36 /* Products */;
34693469
projectDirPath = "";
@@ -5883,6 +5883,14 @@
58835883
/* End XCConfigurationList section */
58845884

58855885
/* Begin XCRemoteSwiftPackageReference section */
5886+
C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
5887+
isa = XCRemoteSwiftPackageReference;
5888+
repositoryURL = "https://github.com/LoopKit/ZIPFoundation.git";
5889+
requirement = {
5890+
branch = "stream-entry";
5891+
kind = branch;
5892+
};
5893+
};
58865894
C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */ = {
58875895
isa = XCRemoteSwiftPackageReference;
58885896
repositoryURL = "https://github.com/ivanschuetz/SwiftCharts";
@@ -5891,6 +5899,14 @@
58915899
kind = branch;
58925900
};
58935901
};
5902+
C1D6EE9E2A06C7270047DE5C /* XCRemoteSwiftPackageReference "MKRingProgressView" */ = {
5903+
isa = XCRemoteSwiftPackageReference;
5904+
repositoryURL = "https://github.com/maxkonovalov/MKRingProgressView.git";
5905+
requirement = {
5906+
branch = master;
5907+
kind = branch;
5908+
};
5909+
};
58945910
/* End XCRemoteSwiftPackageReference section */
58955911

58965912
/* Begin XCSwiftPackageProductDependency section */
@@ -5899,11 +5915,21 @@
58995915
package = C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */;
59005916
productName = SwiftCharts;
59015917
};
5918+
C1735B1D2A0809830082BB8A /* ZIPFoundation */ = {
5919+
isa = XCSwiftPackageProductDependency;
5920+
package = C1735B1C2A0809830082BB8A /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
5921+
productName = ZIPFoundation;
5922+
};
59025923
C1CCF1162858FBAD0035389C /* SwiftCharts */ = {
59035924
isa = XCSwiftPackageProductDependency;
59045925
package = C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */;
59055926
productName = SwiftCharts;
59065927
};
5928+
C1D6EE9F2A06C7270047DE5C /* MKRingProgressView */ = {
5929+
isa = XCSwiftPackageProductDependency;
5930+
package = C1D6EE9E2A06C7270047DE5C /* XCRemoteSwiftPackageReference "MKRingProgressView" */;
5931+
productName = MKRingProgressView;
5932+
};
59075933
C1E3DC4628595FAA00CA19FF /* SwiftCharts */ = {
59085934
isa = XCSwiftPackageProductDependency;
59095935
package = C1CCF10B2858F4F70035389C /* XCRemoteSwiftPackageReference "SwiftCharts" */;

Loop/Extensions/DeviceDataManager+BolusEntryViewModelDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension DeviceDataManager: BolusEntryViewModelDelegate, ManualDoseViewModelDel
7070
}
7171

7272
var preferredGlucoseUnit: HKUnit {
73-
return glucoseStore.preferredUnit ?? .milligramsPerDeciliter
73+
return displayGlucoseUnitObservable.displayGlucoseUnit
7474
}
7575

7676
var pumpInsulinType: InsulinType? {

Loop/Managers/Alerts/AlertManager.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,10 @@ extension AlertManager {
799799
}
800800

801801
func presentCouldNotResetLoopAlert(error: Error) {
802-
let alert = UIAlertController(title: "Could Not Restart Tidepool Loop", message: "While trying to restart Tidepool Loop an error occured.\n\n\(error.localizedDescription)", preferredStyle: .alert)
803-
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
802+
let titleString = String(format: NSLocalizedString("Could Not Restart %1$@", comment: "Format string for title of reset loop alert. (1: App name)"), Bundle.main.bundleDisplayName)
803+
let message = String(format: NSLocalizedString("While trying to restart %1$@ an error occured.\n\n%2$@", comment: "Format string for message of reset loop alert. (1: App name) (2: error description)"), Bundle.main.bundleDisplayName, error.localizedDescription)
804+
let alert = UIAlertController(title: titleString, message: message, preferredStyle: .alert)
805+
alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel button for reset loop alert"), style: .cancel))
804806

805807
alertPresenter.present(alert, animated: true)
806808
}

Loop/Managers/Alerts/AlertStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ extension AlertStore: CriticalEventLog {
539539
return result!
540540
}
541541

542-
public func export(startDate: Date, endDate: Date, to stream: OutputStream, progress: Progress) -> Error? {
542+
public func export(startDate: Date, endDate: Date, to stream: DataOutputStream, progress: Progress) -> Error? {
543543
let encoder = JSONStreamEncoder(stream: stream)
544544
var modificationCounter: Int64 = 0
545545
var fetching = true

Loop/Managers/CriticalEventLogExportManager.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public class CriticalEventLogBaseExporter {
250250
}
251251
}
252252

253-
fileprivate func export(startDate: Date, endDate: Date, to url: URL, compression: ZipArchive.Compression, progress: Progress) -> Error? {
253+
fileprivate func export(startDate: Date, endDate: Date, to url: URL, progress: Progress) -> Error? {
254254
guard !progress.isCancelled else {
255255
return CriticalEventLogError.cancelled
256256
}
@@ -261,24 +261,32 @@ public class CriticalEventLogBaseExporter {
261261
defer { archive.close() }
262262

263263
for log in manager.logs {
264-
if let error = export(startDate: startDate, endDate: endDate, from: log, to: archive, compression: compression, progress: progress) {
264+
if let error = export(startDate: startDate, endDate: endDate, from: log, to: archive, progress: progress) {
265265
return error
266266
}
267267
}
268268

269269
return archive.close()
270270
}
271271

272-
private func export(startDate: Date, endDate: Date, from log: CriticalEventLog, to archive: ZipArchive, compression: ZipArchive.Compression, progress: Progress) -> Error? {
272+
private func export(startDate: Date, endDate: Date, from log: CriticalEventLog, to archive: ZipArchive, progress: Progress) -> Error? {
273273
guard !progress.isCancelled else {
274274
return CriticalEventLogError.cancelled
275275
}
276276

277-
let stream = archive.createArchiveFile(withPath: log.exportName, compression: compression)
278-
stream.open()
279-
defer { stream.close() }
277+
let stream = archive.createArchiveFile(withPath: log.exportName)
280278

281-
return log.export(startDate: startDate, endDate: endDate, to: stream, progress: progress)
279+
if let error = log.export(startDate: startDate, endDate: endDate, to: stream, progress: progress) {
280+
return error
281+
}
282+
283+
do {
284+
try stream.finish(sync: true)
285+
} catch {
286+
return error
287+
}
288+
289+
return nil
282290
}
283291

284292
fileprivate func historicalDate(from now: Date) -> Date { manager.exportDate(for: manager.date(byAddingDays: -Int(manager.historicalDuration.days), to: now)) }
@@ -334,7 +342,7 @@ public class CriticalEventLogHistoricalExporter: CriticalEventLogBaseExporter, C
334342
let temporaryFileURL = manager.fileManager.temporaryFileURL
335343
defer { try? manager.fileManager.removeItem(at: temporaryFileURL) }
336344

337-
if let error = export(startDate: startDate, endDate: endDate, to: temporaryFileURL, compression: .bestCompression, progress: progress) {
345+
if let error = export(startDate: startDate, endDate: endDate, to: temporaryFileURL, progress: progress) {
338346
return error
339347
}
340348

@@ -431,7 +439,7 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
431439

432440
log.default("Exporting %{public}@...", recentFileURL.lastPathComponent)
433441

434-
if let error = export(startDate: manager.recentDate(from: now), endDate: now, to: recentTemporaryFileURL, compression: .bestSpeed, progress: progress) {
442+
if let error = export(startDate: manager.recentDate(from: now), endDate: now, to: recentTemporaryFileURL, progress: progress) {
435443
return error
436444
}
437445

@@ -460,7 +468,8 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
460468
date = manager.date(byAddingDays: 1, to: date)
461469

462470
let exportFileURL = exportsFileURL(for: date)
463-
if let error = archive.createArchiveFile(withPath: exportFileURL.lastPathComponent, contentsOf: exportFileURL) {
471+
log.default("Bundling %{public}@", exportFileURL.lastPathComponent)
472+
if let error = archive.createArchiveFile(withPath: exportFileURL.lastPathComponent, contentsOf: exportFileURL, compressionMethod: .none) {
464473
return error
465474
}
466475

@@ -471,7 +480,8 @@ public class CriticalEventLogFullExporter: CriticalEventLogBaseExporter, Critica
471480
return CriticalEventLogError.cancelled
472481
}
473482

474-
if let error = archive.createArchiveFile(withPath: recentFileURL.lastPathComponent, contentsOf: recentTemporaryFileURL) {
483+
log.default("Bundling %{public}@", recentFileURL.lastPathComponent)
484+
if let error = archive.createArchiveFile(withPath: recentFileURL.lastPathComponent, contentsOf: recentTemporaryFileURL, compressionMethod: .none) {
475485
return error
476486
}
477487

0 commit comments

Comments
 (0)