diff options
| author | Christian Cleberg <[email protected]> | 2026-04-11 19:47:40 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-11 19:47:40 -0500 |
| commit | 61164b6dd8343c8699d091dd5fccc55beb0b90b9 (patch) | |
| tree | 0a2befeb986966d42062802e2a29d795be907fee /Hutch/App/AppConfiguration.swift | |
| parent | 27bfcbbed6acde158ec40c5bb46e45e76c81a319 (diff) | |
| download | hutch-2.11.0.tar.gz hutch-2.11.0.tar.bz2 hutch-2.11.0.zip | |
feat: add contribution calendar to user profilesv2.11.0
Add a trailing 365-day contribution heatmap to user profile views,
backed by HutchStatsService. Includes calendar model, view model,
SwiftUI calendar view, app configuration, and unit tests.
Diffstat (limited to 'Hutch/App/AppConfiguration.swift')
| -rw-r--r-- | Hutch/App/AppConfiguration.swift | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Hutch/App/AppConfiguration.swift b/Hutch/App/AppConfiguration.swift new file mode 100644 index 0000000..7824371 --- /dev/null +++ b/Hutch/App/AppConfiguration.swift @@ -0,0 +1,42 @@ +import Foundation + +struct AppConfiguration: Sendable { + static let defaultHutchStatsBaseURL = URL(string: "https://hutch-stats.zerolabs.sh")! + static let hutchStatsBaseURLEnvironmentKey = "HUTCH_STATS_BASE_URL" + + let hutchStatsBaseURL: URL + + init( + userDefaults: UserDefaults = .standard, + processInfo: ProcessInfo = .processInfo, + environment: [String: String]? = nil + ) { + let resolvedEnvironment = environment ?? processInfo.environment + + if + let rawValue = resolvedEnvironment[Self.hutchStatsBaseURLEnvironmentKey], + let url = Self.normalizedURL(from: rawValue) + { + self.hutchStatsBaseURL = url + } else if + let rawValue = userDefaults.string(forKey: AppStorageKeys.hutchStatsBaseURL), + let url = Self.normalizedURL(from: rawValue) + { + self.hutchStatsBaseURL = url + } else { + self.hutchStatsBaseURL = Self.defaultHutchStatsBaseURL + } + } + + private static func normalizedURL(from rawValue: String) -> URL? { + guard var components = URLComponents(string: rawValue.trimmingCharacters(in: .whitespacesAndNewlines)) else { + return nil + } + + if components.path.isEmpty { + components.path = "/" + } + + return components.url + } +} |
