Skip to content

Commit

Permalink
Add Simple macOS Support (#46)
Browse files Browse the repository at this point in the history
# Add Simple macOS Support

## ⚙️ Release Notes 
- Adds simple macOS support by checking for HealthKit availability.


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
PSchmiedmayer committed Mar 22, 2024
1 parent b1ed46c commit 897dc52
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 54 deletions.
14 changes: 7 additions & 7 deletions LLMonFHIR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1510;
LastUpgradeCheck = 1530;
TargetAttributes = {
653A254C283387FE005D4D48 = {
CreatedOnToolsVersion = 13.4;
Expand Down Expand Up @@ -688,11 +688,11 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
"SWIFT_ELicenseRef-LLMonFHIR_LOC_STRINGS" = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Test;
};
Expand Down Expand Up @@ -891,11 +891,11 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
"SWIFT_ELicenseRef-LLMonFHIR_LOC_STRINGS" = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand Down Expand Up @@ -940,11 +940,11 @@
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "LLM on FHIR";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
"SWIFT_ELicenseRef-LLMonFHIR_LOC_STRINGS" = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "492223cc8959b40571851f634503febc2f994cab9f439437a2002b77d2fda831",
"pins" : [
{
"identity" : "fhirmodels",
Expand All @@ -14,17 +15,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/HealthKitOnFHIR.git",
"state" : {
"revision" : "825e96007d83ed83f81ee49eb3ebab29d7b7ba2f",
"version" : "0.2.5"
"revision" : "00d64d38a8f0d826ee9e27b6f3ce32314a29fd3e",
"version" : "0.2.6"
}
},
{
"identity" : "llama.cpp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/llama.cpp",
"state" : {
"revision" : "b0611c7d3cb049822f9911878514e4706b80e2ac",
"version" : "0.1.8"
"revision" : "7bfd6d4b5bbc9fd47bd023bdbb35f96c827977f3",
"version" : "0.2.1"
}
},
{
Expand All @@ -36,31 +37,22 @@
"version" : "0.2.6"
}
},
{
"identity" : "semaphore",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/Semaphore.git",
"state" : {
"revision" : "f1c4a0acabeb591068dea6cffdd39660b86dec28",
"version" : "0.0.8"
}
},
{
"identity" : "spezi",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/Spezi",
"state" : {
"revision" : "0ced3efbc2af9513c07ac913ad762c773a00a6c8",
"version" : "1.2.1"
"revision" : "c43e4fa3d3938a847de2b677091a34ddaea5bc76",
"version" : "1.2.3"
}
},
{
"identity" : "spezichat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziChat",
"state" : {
"revision" : "eae5c15b211f18e09aa98de63ce119629320afeb",
"version" : "0.1.8"
"revision" : "2334583105224b0c04fc36989db82b000021d31d",
"version" : "0.1.9"
}
},
{
Expand All @@ -77,62 +69,62 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFoundation",
"state" : {
"revision" : "0346857e2f1d6fd4b1d950d271be6c82df97107f",
"version" : "1.0.2"
"revision" : "01af5b91a54f30ddd121258e81aff2ddc2a99ff9",
"version" : "1.0.4"
}
},
{
"identity" : "spezihealthkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziHealthKit.git",
"state" : {
"revision" : "b40695ffa4d1c9d58c5a0ee277640c2343fb5516",
"version" : "0.5.1"
"revision" : "1e9cb5a6036ac7f4ff37ea1c3ed4898103339ad1",
"version" : "0.5.3"
}
},
{
"identity" : "spezillm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziLLM",
"state" : {
"revision" : "6892c5dfe258371b6f3287f02b8fec57a611ba70",
"version" : "0.7.0"
"revision" : "dc37b91ed55c9d50eaf58e645d454cb62e3681d1",
"version" : "0.7.2"
}
},
{
"identity" : "spezionboarding",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziOnboarding.git",
"state" : {
"revision" : "91463ae190611bd14ef52b0657e8db3bf53c9ae8",
"version" : "1.1.0"
"revision" : "4971a82e94996ce0c3d8ecf64fdeec874a1f20d6",
"version" : "1.1.1"
}
},
{
"identity" : "spezispeech",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziSpeech",
"state" : {
"revision" : "a1e1d021d8f605b5e6b23aee773115d7125a57e3",
"version" : "1.0.0"
"revision" : "60b8cdbf6f3d58b0d75eadf30db50f88848069aa",
"version" : "1.0.1"
}
},
{
"identity" : "spezistorage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziStorage",
"location" : "https://github.com/StanfordSpezi/SpeziStorage.git",
"state" : {
"revision" : "eaed2220375c35400aa69d1f96a8d32b7e66b1c7",
"version" : "1.0.0"
"revision" : "b958df9b31f24800388a7bfc28f457ce7b82556c",
"version" : "1.0.2"
}
},
{
"identity" : "speziviews",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziViews.git",
"state" : {
"revision" : "d49f716e4a4d634604bb0dcd6d53df679b6c1358",
"version" : "1.3.0"
"revision" : "4d2a724d97c8f19ac7de7aa2c046b1cb3ef7b279",
"version" : "1.3.1"
}
},
{
Expand Down Expand Up @@ -172,5 +164,5 @@
}
}
],
"version" : 2
"version" : 3
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions LLMonFHIR/Onboarding/HealthKitPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI


struct HealthKitPermissions: View {
@Environment(HealthKit.self) var healthKitDataSource
@Environment(HealthKit.self) var healthKitDataSource: HealthKit?
@Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath
@State var healthKitProcessing = false

Expand Down Expand Up @@ -45,7 +45,7 @@ struct HealthKitPermissions: View {
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
try await _Concurrency.Task.sleep(for: .seconds(5))
} else {
try await healthKitDataSource.askForAuthorization()
try await healthKitDataSource?.askForAuthorization()
}
} catch {
print("Could not request HealthKit permissions.")
Expand Down
15 changes: 14 additions & 1 deletion LLMonFHIR/Onboarding/OnboardingFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@
// SPDX-License-Identifier: MIT
//

import SpeziHealthKit
import SpeziLLMOpenAI
import SpeziOnboarding
import SwiftUI


/// Displays an multi-step onboarding flow for the Spezi LLMonFHIR.
struct OnboardingFlow: View {
@Environment(HealthKit.self) private var healthKit: HealthKit?
@AppStorage(StorageKeys.onboardingFlowComplete) var completedOnboardingFlow = false

private var healthKitAuthorization: Bool {
// As HealthKit not available in preview simulator
if ProcessInfo.processInfo.isPreviewSimulator {
return false
}

return healthKit?.authorized ?? false
}


var body: some View {
OnboardingStack(onboardingFlowComplete: $completedOnboardingFlow) {
Welcome()
Disclaimer()
OpenAIAPIKey()
HealthKitPermissions()
if HKHealthStore.isHealthDataAvailable() && !healthKitAuthorization {
HealthKitPermissions()
}
}
.navigationBarTitleDisplayMode(.inline)
.interactiveDismissDisabled(!completedOnboardingFlow)
Expand Down
18 changes: 10 additions & 8 deletions LLMonFHIR/Settings/ResourceSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

import HealthKit
import ModelsR4
import SpeziFHIR
import SpeziFHIRMockPatients
Expand All @@ -19,10 +20,11 @@ struct ResourceSelection: View {
@State private var bundles: [ModelsR4.Bundle] = []
@State private var showBundleSelection = false

@MainActor var useHealthKitResources: Binding<Bool> {

@MainActor private var useHealthKitResources: Binding<Bool> {
Binding(
get: {
if FeatureFlags.mockPatients {
if !HKHealthStore.isHealthDataAvailable() {
showBundleSelection = true
return false
}
Expand All @@ -38,9 +40,11 @@ struct ResourceSelection: View {

var body: some View {
Form {
Section {
Toggle(isOn: useHealthKitResources) {
Text("Use HealthKit Resources")
if HKHealthStore.isHealthDataAvailable() {
Section {
Toggle(isOn: useHealthKitResources) {
Text("Use HealthKit Resources")
}
}
.onChange(of: useHealthKitResources.wrappedValue, initial: true) {
if useHealthKitResources.wrappedValue {
Expand Down Expand Up @@ -73,11 +77,9 @@ struct ResourceSelection: View {
}
}
.task {
showBundleSelection = !standard.useHealthKitResources || !HKHealthStore.isHealthDataAvailable()
self.bundles = await mockPatients
}
.onAppear {
showBundleSelection = !standard.useHealthKitResources
}
.navigationTitle(Text("Resource Settings"))
}

Expand Down
2 changes: 0 additions & 2 deletions LLMonFHIR/SharedContext/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ enum FeatureFlags {
static let showOnboarding = CommandLine.arguments.contains("--showOnboarding")
/// Sets the application in test mode
static let testMode = CommandLine.arguments.contains("--testMode")
/// Use mock patients
static let mockPatients = CommandLine.arguments.contains("--mockPatients")
}

0 comments on commit 897dc52

Please sign in to comment.