Skip to content

Commit 8f8f093

Browse files
committed
[LOOP-4596] Scenario Organization
1 parent 281e4e1 commit 8f8f093

File tree

2 files changed

+7
-58
lines changed

2 files changed

+7
-58
lines changed

Loop/Managers/LoopAppManager.swift

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -370,45 +370,14 @@ class LoopAppManager: NSObject {
370370
return false
371371
}
372372

373-
private func resetLoop() {
374-
deviceDataManager.pumpManager?.prepareForDeactivation({ _ in })
375-
376-
resetLoopUserDefaults()
377-
resetLoopDocuments()
378-
}
379-
380-
private func resetLoopUserDefaults() {
381-
// Store values to persist
382-
let allowDebugFeatures = UserDefaults.appGroup?.allowDebugFeatures
383-
let studyProductSelection = UserDefaults.appGroup?.studyProductSelection
384-
385-
// Wipe away whole domain
386-
UserDefaults.appGroup?.removePersistentDomain(forName: Bundle.main.appGroupSuiteName)
387-
388-
// Restore values to persist
389-
UserDefaults.appGroup?.allowDebugFeatures = allowDebugFeatures ?? false
390-
UserDefaults.appGroup?.studyProductSelection = studyProductSelection
391-
}
392-
393-
private func resetLoopDocuments() {
394-
let appGroup = Bundle.main.appGroupSuiteName
395-
guard let directoryURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) else {
396-
preconditionFailure("Could not get a container directory URL. Please ensure App Groups are set up correctly in entitlements.")
397-
}
398-
399-
let documents: URL = directoryURL.appendingPathComponent("com.loopkit.LoopKit", isDirectory: true)
400-
try? FileManager.default.removeItem(at: documents)
401-
402-
guard let localDocuments = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) else {
403-
preconditionFailure("Could not get a documents directory URL.")
404-
}
405-
try? FileManager.default.removeItem(at: localDocuments)
406-
}
407-
408373
func askUserToConfirmCrashIfNecessary() {
409-
if UserDefaults.appGroup?.resetLoop == true {
410-
alertManager.presentConfirmCrashAlert() { [weak self] in
411-
self?.resetLoop()
374+
deviceDataManager.pluginManager.availableSupports.forEach { supportUI in
375+
if supportUI.loopNeedsReset {
376+
supportUI.loopNeedsReset = false
377+
alertManager.presentConfirmCrashAlert() { [weak self] in
378+
self?.deviceDataManager.pumpManager?.prepareForDeactivation({ _ in })
379+
supportUI.resetLoop()
380+
}
412381
}
413382
}
414383
}

LoopCore/NSUserDefaults.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +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 studyProductSelection = "org.tidepool.plugins.TidepoolSupport.StudyProductSelection"
24-
case resetLoop = "com.loopkit.Loop.resetLoop"
2523
}
2624

2725
public static let appGroup = UserDefaults(suiteName: Bundle.main.appGroupSuiteName)
@@ -128,24 +126,6 @@ extension UserDefaults {
128126
public var allowSimulators: Bool {
129127
return bool(forKey: Key.allowSimulators.rawValue)
130128
}
131-
132-
public var studyProductSelection: String? {
133-
get {
134-
string(forKey: Key.studyProductSelection.rawValue)
135-
}
136-
set {
137-
set(newValue, forKey: Key.studyProductSelection.rawValue)
138-
}
139-
}
140-
141-
public var resetLoop: Bool {
142-
get {
143-
bool(forKey: Key.resetLoop.rawValue)
144-
}
145-
set {
146-
setValue(newValue, forKey: Key.resetLoop.rawValue)
147-
}
148-
}
149129

150130
public func removeLegacyLoopSettings() {
151131
removeObject(forKey: "com.loudnate.Naterade.BasalRateSchedule")

0 commit comments

Comments
 (0)