Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Apr 14, 2024
1 parent d735963 commit 2d998cb
Show file tree
Hide file tree
Showing 27 changed files with 358 additions and 387 deletions.
22 changes: 11 additions & 11 deletions App/iOS/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
.appendingPathComponent("co.pointfree.Isowords")
.appendingPathComponent("Isowords.sqlite3")
)
$0.serverConfig = .live(apiClient: $0.apiClient, build: $0.build)
//$0.serverConfig = .live(apiClient: $0.apiClient, build: $0.build)
}
}

Expand Down Expand Up @@ -75,13 +75,13 @@ extension AudioPlayerClient {
static let liveValue = Self.live(bundles: [AppAudioLibrary.bundle, AppClipAudioLibrary.bundle])
}

extension ServerConfigClient {
static func live(apiClient: ApiClient, build: Build) -> Self {
.live(
fetch: {
try await apiClient
.apiRequest(route: .config(build: build.number()), as: ServerConfig.self)
}
)
}
}
//extension ServerConfigClient {
// static func live(apiClient: ApiClient, build: Build) -> Self {
// .live(
// fetch: {
// try await apiClient
// .apiRequest(route: .config(build: build.number()), as: ServerConfig.self)
// }
// )
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"branch" : "shared-state-beta",
"revision" : "3c101fe227002bf6bf92a7c83eea4c496d8f53cd"
"branch" : "shared-state-generics",
"revision" : "e6bb5578b10404502c1de01b858672ad6abea297"
}
},
{
Expand Down
25 changes: 4 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(
url: "https://github.com/pointfreeco/swift-composable-architecture",
branch: "shared-state-beta"
branch: "shared-state-generics"
),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.0"),
Expand All @@ -46,8 +46,7 @@ var package = Package(
.target(
name: "Build",
dependencies: [
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Tagged", package: "swift-tagged"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
Expand Down Expand Up @@ -114,7 +113,8 @@ var package = Package(
.target(
name: "ServerConfig",
dependencies: [
"Build"
"ApiClient",
"Build",
]
),
.target(
Expand Down Expand Up @@ -213,7 +213,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "IntegrationTestHelpers", targets: ["IntegrationTestHelpers"]),
.library(name: "LeaderboardFeature", targets: ["LeaderboardFeature"]),
.library(name: "LocalDatabaseClient", targets: ["LocalDatabaseClient"]),
.library(name: "LowPowerModeClient", targets: ["LowPowerModeClient"]),
.library(name: "MultiplayerFeature", targets: ["MultiplayerFeature"]),
.library(name: "NotificationHelpers", targets: ["NotificationHelpers"]),
.library(name: "NotificationsAuthAlert", targets: ["NotificationsAuthAlert"]),
Expand Down Expand Up @@ -301,7 +300,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"HomeFeature",
"LeaderboardFeature",
"LocalDatabaseClient",
"LowPowerModeClient",
"MultiplayerFeature",
"NotificationHelpers",
"OnboardingFeature",
Expand Down Expand Up @@ -450,7 +448,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"CubeCore",
"FeedbackGeneratorClient",
"HapticsCore",
"LowPowerModeClient",
"SelectionSoundsCore",
"SharedModels",
"UserSettings",
Expand Down Expand Up @@ -520,7 +517,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"GameCore",
"DictionaryClient",
"FeedbackGeneratorClient",
"LowPowerModeClient",
"OnboardingFeature",
"SharedModels",
"UserDefaultsClient",
Expand Down Expand Up @@ -575,7 +571,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"GameOverFeature",
"FeedbackGeneratorClient",
"HapticsCore",
"LowPowerModeClient",
"PuzzleGen",
"RemoteNotificationsClient",
"SelectionSoundsCore",
Expand Down Expand Up @@ -670,7 +665,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"DeviceId",
"LeaderboardFeature",
"LocalDatabaseClient",
"LowPowerModeClient",
"MultiplayerFeature",
"ServerConfigClient",
"SettingsFeature",
Expand Down Expand Up @@ -709,7 +703,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ApiClient",
"AudioPlayerClient",
"CubePreview",
"LowPowerModeClient",
"Styleguide",
"SwiftUIHelpers",
"UserSettings",
Expand All @@ -735,12 +728,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.product(name: "Overture", package: "swift-overture"),
]
),
.target(
name: "LowPowerModeClient",
dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture")
]
),
.target(
name: "MultiplayerFeature",
dependencies: [
Expand Down Expand Up @@ -783,7 +770,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"GameCore",
"DictionaryClient",
"FeedbackGeneratorClient",
"LowPowerModeClient",
"PuzzleGen",
"SharedModels",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
Expand Down Expand Up @@ -828,7 +814,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ComposableStoreKit",
"ComposableUserNotifications",
"LocalDatabaseClient",
"LowPowerModeClient",
"RemoteNotificationsClient",
"ServerConfigClient",
"StatsFeature",
Expand Down Expand Up @@ -908,7 +893,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"GameCore",
"DictionaryClient",
"FeedbackGeneratorClient",
"LowPowerModeClient",
"OnboardingFeature",
"SharedModels",
"TcaHelpers",
Expand Down Expand Up @@ -963,7 +947,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"CubePreview",
"FeedbackGeneratorClient",
"LocalDatabaseClient",
"LowPowerModeClient",
"SharedModels",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
Expand Down
8 changes: 5 additions & 3 deletions Sources/AppFeature/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import ComposableUserNotifications
import Foundation
import SettingsFeature
import UserSettings
import Build

@Reducer
public struct AppDelegateReducer {
public struct State: Equatable {
@Shared(.build) var build = Build()
public init() {}
}

Expand All @@ -19,7 +21,7 @@ public struct AppDelegateReducer {

@Dependency(\.apiClient) var apiClient
@Dependency(\.audioPlayer) var audioPlayer
@Dependency(\.build.number) var buildNumber
//@Dependency(\.build.number) var buildNumber
@Dependency(\.dictionary.load) var loadDictionary
@Dependency(\.remoteNotifications.register) var registerForRemoteNotifications
@Dependency(\.applicationClient.setUserInterfaceStyle) var setUserInterfaceStyle
Expand Down Expand Up @@ -83,14 +85,14 @@ public struct AppDelegateReducer {

case let .didRegisterForRemoteNotifications(.success(tokenData)):
let token = tokenData.map { String(format: "%02.2hhx", $0) }.joined()
return .run { _ in
return .run { [build = state.build] _ in
let settings = await self.userNotifications.getNotificationSettings()
_ = try await self.apiClient.apiRequest(
route: .push(
.register(
.init(
authorizationStatus: .init(rawValue: settings.authorizationStatus.rawValue),
build: self.buildNumber(),
build: build.number,
token: token
)
)
Expand Down
25 changes: 13 additions & 12 deletions Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import OnboardingFeature
import SharedModels
import Styleguide
import SwiftUI
import ServerConfigClient

@Reducer
public struct AppReducer {
Expand All @@ -25,6 +26,9 @@ public struct AppReducer {
@Presents public var destination: Destination.State?
public var home: Home.State
@Shared(.savedGames) var savedGames = SavedGamesState()
@Shared(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding = false
@Shared(.installationTime) var installationTime = Date().timeIntervalSince1970
@SharedReader(.serverConfigNew) var serverConfig = ServerConfig()

public init(
appDelegate: AppDelegateReducer.State = AppDelegateReducer.State(),
Expand Down Expand Up @@ -52,8 +56,8 @@ public struct AppReducer {
@Dependency(\.mainRunLoop.now.date) var now
@Dependency(\.dictionary.randomCubes) var randomCubes
@Dependency(\.remoteNotifications) var remoteNotifications
@Dependency(\.serverConfig.refresh) var refreshServerConfig
@Dependency(\.userDefaults) var userDefaults
//@Dependency(\.serverConfig.refresh) var refreshServerConfig
//@Dependency(\.userDefaults) var userDefaults
@Dependency(\.userNotifications) var userNotifications

public init() {}
Expand Down Expand Up @@ -92,16 +96,13 @@ public struct AppReducer {
Reduce { state, action in
switch action {
case .appDelegate(.didFinishLaunching):
if !self.userDefaults.hasShownFirstLaunchOnboarding {
if !state.hasShownFirstLaunchOnboarding {
state.destination = .onboarding(Onboarding.State(presentationStyle: .firstLaunch))
}

return .run { send in
if self.userDefaults.installationTime <= 0 {
await self.userDefaults.setInstallationTime(
self.now.timeIntervalSinceReferenceDate
)
}
if state.installationTime <= 0 {
state.installationTime = self.now.timeIntervalSinceReferenceDate
}
return .run { _ in
try await self.migrate()
}

Expand Down Expand Up @@ -234,12 +235,12 @@ public struct AppReducer {
return .none

case .didChangeScenePhase(.active):
return .run { _ in
return .run { [serverConfig = state.$serverConfig] _ in
async let register: Void = registerForRemoteNotificationsAsync(
remoteNotifications: self.remoteNotifications,
userNotifications: self.userNotifications
)
async let refresh = self.refreshServerConfig()
async let refresh = serverConfig.persistence.reload() //.refreshServerConfig()
_ = try await (register, refresh)
} catch: { _, _ in
}
Expand Down
46 changes: 11 additions & 35 deletions Sources/Build/Build.swift
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
import Dependencies
import DependenciesMacros
import ComposableArchitecture
import Foundation
import Tagged

@DependencyClient
public struct Build {
public var gitSha: () -> String = { "deadbeef" }
public var number: () -> Number = { 0 }
public struct Build: Equatable, Sendable {
public var gitSha = Bundle.main.infoDictionary?["GitSHA"] as? String ?? ""
public var number = Number(
rawValue: (Bundle.main.infoDictionary?["CFBundleVersion"] as? String)
.flatMap(Int.init)
?? 0)
public init() {}

public typealias Number = Tagged<((), number: ()), Int>
}

extension DependencyValues {
public var build: Build {
get { self[Build.self] }
set { self[Build.self] = newValue }
extension PersistenceReaderKey where Self == InMemoryKey<Build> {
public static var build: Self {
inMemory("build")
}
}

extension Build: TestDependencyKey {
public static let previewValue = Self.noop
public static let testValue = Self()
}

extension Build: DependencyKey {
public static let liveValue = Self(
gitSha: { Bundle.main.infoDictionary?["GitSHA"] as? String ?? "" },
number: {
.init(
rawValue: (Bundle.main.infoDictionary?["CFBundleVersion"] as? String)
.flatMap(Int.init)
?? 0
)
}
)
}

extension Build {
public static let noop = Self(
gitSha: { "deadbeef" },
number: { 0 }
)
}
Loading

0 comments on commit 2d998cb

Please sign in to comment.