Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Apr 14, 2024
1 parent 2d998cb commit 8811b9c
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 344 deletions.
3 changes: 1 addition & 2 deletions App/Previews/SettingsPreview/SettingsPreviewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import AudioPlayerClient
import ComposableStoreKit
import ComposableUserNotifications
import RemoteNotificationsClient
import ServerConfigClient
import ServerConfigPersistenceKey
import SettingsFeature
import Styleguide
import SwiftUI
import UserDefaultsClient

@main
struct SettingsPreviewApp: App {
Expand Down
14 changes: 1 addition & 13 deletions App/iOS/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Build
import ComposableArchitecture
import DictionarySqliteClient
import ServerConfig
import ServerConfigClient
import ServerConfigPersistenceKey
import Styleguide
import SwiftUI
import UIApplicationClient
Expand All @@ -25,7 +25,6 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
.appendingPathComponent("co.pointfree.Isowords")
.appendingPathComponent("Isowords.sqlite3")
)
//$0.serverConfig = .live(apiClient: $0.apiClient, build: $0.build)
}
}

Expand Down Expand Up @@ -74,14 +73,3 @@ struct IsowordsApp: App {
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)
// }
// )
// }
//}
26 changes: 6 additions & 20 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "OnboardingFeature", targets: ["OnboardingFeature"]),
.library(name: "RemoteNotificationsClient", targets: ["RemoteNotificationsClient"]),
.library(name: "SelectionSoundsCore", targets: ["SelectionSoundsCore"]),
.library(name: "ServerConfigClient", targets: ["ServerConfigClient"]),
.library(name: "ServerConfigPersistenceKey", targets: ["ServerConfigPersistenceKey"]),
.library(name: "SettingsFeature", targets: ["SettingsFeature"]),
.library(name: "SharedSwiftUIEnvironment", targets: ["SharedSwiftUIEnvironment"]),
.library(name: "SoloFeature", targets: ["SoloFeature"]),
Expand All @@ -231,7 +231,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.library(name: "UserSettings", targets: ["UserSettings"]),
.library(name: "UIApplicationClient", targets: ["UIApplicationClient"]),
.library(name: "UpgradeInterstitialFeature", targets: ["UpgradeInterstitialFeature"]),
.library(name: "UserDefaultsClient", targets: ["UserDefaultsClient"]),
.library(name: "VocabFeature", targets: ["VocabFeature"]),
])
package.targets.append(contentsOf: [
Expand Down Expand Up @@ -366,13 +365,12 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
dependencies: [
"ApiClient",
"Build",
"ServerConfigClient",
"ServerConfigPersistenceKey",
"SharedModels",
"Styleguide",
"SwiftUIHelpers",
"TcaHelpers",
"UIApplicationClient",
"UserDefaultsClient",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Overture", package: "swift-overture"),
]
Expand Down Expand Up @@ -519,7 +517,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"FeedbackGeneratorClient",
"OnboardingFeature",
"SharedModels",
"UserDefaultsClient",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
Expand Down Expand Up @@ -611,7 +608,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"SwiftUIHelpers",
"TcaHelpers",
"UpgradeInterstitialFeature",
"UserDefaultsClient",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
Expand Down Expand Up @@ -666,7 +662,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"LeaderboardFeature",
"LocalDatabaseClient",
"MultiplayerFeature",
"ServerConfigClient",
"ServerConfigPersistenceKey",
"SettingsFeature",
"SharedModels",
"SoloFeature",
Expand All @@ -675,7 +671,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"TcaHelpers",
"UIApplicationClient",
"UpgradeInterstitialFeature",
"UserDefaultsClient",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "Overture", package: "swift-overture"),
]
Expand Down Expand Up @@ -798,7 +793,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
]
),
.target(
name: "ServerConfigClient",
name: "ServerConfigPersistenceKey",
dependencies: [
"ServerConfig",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
Expand All @@ -815,13 +810,12 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ComposableUserNotifications",
"LocalDatabaseClient",
"RemoteNotificationsClient",
"ServerConfigClient",
"ServerConfigPersistenceKey",
"StatsFeature",
"Styleguide",
"SwiftUIHelpers",
"TcaHelpers",
"UIApplicationClient",
"UserDefaultsClient",
"UserSettings",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
Expand Down Expand Up @@ -896,7 +890,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"OnboardingFeature",
"SharedModels",
"TcaHelpers",
"UserDefaultsClient",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]
),
Expand All @@ -917,7 +910,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
name: "UpgradeInterstitialFeature",
dependencies: [
"ComposableStoreKit",
"ServerConfigClient",
"ServerConfigPersistenceKey",
"Styleguide",
"SwiftUIHelpers",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
Expand All @@ -933,13 +926,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
],
exclude: ["__Snapshots__"]
),
.target(
name: "UserDefaultsClient",
dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.target(
name: "VocabFeature",
dependencies: [
Expand Down
1 change: 0 additions & 1 deletion Sources/AppFeature/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public struct AppDelegateReducer {

@Dependency(\.apiClient) var apiClient
@Dependency(\.audioPlayer) var audioPlayer
//@Dependency(\.build.number) var buildNumber
@Dependency(\.dictionary.load) var loadDictionary
@Dependency(\.remoteNotifications.register) var registerForRemoteNotifications
@Dependency(\.applicationClient.setUserInterfaceStyle) var setUserInterfaceStyle
Expand Down
8 changes: 3 additions & 5 deletions Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OnboardingFeature
import SharedModels
import Styleguide
import SwiftUI
import ServerConfigClient
import ServerConfigPersistenceKey

@Reducer
public struct AppReducer {
Expand All @@ -28,7 +28,7 @@ public struct AppReducer {
@Shared(.savedGames) var savedGames = SavedGamesState()
@Shared(.hasShownFirstLaunchOnboarding) var hasShownFirstLaunchOnboarding = false
@Shared(.installationTime) var installationTime = Date().timeIntervalSince1970
@SharedReader(.serverConfigNew) var serverConfig = ServerConfig()
@SharedReader(.serverConfig) var serverConfig = ServerConfig()

public init(
appDelegate: AppDelegateReducer.State = AppDelegateReducer.State(),
Expand Down Expand Up @@ -56,8 +56,6 @@ 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(\.userNotifications) var userNotifications

public init() {}
Expand Down Expand Up @@ -240,7 +238,7 @@ public struct AppReducer {
remoteNotifications: self.remoteNotifications,
userNotifications: self.userNotifications
)
async let refresh = serverConfig.persistence.reload() //.refreshServerConfig()
async let refresh = serverConfig.persistence.reload()
_ = try await (register, refresh)
} catch: { _, _ in
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ChangelogFeature/ChangeView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Build
import ComposableArchitecture
import ServerConfigClient
import ServerConfigPersistenceKey
import SwiftUI
import Tagged

Expand Down
8 changes: 2 additions & 6 deletions Sources/ChangelogFeature/ChangelogView.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApiClient
import Build
import ComposableArchitecture
import ServerConfigClient
import ServerConfigPersistenceKey
import SharedModels
import Styleguide
import SwiftUI
Expand All @@ -16,7 +16,7 @@ public struct ChangelogReducer {
public var currentBuild: Build.Number
public var isRequestInFlight: Bool
public var isUpdateButtonVisible: Bool
@SharedReader(.serverConfigNew) var serverConfig = ServerConfig()
@SharedReader(.serverConfig) var serverConfig = ServerConfig()
@Shared(.build) var build = Build()

public init(
Expand Down Expand Up @@ -48,9 +48,7 @@ public struct ChangelogReducer {
}

@Dependency(\.apiClient) var apiClient
//@Dependency(\.build.number) var buildNumber
@Dependency(\.applicationClient.open) var openURL
//@Dependency(\.serverConfig) var serverConfig

public init() {}

Expand Down Expand Up @@ -185,8 +183,6 @@ public struct ChangelogView: View {
return apiClient
}()
$0.applicationClient = .noop
//$0.build.number = { 98 }
//$0.serverConfig = .noop
}
)
.navigationStyle(
Expand Down
32 changes: 16 additions & 16 deletions Sources/ClientModels/AppStorage.swift
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import SwiftUI

extension AppStorageKey where Value == Bool {
public static let enableCubeShadow = Self(key: "enableCubeShadow", defaultValue: true)
public static let showSceneStatistics = Self(key: "showSceneStatistics", defaultValue: false)
extension _AppStorageKey where Value == Bool {
public static let enableCubeShadow = _AppStorageKey(key: "enableCubeShadow", defaultValue: true)
public static let showSceneStatistics = _AppStorageKey(key: "showSceneStatistics", defaultValue: false)
}

public struct AppStorageKey<Value> {
public struct _AppStorageKey<Value> {
public let key: String
public let defaultValue: Value
}

extension AppStorage {
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Bool {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Bool {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Int {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Int {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Double {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Double {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == String {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == String {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Data {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Data {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil)
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil)
where Value: RawRepresentable, Value.RawValue == Int {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil)
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil)
where Value: RawRepresentable, Value.RawValue == String {
self.init(wrappedValue: key.defaultValue, key.key, store: store)
}
}

extension AppStorage where Value: ExpressibleByNilLiteral {
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Bool? {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Bool? {
self.init(key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Int? {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Int? {
self.init(key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Double? {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Double? {
self.init(key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == String? {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == String? {
self.init(key.key, store: store)
}
public init(_ key: AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Data? {
public init(_ key: _AppStorageKey<Value>, store: UserDefaults? = nil) where Value == Data? {
self.init(key.key, store: store)
}
}
22 changes: 22 additions & 0 deletions Sources/ClientModels/AppStoragePersistenceKeys.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ComposableArchitecture

extension PersistenceKey where Self == AppStorageKey<Double> {
public static var installationTime: Self {
appStorage("installationTimeKey")
}
}
extension PersistenceKey where Self == AppStorageKey<Bool> {
public static var hasShownFirstLaunchOnboarding: Self {
AppStorageKey("hasShownFirstLaunchOnboardingKey")
}
}
extension PersistenceKey where Self == AppStorageKey<Int> {
public static var multiplayerOpensCount: Self {
AppStorageKey("multiplayerOpensCount")
}
}
extension PersistenceKey where Self == AppStorageKey<Double> {
public static var lastReviewRequest: Self {
AppStorageKey("last-review-request-timeinterval")
}
}
16 changes: 8 additions & 8 deletions Sources/CubeCore/CubeSceneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {
private let cameraNode = SCNNode()
private var cancellables: Set<AnyCancellable> = []
private let gameCubeNode = SCNNode()
@Published var isLowPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled
private let light = SCNLight()
private var motionManager: CMMotionManager?
private var startingAttitude: Attitude?
private let viewStore: ViewStore<ViewState, ViewAction>
private var worldScale: Float = 1.0

@Published var isLowPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled {
didSet { self.update() }
}
var enableCubeShadow = true {
didSet { self.update() }
}
Expand Down Expand Up @@ -113,13 +115,11 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {
gameCubeNode.scale = .init(worldScale, worldScale, worldScale)
self.scene?.rootNode.addChildNode(self.gameCubeNode)

NotificationCenter.default.addObserver(
forName: .NSProcessInfoPowerStateDidChange,
object: nil,
queue: nil
) { [weak self] _ in
self?.isLowPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled
}
NotificationCenter.default.publisher(for: .NSProcessInfoPowerStateDidChange)
.sink { [weak self] _ in
self?.isLowPowerEnabled = ProcessInfo.processInfo.isLowPowerModeEnabled
}
.store(in: &cancellables)

self.viewStore.publisher.cubes
.sink { cubes in
Expand Down
6 changes: 1 addition & 5 deletions Sources/DailyChallengeFeature/DailyChallengeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ public struct DailyChallengeReducer {
await send(
.startDailyChallengeResponse(
Result {
try await startDailyChallengeAsync(
challenge,
apiClient: self.apiClient,
date: { self.now }
)
try await startDailyChallenge(challenge)
}
)
)
Expand Down
Loading

0 comments on commit 8811b9c

Please sign in to comment.