forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostApp.swift
More file actions
70 lines (56 loc) · 1.54 KB
/
HostApp.swift
File metadata and controls
70 lines (56 loc) · 1.54 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
import Client
import ComposableArchitecture
import Foundation
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let showHideWidget = Self("ShowHideWidget")
}
@Reducer
struct HostApp {
@ObservableState
struct State: Equatable {
var general = General.State()
}
enum Action: Equatable {
case appear
case general(General.Action)
}
@Dependency(\.toast) var toast
init() {
KeyboardShortcuts.userDefaults = .shared
}
var body: some ReducerOf<Self> {
Scope(state: \.general, action: /Action.general) {
General()
}
Reduce { _, action in
switch action {
case .appear:
return .none
case .general:
return .none
}
}
}
}
import Dependencies
import Preferences
struct UserDefaultsDependencyKey: DependencyKey {
static var liveValue: UserDefaultsType = UserDefaults.shared
static var previewValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppPreview")!
it.removePersistentDomain(forName: "HostAppPreview")
return it
}()
static var testValue: UserDefaultsType = {
let it = UserDefaults(suiteName: "HostAppTest")!
it.removePersistentDomain(forName: "HostAppTest")
return it
}()
}
extension DependencyValues {
var userDefaults: UserDefaultsType {
get { self[UserDefaultsDependencyKey.self] }
set { self[UserDefaultsDependencyKey.self] = newValue }
}
}