Skip to content

Commit

Permalink
LOOP-5122 onboarding updates (#719)
Browse files Browse the repository at this point in the history
* OnboardingManager is a PluginHost

* Update Common/Extensions/NSBundle.swift

Co-authored-by: Cameron Ingham <[email protected]>

---------

Co-authored-by: Cameron Ingham <[email protected]>
  • Loading branch information
ps2 and Camji55 authored Oct 25, 2024
1 parent fb2ba32 commit 3fe998b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
22 changes: 22 additions & 0 deletions Common/Extensions/NSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,27 @@ extension Bundle {
}
return .days(localCacheDurationDays)
}

var hostIdentifier: String {
var identifier = bundleIdentifier ?? "com.loopkit.Loop"
let components = identifier.components(separatedBy: ".")
// DIY Loop has bundle identifiers like com.UY653SP37Q.loopkit.Loop
if components[2] == "loopkit" && components[3] == "Loop" {
identifier = "com.loopkit.Loop"
}
return identifier
}

var hostVersion: String {
var semanticVersion = shortVersionString

while semanticVersion.split(separator: ".").count < 3 {
semanticVersion += ".0"
}

semanticVersion += "+\(Bundle.main.version)"

return semanticVersion
}
}

30 changes: 13 additions & 17 deletions Loop/Managers/OnboardingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,6 @@ extension OnboardingManager: ServiceProvider {
var activeServices: [Service] { servicesManager.activeServices }

var availableServices: [ServiceDescriptor] { servicesManager.availableServices }

func onboardService(withIdentifier identifier: String) -> Swift.Result<OnboardingResult<ServiceViewController, Service>, Error> {
guard let service = activeServices.first(where: { $0.pluginIdentifier == identifier }) else {
return servicesManager.setupService(withIdentifier: identifier)
}

if service.isOnboarded {
return .success(.createdAndOnboarded(service))
}

guard let serviceUI = service as? ServiceUI else {
return .failure(OnboardingError.invalidState)
}

return .success(.userInteractionRequired(serviceUI.settingsViewController(colorPalette: .default)))
}
}

// MARK: - TherapySettingsProvider
Expand All @@ -455,10 +439,22 @@ extension OnboardingManager: TherapySettingsProvider {
}
}

// MARK: - PluginHost

extension OnboardingManager: PluginHost {
nonisolated var hostIdentifier: String {
return Bundle.main.hostIdentifier
}

nonisolated var hostVersion: String {
return Bundle.main.hostVersion
}
}

// MARK: - OnboardingProvider

extension OnboardingManager: OnboardingProvider {
var allowDebugFeatures: Bool { FeatureFlags.allowDebugFeatures } // NOTE: DEBUG FEATURES - DEBUG AND TEST ONLY
nonisolated var allowDebugFeatures: Bool { FeatureFlags.allowDebugFeatures } // NOTE: DEBUG FEATURES - DEBUG AND TEST ONLY
}

// MARK: - SupportProvider
Expand Down
31 changes: 10 additions & 21 deletions Loop/Managers/ServicesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,31 +259,20 @@ extension ServicesManager: StatefulPluggableDelegate {
}
}

// MARK: - ServiceDelegate

extension ServicesManager: ServiceDelegate {
var hostIdentifier: String {
var identifier = Bundle.main.bundleIdentifier ?? "com.loopkit.Loop"
let components = identifier.components(separatedBy: ".")
// DIY Loop has bundle identifiers like com.UY653SP37Q.loopkit.Loop
if components[2] == "loopkit" && components[3] == "Loop" {
identifier = "com.loopkit.Looo"
}
return identifier
// MARK: - PluginHost
extension ServicesManager: PluginHost {
nonisolated var hostIdentifier: String {
return Bundle.main.hostIdentifier
}

var hostVersion: String {
var semanticVersion = Bundle.main.shortVersionString

while semanticVersion.split(separator: ".").count < 3 {
semanticVersion += ".0"
}
nonisolated var hostVersion: String {
return Bundle.main.hostVersion
}
}

semanticVersion += "+\(Bundle.main.version)"
// MARK: - ServiceDelegate

return semanticVersion
}

extension ServicesManager: ServiceDelegate {
func enactRemoteOverride(name: String, durationTime: TimeInterval?, remoteAddress: String) async throws {

var duration: TemporaryScheduleOverride.Duration? = nil
Expand Down

0 comments on commit 3fe998b

Please sign in to comment.