-
Notifications
You must be signed in to change notification settings - Fork 214
/
App.swift
90 lines (80 loc) · 2.38 KB
/
App.swift
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
import ApiClientLive
import AppAudioLibrary
import AppClipAudioLibrary
import AppFeature
import AudioPlayerClient
import Build
import ComposableArchitecture
import DictionarySqliteClient
import ServerConfig
import ServerConfigClient
import Styleguide
import SwiftUI
import UIApplicationClient
final class AppDelegate: NSObject, UIApplicationDelegate {
let store = Store(
initialState: AppReducer.State(),
reducer: AppReducer().transformDependency(\.self) {
$0.audioPlayer = .liveValue
$0.database = .live(
path: FileManager.default
.urls(for: .documentDirectory, in: .userDomainMask)
.first!
.appendingPathComponent("co.pointfree.Isowords")
.appendingPathComponent("Isowords.sqlite3")
)
$0.serverConfig = .live(apiClient: $0.apiClient, build: $0.build)
}
)
var viewStore: ViewStore<Void, AppReducer.Action> {
ViewStore(self.store.stateless)
}
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))))
}
}
@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 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)
}
)
}
}