Skip to content

Commit

Permalink
[PAL-818] plugin dependency (#112)
Browse files Browse the repository at this point in the history
* do not allow deleting of the service when it is a dependency

* pass allowDebugFeatures to service
  • Loading branch information
nhamming authored Oct 30, 2024
1 parent da6df5b commit 342c8e9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
4 changes: 4 additions & 0 deletions TidepoolService.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
A9E8C611272C76A500016E2E /* TimeInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E8C610272C76A500016E2E /* TimeInterval.swift */; };
A9F9F317271A046E00D19374 /* StoredCarbEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9F9F316271A046E00D19374 /* StoredCarbEntry.swift */; };
A9F9F319271A05B100D19374 /* IdentifiableHKDatum.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9F9F318271A05B100D19374 /* IdentifiableHKDatum.swift */; };
B40B20CC2CD2AC600027BF35 /* EnvironmentValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = B40B20CB2CD2AC600027BF35 /* EnvironmentValues.swift */; };
C110888F2A39149100BA4898 /* BuildDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = C110888E2A39149100BA4898 /* BuildDetails.swift */; };
C124239D2A58771A00EAC89E /* TidepoolKit in Frameworks */ = {isa = PBXBuildFile; productRef = C124239C2A58771A00EAC89E /* TidepoolKit */; };
C12E4BBA288F2215009C98A2 /* TidepoolServiceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9DAACFF22E7987800E76C9F /* TidepoolServiceKit.framework */; platformFilter = ios; };
Expand Down Expand Up @@ -224,6 +225,7 @@
A9E8C610272C76A500016E2E /* TimeInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeInterval.swift; sourceTree = "<group>"; };
A9F9F316271A046E00D19374 /* StoredCarbEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredCarbEntry.swift; sourceTree = "<group>"; };
A9F9F318271A05B100D19374 /* IdentifiableHKDatum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiableHKDatum.swift; sourceTree = "<group>"; };
B40B20CB2CD2AC600027BF35 /* EnvironmentValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentValues.swift; sourceTree = "<group>"; };
C110888E2A39149100BA4898 /* BuildDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildDetails.swift; sourceTree = "<group>"; };
C12522E1298309B5006EA1CD /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = "<group>"; };
C1317D4129830A0800625B94 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -482,6 +484,7 @@
C1D0B62A29848BD90098D215 /* Extensions */ = {
isa = PBXGroup;
children = (
B40B20CB2CD2AC600027BF35 /* EnvironmentValues.swift */,
C1D0B62B29848BEB0098D215 /* Image.swift */,
C1C9414529F0CB21008D3E05 /* UIImage.swift */,
);
Expand Down Expand Up @@ -806,6 +809,7 @@
A97651762421AA11002EB5D4 /* OSLog.swift in Sources */,
A9DAAD3422E7CA1A00E76C9F /* LocalizedString.swift in Sources */,
A9DAAD3922E7DEE000E76C9F /* TidepoolService+UI.swift in Sources */,
B40B20CC2CD2AC600027BF35 /* EnvironmentValues.swift in Sources */,
A9DAAD6F22E7EA9700E76C9F /* NibLoadable.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
8 changes: 7 additions & 1 deletion TidepoolServiceKit/TidepoolService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {

public let tapi: TAPI = TAPI(clientId: BuildDetails.default.tidepoolServiceClientId, redirectURL: BuildDetails.default.tidepoolServiceRedirectURL)

public private (set) var error: Error?
public private(set) var error: Error?

private let id: String

Expand All @@ -77,6 +77,8 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {
private let tidepoolKitLog = OSLog(category: "TidepoolKit")

private var deviceLogUploader: DeviceLogUploader?

public var isDependency: Bool = false

private func setDeviceLogUploaderDelegate() async {
await deviceLogUploader?.setDelegate(remoteDataServiceDelegate)
Expand Down Expand Up @@ -137,6 +139,10 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {
}

public var isOnboarded = false // No distinction between created and onboarded

public func markAsDepedency(_ isDependency: Bool) {
self.isDependency = isDependency
}

@Published public var session: TSession?

Expand Down
20 changes: 20 additions & 0 deletions TidepoolServiceKitUI/Extensions/EnvironmentValues.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// EnvironmentValues.swift
// TidepoolService
//
// Created by Nathaniel Hamming on 2024-10-30.
// Copyright © 2024 LoopKit Authors. All rights reserved.
//

import SwiftUI

private struct AllowDebugFeaturesKey: EnvironmentKey {
static let defaultValue: Bool = false
}

public extension EnvironmentValues {
var allowDebugFeatures: Bool {
get { self[AllowDebugFeaturesKey.self] }
set { self[AllowDebugFeaturesKey.self] = newValue }
}
}
16 changes: 11 additions & 5 deletions TidepoolServiceKitUI/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import TidepoolKit
import TidepoolServiceKit

public struct SettingsView: View {

@Environment(\.allowDebugFeatures) var allowDebugFeatures

@State private var isEnvironmentActionSheetPresented = false
@State private var showingDeletionConfirmation = false

Expand All @@ -28,7 +29,12 @@ public struct SettingsView: View {
private let onboarding: Bool

var isLoggedIn: Bool {
return service.session != nil
service.session != nil
}

var canDeleteService: Bool {
guard !allowDebugFeatures else { return true }
return !service.isDependency
}

public init(service: TidepoolService, login: ((TEnvironment) async throws -> Void)?, dismiss: (() -> Void)?, onboarding: Bool)
Expand Down Expand Up @@ -97,11 +103,11 @@ public struct SettingsView: View {
.padding()
}
Spacer()
if isLoggedIn && !onboarding {
if isLoggedIn && !onboarding && canDeleteService {
deleteServiceButton
} else if isLoggedIn {
} else if isLoggedIn && onboarding {
continueButton
} else {
} else if !isLoggedIn {
loginButton
}
}
Expand Down
12 changes: 6 additions & 6 deletions TidepoolServiceKitUI/TidepoolService+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension TidepoolService: @retroactive ServiceUI {
UIImage(frameworkImage: "Tidepool Logo")
}

public static func setupViewController(pluginHost: PluginHost, onboarding: Bool) -> SetupUIResult<ServiceViewController, ServiceUI> {
public static func setupViewController(pluginHost: PluginHost, onboarding: Bool, allowDebugFeatures: Bool) -> SetupUIResult<ServiceViewController, ServiceUI> {

let navController = ServiceNavigationController()
navController.isNavigationBarHidden = true
Expand All @@ -58,7 +58,7 @@ extension TidepoolService: @retroactive ServiceUI {
Task {
await navController.notifyComplete()
}
}, onboarding: onboarding)
}, onboarding: onboarding).environment(\.allowDebugFeatures, allowDebugFeatures)

let hostingController = await UIHostingController(rootView: settingsView)
await navController.pushViewController(hostingController, animated: false)
Expand All @@ -67,11 +67,11 @@ extension TidepoolService: @retroactive ServiceUI {
return .userInteractionRequired(navController)
}

public static func setupViewController(colorPalette: LoopUIColorPalette, pluginHost: PluginHost) -> SetupUIResult<ServiceViewController, ServiceUI> {
return setupViewController(pluginHost: pluginHost, onboarding: false)
public static func setupViewController(colorPalette: LoopUIColorPalette, pluginHost: PluginHost, allowDebugFeatures: Bool) -> SetupUIResult<ServiceViewController, ServiceUI> {
return setupViewController(pluginHost: pluginHost, onboarding: false, allowDebugFeatures: allowDebugFeatures)
}

public func settingsViewController(colorPalette: LoopUIColorPalette) -> ServiceViewController {
public func settingsViewController(colorPalette: LoopUIColorPalette, allowDebugFeatures: Bool) -> ServiceViewController {

let navController = ServiceNavigationController()
navController.isNavigationBarHidden = true
Expand All @@ -92,7 +92,7 @@ extension TidepoolService: @retroactive ServiceUI {
Task {
await navController.notifyComplete()
}
}, onboarding: false)
}, onboarding: false).environment(\.allowDebugFeatures, allowDebugFeatures)

let hostingController = await UIHostingController(rootView: settingsView)
await navController.pushViewController(hostingController, animated: false)
Expand Down

0 comments on commit 342c8e9

Please sign in to comment.