From 73bef30e31079bc80353994bd31e04ab8336a984 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 30 Apr 2024 19:49:47 -0700 Subject: [PATCH] wip --- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- Package.swift | 2 +- Sources/AppFeature/AppView.swift | 19 ++++++++++++------- Sources/HomeFeature/Home.swift | 6 +++--- .../OnboardingFeature/OnboardingView.swift | 8 +++++--- Sources/UserDefaultsClient/Interface.swift | 13 +++++++++++++ 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/App/isowords.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/App/isowords.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index d2cb4c1a..454ee6b5 100644 --- a/App/isowords.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/App/isowords.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-composable-architecture", "state" : { - "revision" : "115fe5af41d333b6156d4924d7c7058bc77fd580", - "version" : "1.9.2" + "branch" : "shared-state-beta", + "revision" : "76343472bde40429785fa17c771bc6be42db2a87" } }, { @@ -129,7 +129,7 @@ { "identity" : "swift-crypto", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-crypto.git", + "location" : "https://github.com/apple/swift-crypto", "state" : { "revision" : "ddb07e896a2a8af79512543b1c7eb9797f8898a5", "version" : "1.1.7" diff --git a/Package.swift b/Package.swift index b9538df5..8ae17ac8 100644 --- a/Package.swift +++ b/Package.swift @@ -28,7 +28,7 @@ var package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-crypto", from: "1.1.6"), .package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"), - .package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.9.2"), + .package(url: "https://github.com/pointfreeco/swift-composable-architecture", branch: "shared-state-beta"), .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"), .package(url: "https://github.com/pointfreeco/swift-gen", from: "0.3.0"), diff --git a/Sources/AppFeature/AppView.swift b/Sources/AppFeature/AppView.swift index dcf417e4..ff865e86 100644 --- a/Sources/AppFeature/AppView.swift +++ b/Sources/AppFeature/AppView.swift @@ -22,7 +22,9 @@ public struct AppReducer { public struct State: Equatable { public var appDelegate: AppDelegateReducer.State @Presents public var destination: Destination.State? + @SharedReader(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding public var home: Home.State + @Shared(.installationTime) var installationTime public init( appDelegate: AppDelegateReducer.State = AppDelegateReducer.State(), @@ -53,7 +55,7 @@ public struct AppReducer { @Dependency(\.dictionary.randomCubes) var randomCubes @Dependency(\.remoteNotifications) var remoteNotifications @Dependency(\.serverConfig.refresh) var refreshServerConfig - @Dependency(\.userDefaults) var userDefaults + //@Dependency(\.userDefaults) var userDefaults @Dependency(\.userNotifications) var userNotifications public init() {} @@ -100,17 +102,20 @@ 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)) } + if state.installationTime <= 0 { + state.installationTime = now.timeIntervalSinceReferenceDate + } return .run { send in async let migrate: Void = self.migrate() - if self.userDefaults.installationTime <= 0 { - await self.userDefaults.setInstallationTime( - self.now.timeIntervalSinceReferenceDate - ) - } +// if self.userDefaults.installationTime <= 0 { +// await self.userDefaults.setInstallationTime( +// self.now.timeIntervalSinceReferenceDate +// ) +// } await send( .savedGamesLoaded( Result { try await self.fileClient.loadSavedGames() } diff --git a/Sources/HomeFeature/Home.swift b/Sources/HomeFeature/Home.swift index ad59735b..d373f00e 100644 --- a/Sources/HomeFeature/Home.swift +++ b/Sources/HomeFeature/Home.swift @@ -38,6 +38,7 @@ public struct Home { @Presents public var destination: Destination.State? public var hasChangelog: Bool public var hasPastTurnBasedGames: Bool + @SharedReader(.installationTime) var installationTime @Presents public var nagBanner: NagBanner.State? public var savedGames: SavedGamesState { didSet { @@ -125,7 +126,7 @@ public struct Home { @Dependency(\.audioPlayer.play) var playSound @Dependency(\.serverConfig) var serverConfig @Dependency(\.timeZone) var timeZone - @Dependency(\.userDefaults) var userDefaults + //@Dependency(\.userDefaults) var userDefaults public init() {} @@ -207,8 +208,7 @@ public struct Home { case let .authenticationResponse(currentPlayerEnvelope): let now = self.now.timeIntervalSinceReferenceDate - let itsNagTime = - Int(now - self.userDefaults.installationTime) + let itsNagTime = Int(now - state.installationTime) >= self.serverConfig.config().upgradeInterstitial.nagBannerAfterInstallDuration let isFullGamePurchased = currentPlayerEnvelope.appleReceipt?.receipt.originalPurchaseDate != nil diff --git a/Sources/OnboardingFeature/OnboardingView.swift b/Sources/OnboardingFeature/OnboardingView.swift index b10ada14..d46e4391 100644 --- a/Sources/OnboardingFeature/OnboardingView.swift +++ b/Sources/OnboardingFeature/OnboardingView.swift @@ -20,6 +20,7 @@ public struct Onboarding { public var game: Game.State public var presentationStyle: PresentationStyle public var step: Step + @Shared(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding public init( alert: AlertState? = nil, @@ -181,7 +182,7 @@ public struct Onboarding { @Dependency(\.dictionary) var dictionary @Dependency(\.feedbackGenerator) var feedbackGenerator @Dependency(\.mainQueue) var mainQueue - @Dependency(\.userDefaults) var userDefaults + //@Dependency(\.userDefaults) var userDefaults @Dependency(\.userSettings) var userSettings public init() {} @@ -204,8 +205,9 @@ public struct Onboarding { return .none case .delegate(.getStarted): + state.hasShownFirstLaunchOnboarding = true return .run { _ in - await self.userDefaults.setHasShownFirstLaunchOnboarding(true) + //await self.userDefaults.setHasShownFirstLaunchOnboarding(true) await self.audioPlayer.stop(.onboardingBgMusic) Task.cancel(id: CancelID.delayedNextStep) } @@ -268,7 +270,7 @@ public struct Onboarding { return .run { _ in await self.audioPlayer.play(.uiSfxTap) } case .skipButtonTapped: - guard !self.userDefaults.hasShownFirstLaunchOnboarding else { + guard !state.hasShownFirstLaunchOnboarding else { return .run { send in await send(.delegate(.getStarted), animation: .default) await self.audioPlayer.play(.uiSfxTap) diff --git a/Sources/UserDefaultsClient/Interface.swift b/Sources/UserDefaultsClient/Interface.swift index 5ad37db0..45e7b3af 100644 --- a/Sources/UserDefaultsClient/Interface.swift +++ b/Sources/UserDefaultsClient/Interface.swift @@ -47,3 +47,16 @@ public struct UserDefaultsClient { let hasShownFirstLaunchOnboardingKey = "hasShownFirstLaunchOnboardingKey" let installationTimeKey = "installationTimeKey" let multiplayerOpensCount = "multiplayerOpensCount" + +import ComposableArchitecture + +extension PersistenceKey where Self == PersistenceKeyDefault> { + public static var hasShownFirstLaunchOnboarding: Self { + PersistenceKeyDefault(.appStorage("hasShownFirstLaunchOnboardingKey"), false) + } +} +extension PersistenceKey where Self == PersistenceKeyDefault> { + public static var installationTime: Self { + PersistenceKeyDefault(.appStorage("installationTimeKey"), 0.0) + } +}