From 4689b5325f9a1c9afbc0d1995f95d16eca4f6bd4 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 4 Jan 2024 10:59:36 +0800 Subject: [PATCH] Ensure app environment is configured This can happen if a user sets a custom self hosting environment, then deletes and re-installs the app. --- .../Sources/App/Views/RootView/RootView.swift | 2 +- apple/OmnivoreKit/Sources/Models/AppEnvironment.swift | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift index 62a77584a..7260e6bab 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootView.swift @@ -49,7 +49,7 @@ struct InnerRootView: View { @ObservedObject var viewModel: RootViewModel @ViewBuilder private var innerBody: some View { - if authenticator.isLoggedIn { + if authenticator.isLoggedIn, dataService.appEnvironment.environmentConfigured { PrimaryContentView() .task { try? await dataService.syncOfflineItemsWithServerIfNeeded() diff --git a/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift b/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift index 854059f41..b57f6bf81 100644 --- a/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift +++ b/apple/OmnivoreKit/Sources/Models/AppEnvironment.swift @@ -54,6 +54,17 @@ public extension AppEnvironment { ) } + var environmentConfigured: Bool { + if self == .custom { + if let str = UserDefaults.standard.string(forKey: AppEnvironmentUserDefaultKey.webAppBaseURL.rawValue), let url = URL(string: str) { + return true + } else { + return false + } + } + return true + } + var graphqlPath: String { "\(serverBaseURL.absoluteString)/api/graphql" }