Skip to content

Commit 3cd5cf6

Browse files
committed
Sync with dev
2 parents d666489 + c61cd6e commit 3cd5cf6

File tree

8 files changed

+45
-70
lines changed

8 files changed

+45
-70
lines changed

Loop/Managers/Alerts/AlertManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ extension AlertManager {
789789
let alert = UIAlertController(title: "New Study Product Detected", message: "We've detected a new study product is selected. In order to show use this study product, Tidepool Loop will need to restart.", preferredStyle: .alert)
790790
alert.addAction(UIAlertAction(title: "Confirm", style: .default, handler: { _ in
791791
confirmAction()
792-
exit(0)
792+
fatalError("DEBUG: Resetting Loop")
793793
}))
794794
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
795795

Loop/Managers/LocalTestingScenariosManager.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ final class LocalTestingScenariosManager: TestingScenariosManagerRequirements, D
3030
delegate?.testingScenariosManager(self, didUpdateScenarioURLs: scenarioURLs)
3131
}
3232
}
33+
34+
var pluginManager: PluginManager {
35+
deviceManager.pluginManager
36+
}
3337

3438
init(deviceManager: DeviceDataManager) {
3539
guard FeatureFlags.scenariosEnabled else {
@@ -63,7 +67,6 @@ final class LocalTestingScenariosManager: TestingScenariosManagerRequirements, D
6367
do {
6468
let scenarioURLs = try fileManager.contentsOfDirectory(at: scenariosSource, includingPropertiesForKeys: nil)
6569
.filter { $0.pathExtension == "json" }
66-
.sorted(by: { $0.lastPathComponent < $1.lastPathComponent })
6770
self.scenarioURLs = scenarioURLs
6871
delegate?.testingScenariosManager(self, didUpdateScenarioURLs: scenarioURLs)
6972
log.debug("Reloaded scenario URLs")

Loop/Managers/LoopAppManager.swift

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -398,45 +398,14 @@ class LoopAppManager: NSObject {
398398
return false
399399
}
400400

401-
private func resetLoop() {
402-
deviceDataManager.pumpManager?.prepareForDeactivation({ _ in })
403-
404-
resetLoopUserDefaults()
405-
resetLoopDocuments()
406-
}
407-
408-
private func resetLoopUserDefaults() {
409-
// Store values to persist
410-
let allowDebugFeatures = UserDefaults.appGroup?.allowDebugFeatures
411-
let studyProductSelection = UserDefaults.appGroup?.studyProductSelection
412-
413-
// Wipe away whole domain
414-
UserDefaults.appGroup?.removePersistentDomain(forName: Bundle.main.appGroupSuiteName)
415-
416-
// Restore values to persist
417-
UserDefaults.appGroup?.allowDebugFeatures = allowDebugFeatures ?? false
418-
UserDefaults.appGroup?.studyProductSelection = studyProductSelection
419-
}
420-
421-
private func resetLoopDocuments() {
422-
let appGroup = Bundle.main.appGroupSuiteName
423-
guard let directoryURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else {
424-
preconditionFailure("Could not get a container directory URL. Please ensure App Groups are set up correctly in entitlements.")
425-
}
426-
427-
let documents: URL = directoryURL.appendingPathComponent("com.loopkit.LoopKit", isDirectory: true)
428-
try? FileManager.default.removeItem(at: documents)
429-
430-
guard let localDocuments = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) else {
431-
preconditionFailure("Could not get a documents directory URL.")
432-
}
433-
try? FileManager.default.removeItem(at: localDocuments)
434-
}
435-
436401
func askUserToConfirmCrashIfNecessary() {
437-
if UserDefaults.appGroup?.resetLoop == true {
438-
alertManager.presentConfirmCrashAlert() { [weak self] in
439-
self?.resetLoop()
402+
deviceDataManager.pluginManager.availableSupports.forEach { supportUI in
403+
if supportUI.loopNeedsReset {
404+
supportUI.loopNeedsReset = false
405+
alertManager.presentConfirmCrashAlert() { [weak self] in
406+
self?.deviceDataManager.pumpManager?.prepareForDeactivation({ _ in })
407+
supportUI.resetLoop()
408+
}
440409
}
441410
}
442411
}

Loop/Managers/OnboardingManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@ extension OnboardingManager: TherapySettingsProvider {
435435

436436
extension OnboardingManager: OnboardingProvider {
437437
var allowDebugFeatures: Bool { FeatureFlags.allowDebugFeatures } // NOTE: DEBUG FEATURES - DEBUG AND TEST ONLY
438-
var studyProductSelection: StudyProduct { StudyProduct(rawValue: UserDefaults.appGroup?.studyProductSelection ?? "none") ?? .none }
438+
}
439+
440+
// MARK: - SupportProvider
441+
442+
extension OnboardingManager: SupportProvider {
443+
var availableSupports: [SupportUI] { deviceDataManager.pluginManager.availableSupports }
439444
}
440445

441446
// MARK: - OnboardingUI

Loop/Managers/TestingScenariosManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ protocol TestingScenariosManager: AnyObject {
1818
var delegate: TestingScenariosManagerDelegate? { get set }
1919
var activeScenarioURL: URL? { get }
2020
var scenarioURLs: [URL] { get }
21+
var pluginManager: PluginManager { get }
2122
func loadScenario(from url: URL, completion: @escaping (Error?) -> Void)
2223
func loadScenario(from url: URL, advancedByLoopIterations iterations: Int, completion: @escaping (Error?) -> Void)
2324
func loadScenario(from url: URL, rewoundByLoopIterations iterations: Int, completion: @escaping (Error?) -> Void)

Loop/View Controllers/TestingScenariosTableViewController.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
1414

1515
private let scenariosManager: TestingScenariosManager
1616

17-
private var scenarioURLs: [URL] = [] {
17+
private var scenarios: [LoopScenario] = [] {
1818
didSet {
19-
options = scenarioURLs.map { $0.deletingPathExtension().lastPathComponent }
19+
options = scenarios.map(\.name)
20+
2021
if isViewLoaded {
2122
DispatchQueue.main.async {
2223
self.updateLoadButtonEnabled()
@@ -58,14 +59,14 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
5859
contextHelp = "The scenarios directory location is available in the debug output of the Xcode console."
5960

6061
if let activeScenarioURL = scenariosManager.activeScenarioURL {
61-
selectedIndex = scenarioURLs.firstIndex(of: activeScenarioURL)
62+
selectedIndex = scenarios.firstIndex(where: { $0.url == activeScenarioURL })
6263
}
6364

6465
updateLoadButtonEnabled()
6566
}
6667

6768
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
68-
let url = scenarioURLs[indexPath.row]
69+
let url = scenarios[indexPath.row].url
6970

7071
let rewindScenario = contextualAction(
7172
rowTitle: "⏮ Rewind",
@@ -79,7 +80,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
7980
}
8081

8182
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
82-
let url = scenarioURLs[indexPath.row]
83+
let url = scenarios[indexPath.row].url
8384

8485
let advanceScenario = contextualAction(
8586
rowTitle: "Advance ⏭",
@@ -130,7 +131,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
130131
}
131132

132133
private func updateLoadButtonEnabled() {
133-
loadButtonItem.isEnabled = !scenarioURLs.isEmpty && selectedIndex != nil
134+
loadButtonItem.isEnabled = !scenarios.isEmpty && selectedIndex != nil
134135
}
135136

136137
@objc private func loadSelectedScenario() {
@@ -139,7 +140,7 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
139140
return
140141
}
141142

142-
let url = scenarioURLs[selectedIndex]
143+
let url = scenarios[selectedIndex].url
143144

144145
loadButtonItem.isEnabled = false
145146
loadButtonItem.title = "Loading..."
@@ -163,6 +164,13 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
163164

164165
extension TestingScenariosTableViewController: TestingScenariosManagerDelegate {
165166
func testingScenariosManager(_ manager: TestingScenariosManager, didUpdateScenarioURLs scenarioURLs: [URL]) {
166-
self.scenarioURLs = scenarioURLs
167+
var filteredScenarios = Set<LoopScenario>()
168+
manager.pluginManager.availableSupports.forEach { supportUI in
169+
supportUI.getScenarios(from: scenarioURLs).forEach { scenario in
170+
filteredScenarios.insert(scenario)
171+
}
172+
}
173+
174+
self.scenarios = Array(filteredScenarios).sorted(by: { $0.name < $1.name })
167175
}
168176
}

LoopCore/NSUserDefaults.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ extension UserDefaults {
2020
case lastProfileExpirationAlertDate = "com.loopkit.Loop.lastProfileExpirationAlertDate"
2121
case allowDebugFeatures = "com.loopkit.Loop.allowDebugFeatures"
2222
case allowSimulators = "com.loopkit.Loop.allowSimulators"
23-
case resetLoop = "com.loopkit.Loop.resetLoop"
24-
case LastMissedMealNotification = "com.loopkit.Loop.lastMissedMealNotification"
25-
case studyProductSelection = "com.loopkit.Loop.studyProductSelection"
2623
}
2724

2825
public static let appGroup = UserDefaults(suiteName: Bundle.main.appGroupSuiteName)
@@ -152,24 +149,6 @@ extension UserDefaults {
152149
public var allowSimulators: Bool {
153150
return bool(forKey: Key.allowSimulators.rawValue)
154151
}
155-
156-
public var studyProductSelection: String? {
157-
get {
158-
string(forKey: Key.studyProductSelection.rawValue)
159-
}
160-
set {
161-
set(newValue, forKey: Key.studyProductSelection.rawValue)
162-
}
163-
}
164-
165-
public var resetLoop: Bool {
166-
get {
167-
bool(forKey: Key.resetLoop.rawValue)
168-
}
169-
set {
170-
setValue(newValue, forKey: Key.resetLoop.rawValue)
171-
}
172-
}
173152

174153
public func removeLegacyLoopSettings() {
175154
removeObject(forKey: "com.loudnate.Naterade.BasalRateSchedule")

LoopTests/Managers/SupportManagerTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,23 @@ class SupportManagerTests: XCTestCase {
3939
override init() { super.init() }
4040
required init?(rawState: RawStateValue) { super.init() }
4141
var rawState: RawStateValue = [:]
42+
43+
var loopNeedsReset: Bool = false
44+
var studyProductSelection: String? = nil
45+
func getScenarios(from scenarioURLs: [URL]) -> [LoopScenario] { [] }
46+
func resetLoop() {}
4247
}
4348
class AnotherMockSupport: Mixin, SupportUI {
4449
func configurationMenuItems() -> [AnyView] { return [] }
4550
static var supportIdentifier: String { "SupportManagerTestsAnotherMockSupport" }
4651
override init() { super.init() }
4752
required init?(rawState: RawStateValue) { super.init() }
4853
var rawState: RawStateValue = [:]
54+
55+
var loopNeedsReset: Bool = false
56+
var studyProductSelection: String? = nil
57+
func getScenarios(from scenarioURLs: [URL]) -> [LoopScenario] { [] }
58+
func resetLoop() {}
4959
}
5060

5161
class MockAlertIssuer: AlertIssuer {

0 commit comments

Comments
 (0)