Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Apr 19, 2024
1 parent 57e74cf commit b6e5a89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/HomeFeature/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public struct Home {
public var weekInReview: FetchWeekInReviewResponse?
@Shared(.installationTime) var installationTime = Date().timeIntervalSince1970
@Shared(.build) var build = Build()
@SharedReader(.serverConfig) var serverConfig = ServerConfig()
//@SharedReader(.serverConfig) var serverConfig = ServerConfig()
@ObservationStateIgnored
@ServerConfig_ var serverConfig

public var hasChangelog: Bool {
self.serverConfig.newestBuild > self.build.number
Expand Down Expand Up @@ -114,7 +116,7 @@ public struct Home {
@Dependency(\.mainRunLoop.now.date) var now
@Dependency(\.audioPlayer.play) var playSound
@Dependency(\.timeZone) var timeZone
@SharedReader(.serverConfig) var serverConfig = ServerConfig()
//@SharedReader(.serverConfig) var serverConfig = ServerConfig()

public init() {}

Expand Down Expand Up @@ -294,7 +296,8 @@ public struct Home {
)
await send(.authenticationResponse(currentPlayerEnvelope))

async let serverConfigResponse: Void = $serverConfig.persistence.reload()
@ServerConfig_ var serverConfig
async let serverConfigResponse: Void = $serverConfig.reload()

async let dailyChallengeResponse: Void = send(
.dailyChallengeResponse(
Expand Down Expand Up @@ -324,7 +327,7 @@ public struct Home {
}
)
)
_ = await (
_ = try await (
serverConfigResponse, dailyChallengeResponse, weekInReviewResponse, activeMatchesResponse
)
} catch {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import Dependencies
import Foundation
@_exported import ServerConfig

@propertyWrapper
public struct ServerConfig_: Equatable {
@Shared(.fileStorage(.serverConfig)) var config = ServerConfig()

public init(config: ServerConfig = ServerConfig()) {
self.config = config
}

public var projectedValue: Self { self }

public var wrappedValue: ServerConfig {
get { config }
nonmutating set { config = newValue }
}

public func reload() async throws {
@Dependency(\.apiClient) var apiClient
@Shared(.build) var build = Build()
self.config = try await apiClient
.apiRequest(route: .config(build: build.number), as: ServerConfig.self)
}
}

extension PersistenceReaderKey where Self == ServerConfigKey {
public static var serverConfig: Self {
ServerConfigKey()
Expand Down

0 comments on commit b6e5a89

Please sign in to comment.