Skip to content

Commit

Permalink
Merge pull request #12 from LoopKit/tidepool-sync
Browse files Browse the repository at this point in the history
Tidepool Sync
  • Loading branch information
ps2 authored May 6, 2023
2 parents 0eef224 + 810a138 commit 3cad23b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
24 changes: 10 additions & 14 deletions TidepoolService.xcodeproj/xcshareddata/xcschemes/Shared.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -41,6 +41,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9DAACFE22E7987800E76C9F"
BuildableName = "TidepoolServiceKit.framework"
BlueprintName = "TidepoolServiceKit"
ReferencedContainer = "container:TidepoolService.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -63,17 +72,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A9DAACFE22E7987800E76C9F"
BuildableName = "TidepoolServiceKit.framework"
BlueprintName = "TidepoolServiceKit"
ReferencedContainer = "container:TidepoolService.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -94,8 +92,6 @@
ReferencedContainer = "container:TidepoolService.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
17 changes: 17 additions & 0 deletions TidepoolServiceKit/Extensions/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ extension Bundle {

private func string(forInfoDictionaryKey key: String) -> String? { object(forInfoDictionaryKey: key) as? String }
}

public extension Bundle {

// TidepoolServiceClientId should be set in the hosting app's info plist
// TidepoolServiceRedirectURI generally does not need to be set, and the default can be used.

var tidepoolServiceClientId: String {
return object(forInfoDictionaryKey: "TidepoolServiceClientId") as? String ?? "client-id-not-in-info-plist"
}

var tidepoolServiceRedirectURL: URL {
if let str = object(forInfoDictionaryKey: "TidepoolServiceRedirectURL") as? String, let url = URL(string: str) {
return url
}
return URL(string: "org.tidepool.tidepoolkit.auth://redirect")!
}
}
8 changes: 0 additions & 8 deletions TidepoolServiceKit/IdentifiableDatum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ extension IdentifiableDatum {
return "\(userId):\(resolvedIdentifier)".md5hash!
}

// var datumOrigin: TOrigin {
// return datumOrigin(for: resolvedIdentifier)
// }
//
// func datumOrigin<T: TypedDatum>(for type: T.Type) -> TOrigin {
// return datumOrigin(for: resolvedIdentifier(for: type))
// }

func datumOrigin(for resolvedIdentifier: String, hostIdentifier: String, hostVersion: String) -> TOrigin {
return TOrigin(id: resolvedIdentifier,
name: hostIdentifier,
Expand Down
8 changes: 0 additions & 8 deletions TidepoolServiceKit/IdentifiableHKDatum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ extension IdentifiableHKDatum {
return "\(userId):\(resolvedIdentifier)".md5hash
}

// var datumOrigin: TOrigin? {
// return datumOrigin(for: resolvedIdentifier)
// }
//
// func datumOrigin<T: TypedDatum>(for type: T.Type) -> TOrigin? {
// return datumOrigin(for: resolvedIdentifier(for: type))
// }

func datumOrigin(for resolvedIdentifier: String?, hostIdentifier: String, hostVersion: String) -> TOrigin? {
guard let resolvedIdentifier = resolvedIdentifier else {
return nil
Expand Down
11 changes: 2 additions & 9 deletions TidepoolServiceKit/TidepoolService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {

public lazy var sessionStorage: SessionStorage = KeychainManager()

public let tapi: TAPI
public let tapi: TAPI = TAPI(clientId: Bundle.main.tidepoolServiceClientId, redirectURL: Bundle.main.tidepoolServiceRedirectURL)

public private (set) var error: Error?

Expand All @@ -67,17 +67,11 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {
private let log = OSLog(category: "TidepoolService")
private let tidepoolKitLog = OSLog(category: "TidepoolKit")

public init(hostIdentifier: String, hostVersion: String, automaticallyFetchEnvironments: Bool = true) {
public init(hostIdentifier: String, hostVersion: String) {
self.id = UUID().uuidString
self.tapi = TAPI(clientId: "diy-loop", redirectURL: URL(string: "org.loopkit.Loop://tidepool_service_redirect")!)
self.hostIdentifier = hostIdentifier
self.hostVersion = hostVersion

// TODO: REMOVE BEFORE SHIPPING - https://tidepool.atlassian.net/browse/LOOP-4060
if tapi.defaultEnvironment == nil {
tapi.defaultEnvironment = TEnvironment(host: "app.tidepool.org", port: 443)
}

Task {
await tapi.setLogging(self)
await tapi.addObserver(self)
Expand All @@ -86,7 +80,6 @@ public final class TidepoolService: Service, TAPIObserver, ObservableObject {

public init?(rawState: RawStateValue) {
self.isOnboarded = true // Assume when restoring from state, that we're onboarded
self.tapi = TAPI(clientId: "diy-loop", redirectURL: URL(string: "org.loopkit.Loop://tidepool_service_redirect")!)
guard let id = rawState["id"] as? String else {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion TidepoolServiceKitTests/TidepoolServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TidepoolServiceTests: XCTestCase {
override func setUp() {
super.setUp()

tidepoolService = TidepoolService(hostIdentifier: "Loop", hostVersion: "1.2.3", automaticallyFetchEnvironments: false)
tidepoolService = TidepoolService(hostIdentifier: "Loop", hostVersion: "1.2.3")
userID = "1234567890"
}

Expand Down
2 changes: 0 additions & 2 deletions TidepoolServiceKitUI/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SwiftUI
import TidepoolKit
import TidepoolServiceKit

@MainActor
public struct SettingsView: View {

@State private var isEnvironmentActionSheetPresented = false
Expand Down Expand Up @@ -190,7 +189,6 @@ public struct SettingsView: View {
do {
try await login?(selectedEnvironment)
isLoggingIn = false
//dismiss?()
} catch {
self.error = error
isLoggingIn = false
Expand Down
1 change: 0 additions & 1 deletion TidepoolServiceKitUI/TidepoolService+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extension TidepoolService: ServiceUI {
try await service.tapi.login(environment: environment, presenting: navController)
try await service.completeCreate()
await navController.notifyServiceCreatedAndOnboarded(service)
//await navController.notifyComplete()
}, dismiss: {
Task {
await navController.notifyComplete()
Expand Down

0 comments on commit 3cad23b

Please sign in to comment.