Skip to content

Commit

Permalink
[COASTAL-1291] plugin identifier is no longer class property (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhamming authored Sep 25, 2023
1 parent 49b329e commit 26e1560
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Common/Models/PumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import MockKit
import MockKitUI

let staticPumpManagersByIdentifier: [String: PumpManagerUI.Type] = [
MockPumpManager.pluginIdentifier : MockPumpManager.self
MockPumpManager.managerIdentifier : MockPumpManager.self
]

var availableStaticPumpManagers: [PumpManagerDescriptor] {
if FeatureFlags.allowSimulators {
return [
PumpManagerDescriptor(identifier: MockPumpManager.pluginIdentifier, localizedTitle: MockPumpManager.localizedTitle)
PumpManagerDescriptor(identifier: MockPumpManager.managerIdentifier, localizedTitle: MockPumpManager.localizedTitle)
]
} else {
return []
Expand Down
4 changes: 2 additions & 2 deletions Loop/Managers/CGMManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import LoopKitUI
import MockKit

let staticCGMManagersByIdentifier: [String: CGMManager.Type] = [
MockCGMManager.pluginIdentifier: MockCGMManager.self
MockCGMManager.managerIdentifier: MockCGMManager.self
]

var availableStaticCGMManagers: [CGMManagerDescriptor] {
if FeatureFlags.allowSimulators {
return [
CGMManagerDescriptor(identifier: MockCGMManager.pluginIdentifier, localizedTitle: MockCGMManager.localizedTitle)
CGMManagerDescriptor(identifier: MockCGMManager.managerIdentifier, localizedTitle: MockCGMManager.localizedTitle)
]
} else {
return []
Expand Down
23 changes: 6 additions & 17 deletions Loop/Managers/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ import MockKit

let staticServices: [Service.Type] = [MockService.self]

let staticServicesByIdentifier: [String: Service.Type] = staticServices.reduce(into: [:]) { (map, Type) in
map[Type.pluginIdentifier] = Type
}
let staticServicesByIdentifier: [String: Service.Type] = [
MockService.serviceIdentifier: MockService.self
]

let availableStaticServices = staticServices.map { (Type) -> ServiceDescriptor in
return ServiceDescriptor(identifier: Type.pluginIdentifier, localizedTitle: Type.localizedTitle)
}

func ServiceFromRawValue(_ rawValue: [String: Any]) -> Service? {
guard let serviceIdentifier = rawValue["statefulPluginIdentifier"] as? String,
let rawState = rawValue["state"] as? Service.RawStateValue,
let ServiceType = staticServicesByIdentifier[serviceIdentifier]
else {
return nil
}

return ServiceType.init(rawState: rawState)
}
let availableStaticServices: [ServiceDescriptor] = [
ServiceDescriptor(identifier: MockService.serviceIdentifier, localizedTitle: MockService.localizedTitle)
]
14 changes: 13 additions & 1 deletion Loop/Managers/ServicesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ServicesManager {
}

private func serviceTypeFromRawValue(_ rawValue: Service.RawStateValue) -> Service.Type? {
guard let identifier = rawValue["statefulPluginIdentifier"] as? String else {
guard let identifier = rawValue["serviceIdentifier"] as? String else {
return nil
}

Expand Down Expand Up @@ -400,3 +400,15 @@ extension ServicesManager: ServiceOnboardingDelegate {
extension ServicesManager {
var availableSupports: [SupportUI] { activeServices.compactMap { $0 as? SupportUI } }
}

// Service extension for rawValue
extension Service {
typealias RawValue = [String: Any]

var rawValue: RawValue {
return [
"serviceIdentifier": pluginIdentifier,
"state": rawState
]
}
}
2 changes: 1 addition & 1 deletion Loop/Managers/StatefulPluginManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class StatefulPluginManager: StatefulPluggableProvider {
}

private func statefulPluginTypeFromRawValue(_ rawValue: StatefulPluggable.RawStateValue) -> StatefulPluggable.Type? {
guard let identifier = rawValue["statefulPluginIdentifier"] as? String else {
guard let identifier = rawValue["serviceIdentifier"] as? String else {
return nil
}

Expand Down
15 changes: 3 additions & 12 deletions Loop/Managers/SupportManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,17 @@ public final class SupportManager {
private let alertIssuer: AlertIssuer
private let deviceSupportDelegate: DeviceSupportDelegate
private let pluginManager: PluginManager
private let staticSupportTypes: [SupportUI.Type]
private let staticSupportTypesByIdentifier: [String: SupportUI.Type]

lazy private var cancellables = Set<AnyCancellable>()

init(pluginManager: PluginManager,
deviceSupportDelegate: DeviceSupportDelegate,
servicesManager: ServicesManager? = nil,
staticSupportTypes: [SupportUI.Type]? = nil,
alertIssuer: AlertIssuer) {

self.alertIssuer = alertIssuer
self.deviceSupportDelegate = deviceSupportDelegate
self.pluginManager = pluginManager
self.staticSupportTypes = []
staticSupportTypesByIdentifier = self.staticSupportTypes.reduce(into: [:]) { (map, type) in
map[type.pluginIdentifier] = type
}

restoreState()

Expand Down Expand Up @@ -86,8 +79,7 @@ public final class SupportManager {
let availablePluginSupports = [SupportUI]()
let availableDeviceSupports = deviceSupportDelegate.availableSupports
let availableServiceSupports = servicesManager?.availableSupports ?? [SupportUI]()
let staticSupports = self.staticSupportTypes.map { $0.init(rawState: [:]) }.compactMap { $0 }
let allSupports = availablePluginSupports + availableDeviceSupports + availableServiceSupports + staticSupports
let allSupports = availablePluginSupports + availableDeviceSupports + availableServiceSupports
allSupports.forEach {
addSupport($0)
}
Expand Down Expand Up @@ -283,7 +275,7 @@ extension SupportManager {

private func supportTypeFromRawValue(_ rawValue: [String: Any]) -> SupportUI.Type? {
guard let supportIdentifier = rawValue["supportIdentifier"] as? String,
let supportType = pluginManager.getSupportUITypeByIdentifier(supportIdentifier) ?? staticSupportTypesByIdentifier[supportIdentifier]
let supportType = pluginManager.getSupportUITypeByIdentifier(supportIdentifier)
else {
return nil
}
Expand Down Expand Up @@ -331,11 +323,10 @@ fileprivate extension UserDefaults {
extension SupportUI {
var rawValue: RawStateValue {
return [
"supportIdentifier": Self.pluginIdentifier,
"supportIdentifier": pluginIdentifier,
"state": rawState
]
}

}

extension Bundle {
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/TestingScenariosManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension TestingScenariosManagerRequirements {
load(scenario) { error in
if error == nil {
self.activeScenarioURL = url
self.log.debug("@{public}%", successLogMessage)
self.log.debug("%{public}@", successLogMessage)
}
completion(error)
}
Expand Down
4 changes: 2 additions & 2 deletions Loop/View Models/ServicesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ServicesViewModel: ObservableObject {
extension ServicesViewModel {
fileprivate class FakeService1: Service {
static var localizedTitle: String = "Service 1"
static var pluginIdentifier: String = "FakeService1"
var pluginIdentifier: String = "FakeService1"
var stateDelegate: StatefulPluggableDelegate?
var serviceDelegate: ServiceDelegate?
var rawState: RawStateValue = [:]
Expand All @@ -65,7 +65,7 @@ extension ServicesViewModel {
}
fileprivate class FakeService2: Service {
static var localizedTitle: String = "Service 2"
static var pluginIdentifier: String = "FakeService2"
var pluginIdentifier: String = "FakeService2"
var stateDelegate: StatefulPluggableDelegate?
var serviceDelegate: ServiceDelegate?
var rawState: RawStateValue = [:]
Expand Down
2 changes: 1 addition & 1 deletion LoopTests/Managers/DoseEnactorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MockPumpManager: PumpManager {
.minutes(units / deliveryUnitsPerMinute)
}

static var pluginIdentifier: String = "MockPumpManager"
var pluginIdentifier: String = "MockPumpManager"

var localizedTitle: String = "MockPumpManager"

Expand Down
6 changes: 3 additions & 3 deletions LoopTests/Managers/SupportManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SupportManagerTests: XCTestCase {
weak var delegate: SupportUIDelegate?
}
class MockSupport: Mixin, SupportUI {
static var pluginIdentifier: String { "SupportManagerTestsMockSupport" }
var pluginIdentifier: String { "SupportManagerTestsMockSupport" }
override init() { super.init() }
required init?(rawState: RawStateValue) { super.init() }
var rawState: RawStateValue = [:]
Expand All @@ -46,7 +46,7 @@ class SupportManagerTests: XCTestCase {
}

class AnotherMockSupport: Mixin, SupportUI {
static var pluginIdentifier: String { "SupportManagerTestsAnotherMockSupport" }
var pluginIdentifier: String { "SupportManagerTestsAnotherMockSupport" }
override init() { super.init() }
required init?(rawState: RawStateValue) { super.init() }
var rawState: RawStateValue = [:]
Expand Down Expand Up @@ -86,7 +86,7 @@ class SupportManagerTests: XCTestCase {

override func setUp() {
mockAlertIssuer = MockAlertIssuer()
supportManager = SupportManager(pluginManager: pluginManager, deviceSupportDelegate: mocKDeviceSupportDelegate, staticSupportTypes: [], alertIssuer: mockAlertIssuer)
supportManager = SupportManager(pluginManager: pluginManager, deviceSupportDelegate: mocKDeviceSupportDelegate, alertIssuer: mockAlertIssuer)
mockSupport = SupportManagerTests.MockSupport()
supportManager.addSupport(mockSupport)
}
Expand Down

0 comments on commit 26e1560

Please sign in to comment.