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
106 lines (89 loc) · 2.5 KB
/
HostApp.swift
File metadata and controls
106 lines (89 loc) · 2.5 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
import Client
import ComposableArchitecture
import Foundation
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let showHideWidget = Self("ShowHideWidget")
}
public enum TabIndex: Int, CaseIterable {
case general = 0
case advanced = 1
case tools = 2
case byok = 3
var title: String {
switch self {
case .general: return "General"
case .advanced: return "Advanced"
case .tools: return "Tools"
case .byok: return "Models"
}
}
var image: String {
switch self {
case .general: return "CopilotLogo"
case .advanced: return "gearshape.2.fill"
case .tools: return "wrench.and.screwdriver.fill"
case .byok: return "Model"
}
}
var isSystemImage: Bool {
switch self {
case .general, .byok: return false
default: return true
}
}
}
@Reducer
public struct HostApp {
@ObservableState
public struct State: Equatable {
var general = General.State()
public var activeTabIndex: TabIndex = .general
}
public enum Action: Equatable {
case appear
case general(General.Action)
case setActiveTab(TabIndex)
}
@Dependency(\.toast) var toast
init() {
KeyboardShortcuts.userDefaults = .shared
}
public var body: some ReducerOf<Self> {
Scope(state: \.general, action: /Action.general) {
General()
}
Reduce { state, action in
switch action {
case .appear:
return .none
case .general:
return .none
case .setActiveTab(let index):
state.activeTabIndex = index
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 }
}
}