Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed May 1, 2024
1 parent ca796b7 commit 73bef30
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
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" : {
"revision" : "115fe5af41d333b6156d4924d7c7058bc77fd580",
"version" : "1.9.2"
"branch" : "shared-state-beta",
"revision" : "76343472bde40429785fa17c771bc6be42db2a87"
}
},
{
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
19 changes: 12 additions & 7 deletions Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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() }
Expand Down
6 changes: 3 additions & 3 deletions Sources/HomeFeature/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Sources/OnboardingFeature/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action.Alert>? = nil,
Expand Down Expand Up @@ -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() {}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions Sources/UserDefaultsClient/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ public struct UserDefaultsClient {
let hasShownFirstLaunchOnboardingKey = "hasShownFirstLaunchOnboardingKey"
let installationTimeKey = "installationTimeKey"
let multiplayerOpensCount = "multiplayerOpensCount"

import ComposableArchitecture

extension PersistenceKey where Self == PersistenceKeyDefault<AppStorageKey<Bool>> {
public static var hasShownFirstLaunchOnboarding: Self {
PersistenceKeyDefault(.appStorage("hasShownFirstLaunchOnboardingKey"), false)
}
}
extension PersistenceKey where Self == PersistenceKeyDefault<AppStorageKey<Double>> {
public static var installationTime: Self {
PersistenceKeyDefault(.appStorage("installationTimeKey"), 0.0)
}
}

0 comments on commit 73bef30

Please sign in to comment.