-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathApp.swift
More file actions
132 lines (121 loc) · 3.34 KB
/
App.swift
File metadata and controls
132 lines (121 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import ApiClientLive
import AppAudioLibrary
import AppClipAudioLibrary
import AppFeature
import Build
import ComposableArchitecture
import CryptoKit
import DictionarySqliteClient
import ServerConfig
import ServerConfigClient
import Styleguide
import SwiftUI
import UIApplicationClient
final class AppDelegate: NSObject, UIApplicationDelegate {
let store = Store(
initialState: .init(),
reducer: appReducer,
environment: .live
)
lazy var viewStore = ViewStore(
self.store.scope(state: { _ in () }),
removeDuplicates: ==
)
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
self.viewStore.send(.appDelegate(.didFinishLaunching))
return true
}
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
self.viewStore.send(.appDelegate(.didRegisterForRemoteNotifications(.success(deviceToken))))
}
func application(
_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error
) {
self.viewStore.send(
.appDelegate(.didRegisterForRemoteNotifications(.failure(error as NSError)))
)
}
}
@main
struct IsowordsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@Environment(\.scenePhase) private var scenePhase
init() {
Styleguide.registerFonts()
}
var body: some Scene {
WindowGroup {
AppView(store: self.appDelegate.store)
}
.onChange(of: self.scenePhase) {
self.appDelegate.viewStore.send(.didChangeScenePhase($0))
}
}
}
extension AppEnvironment {
static var live: Self {
let apiClient = ApiClient.live
let build = Build.live
return Self(
apiClient: apiClient,
applicationClient: .live,
audioPlayer: .live(
bundles: [
AppAudioLibrary.bundle,
AppClipAudioLibrary.bundle,
]
),
backgroundQueue: DispatchQueue(label: "background-queue").eraseToAnyScheduler(),
build: build,
database: .live(
path: FileManager.default
.urls(for: .documentDirectory, in: .userDomainMask)
.first!
.appendingPathComponent("co.pointfree.Isowords")
.appendingPathComponent("Isowords.sqlite3")
),
deviceId: .live,
dictionary: .sqlite(),
feedbackGenerator: .live,
fileClient: .live,
gameCenter: .live,
lowPowerMode: .live,
mainQueue: .main,
mainRunLoop: .main,
remoteNotifications: .live,
serverConfig: .live(apiClient: apiClient, build: build),
setUserInterfaceStyle: { userInterfaceStyle in
.fireAndForget {
UIApplication.shared.windows.first?.overrideUserInterfaceStyle = userInterfaceStyle
}
},
storeKit: .live(),
timeZone: { .autoupdatingCurrent },
userDefaults: .live(),
userNotifications: .live
)
}
}
extension ApiClient {
static let live = Self.live(
sha256: { Data(SHA256.hash(data: $0)) }
)
}
extension ServerConfigClient {
static func live(apiClient: ApiClient, build: Build) -> Self {
.live(
fetch: {
apiClient.apiRequest(route: .config(build: build.number()), as: ServerConfig.self)
.mapError { $0 as Error }
.eraseToEffect()
}
)
}
}