diff --git a/Package.swift b/Package.swift index a7441d35..67c3a8b1 100644 --- a/Package.swift +++ b/Package.swift @@ -112,10 +112,7 @@ var package = Package( ), .target( name: "ServerConfig", - dependencies: [ - "ApiClient", - "Build", - ] + dependencies: ["Build"] ), .target( name: "ServerRouter", diff --git a/Sources/ActiveGamesFeature/ActiveGamesView.swift b/Sources/ActiveGamesFeature/ActiveGamesView.swift index 60626e02..d2c8bba8 100644 --- a/Sources/ActiveGamesFeature/ActiveGamesView.swift +++ b/Sources/ActiveGamesFeature/ActiveGamesView.swift @@ -340,8 +340,7 @@ private let relativeDateFormatter = RelativeDateTimeFormatter() struct ActiveGamesView_Previews: PreviewProvider { static var previews: some View { - @Shared(.savedGames) var savedGames = SavedGamesState() - savedGames = SavedGamesState( + @Shared(.savedGames) var savedGames = SavedGamesState( dailyChallengeUnlimited: update(.mock) { $0?.moves = [.highScoringMove] $0?.gameContext = .dailyChallenge(.init(rawValue: .dailyChallengeId)) diff --git a/Sources/AppFeature/AppDelegate.swift b/Sources/AppFeature/AppDelegate.swift index de2d3289..84f116dd 100644 --- a/Sources/AppFeature/AppDelegate.swift +++ b/Sources/AppFeature/AppDelegate.swift @@ -9,7 +9,6 @@ import Build @Reducer public struct AppDelegateReducer { public struct State: Equatable { - @Shared(.build) var build = Build() public init() {} } @@ -25,6 +24,7 @@ public struct AppDelegateReducer { @Dependency(\.remoteNotifications.register) var registerForRemoteNotifications @Dependency(\.applicationClient.setUserInterfaceStyle) var setUserInterfaceStyle @Dependency(\.userNotifications) var userNotifications + @Shared(.build) var build = Build() public init() {} @@ -84,14 +84,14 @@ public struct AppDelegateReducer { case let .didRegisterForRemoteNotifications(.success(tokenData)): let token = tokenData.map { String(format: "%02.2hhx", $0) }.joined() - return .run { [build = state.build] _ in + return .run { _ in let settings = await self.userNotifications.getNotificationSettings() _ = try await self.apiClient.apiRequest( route: .push( .register( .init( authorizationStatus: .init(rawValue: settings.authorizationStatus.rawValue), - build: build.number, + build: self.build.number, token: token ) ) diff --git a/Sources/AppFeature/AppView.swift b/Sources/AppFeature/AppView.swift index f8e270fe..7223f7b0 100644 --- a/Sources/AppFeature/AppView.swift +++ b/Sources/AppFeature/AppView.swift @@ -24,9 +24,9 @@ public struct AppReducer { public struct State: Equatable { public var appDelegate: AppDelegateReducer.State @Presents public var destination: Destination.State? - @Shared(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding = false + @SharedReader(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding = false public var home: Home.State - @Shared(.installationTime) var installationTime = Date().timeIntervalSince1970 + @Shared(.installationTime) var installationTime = 0 @SharedReader(.serverConfig) var serverConfig = ServerConfig() @Shared(.savedGames) var savedGames = SavedGamesState() @@ -238,8 +238,8 @@ public struct AppReducer { remoteNotifications: self.remoteNotifications, userNotifications: self.userNotifications ) - async let refresh = serverConfig.persistence.reload() - _ = try await (register, refresh) + async let refresh: Void = serverConfig.persistence.reload() + _ = await (register, refresh) } catch: { _, _ in } diff --git a/Sources/ChangelogFeature/ChangelogView.swift b/Sources/ChangelogFeature/ChangelogView.swift index cfc352b5..dfebd2c3 100644 --- a/Sources/ChangelogFeature/ChangelogView.swift +++ b/Sources/ChangelogFeature/ChangelogView.swift @@ -12,12 +12,12 @@ import UIApplicationClient public struct ChangelogReducer { @ObservableState public struct State: Equatable { + @SharedReader(.build) var build = Build() public var changelog: IdentifiedArrayOf public var currentBuild: Build.Number public var isRequestInFlight: Bool public var isUpdateButtonVisible: Bool @SharedReader(.serverConfig) var serverConfig = ServerConfig() - @Shared(.build) var build = Build() public init( changelog: IdentifiedArrayOf = [], diff --git a/Sources/ClientModels/AppStoragePersistenceKeys.swift b/Sources/ClientModels/AppStoragePersistenceKeys.swift index c15f906a..7a2e487f 100644 --- a/Sources/ClientModels/AppStoragePersistenceKeys.swift +++ b/Sources/ClientModels/AppStoragePersistenceKeys.swift @@ -1,21 +1,21 @@ import ComposableArchitecture -extension PersistenceKey where Self == AppStorageKey { +extension PersistenceReaderKey where Self == AppStorageKey { public static var installationTime: Self { appStorage("installationTimeKey") } } -extension PersistenceKey where Self == AppStorageKey { +extension PersistenceReaderKey where Self == AppStorageKey { public static var hasShownFirstLaunchOnboarding: Self { AppStorageKey("hasShownFirstLaunchOnboardingKey") } } -extension PersistenceKey where Self == AppStorageKey { +extension PersistenceReaderKey where Self == AppStorageKey { public static var multiplayerOpensCount: Self { AppStorageKey("multiplayerOpensCount") } } -extension PersistenceKey where Self == AppStorageKey { +extension PersistenceReaderKey where Self == AppStorageKey { public static var lastReviewRequest: Self { AppStorageKey("last-review-request-timeinterval") } diff --git a/Sources/ClientModels/SavedGamesState.swift b/Sources/ClientModels/SavedGamesState.swift index b7c55a7a..016368ed 100644 --- a/Sources/ClientModels/SavedGamesState.swift +++ b/Sources/ClientModels/SavedGamesState.swift @@ -13,7 +13,7 @@ public struct SavedGamesState: Codable, Equatable { } } -extension PersistenceKey where Self == FileStorageKey { +extension PersistenceReaderKey where Self == FileStorageKey { public static var savedGames: Self { fileStorage(.documentsDirectory.appending(path: "saved-games.json")) } diff --git a/Sources/HomeFeature/Home.swift b/Sources/HomeFeature/Home.swift index 01b1e22e..0b920acb 100644 --- a/Sources/HomeFeature/Home.swift +++ b/Sources/HomeFeature/Home.swift @@ -114,6 +114,7 @@ public struct Home { @Dependency(\.mainRunLoop.now.date) var now @Dependency(\.audioPlayer.play) var playSound @Dependency(\.timeZone) var timeZone + @SharedReader(.serverConfig) var serverConfig = ServerConfig() public init() {} @@ -293,7 +294,6 @@ public struct Home { ) await send(.authenticationResponse(currentPlayerEnvelope)) - @SharedReader(.serverConfig) var serverConfig = ServerConfig() async let serverConfigResponse: Void = $serverConfig.persistence.reload() async let dailyChallengeResponse: Void = send( @@ -324,7 +324,7 @@ public struct Home { } ) ) - _ = try await ( + _ = await ( serverConfigResponse, dailyChallengeResponse, weekInReviewResponse, activeMatchesResponse ) } catch {}