|
1 | 1 | import Client |
| 2 | +import ComposableArchitecture |
2 | 3 | import LaunchAgentManager |
3 | 4 | import Preferences |
4 | 5 | import SwiftUI |
5 | 6 |
|
6 | 7 | struct GeneralView: View { |
| 8 | + let store: StoreOf<General> |
| 9 | + |
7 | 10 | var body: some View { |
8 | 11 | ScrollView { |
9 | 12 | VStack(alignment: .leading, spacing: 0) { |
10 | 13 | AppInfoView() |
11 | 14 | Divider() |
12 | | - ExtensionServiceView() |
| 15 | + ExtensionServiceView(store: store) |
13 | 16 | Divider() |
14 | 17 | LaunchAgentView() |
15 | 18 | Divider() |
16 | 19 | GeneralSettingsView() |
17 | 20 | } |
18 | 21 | } |
| 22 | + .onAppear { |
| 23 | + store.send(.appear) |
| 24 | + } |
19 | 25 | } |
20 | 26 | } |
21 | 27 |
|
@@ -74,24 +80,28 @@ struct AppInfoView: View { |
74 | 80 | } |
75 | 81 |
|
76 | 82 | struct ExtensionServiceView: View { |
77 | | - @Environment(\.toast) var toast |
78 | | - @State var xpcServiceVersion: String? |
79 | | - @State var isAccessibilityPermissionGranted: Bool? |
80 | | - @State var isRunningAction = false |
| 83 | + let store: StoreOf<General> |
81 | 84 |
|
82 | 85 | var body: some View { |
83 | 86 | VStack(alignment: .leading) { |
84 | | - Text("Extension Service Version: \(xpcServiceVersion ?? "Loading..")") |
85 | | - let grantedStatus: String = { |
86 | | - guard let isAccessibilityPermissionGranted else { return "Loading.." } |
87 | | - return isAccessibilityPermissionGranted ? "Granted" : "Not Granted" |
88 | | - }() |
89 | | - Text("Accessibility Permission: \(grantedStatus)") |
| 87 | + WithViewStore(store, observe: { $0.xpcServiceVersion }) { viewStore in |
| 88 | + Text("Extension Service Version: \(viewStore.state ?? "Loading..")") |
| 89 | + } |
| 90 | + |
| 91 | + WithViewStore(store, observe: { $0.isAccessibilityPermissionGranted }) { viewStore in |
| 92 | + let grantedStatus: String = { |
| 93 | + guard let granted = viewStore.state else { return "Loading.." } |
| 94 | + return granted ? "Granted" : "Not Granted" |
| 95 | + }() |
| 96 | + Text("Accessibility Permission: \(grantedStatus)") |
| 97 | + } |
90 | 98 |
|
91 | 99 | HStack { |
92 | | - Button(action: { checkStatus() }) { |
93 | | - Text("Refresh") |
94 | | - }.disabled(isRunningAction) |
| 100 | + WithViewStore(store, observe: { $0.isReloading }) { viewStore in |
| 101 | + Button(action: { viewStore.send(.reloadStatus) }) { |
| 102 | + Text("Refresh") |
| 103 | + }.disabled(viewStore.state) |
| 104 | + } |
95 | 105 |
|
96 | 106 | Button(action: { |
97 | 107 | Task { |
@@ -126,25 +136,6 @@ struct ExtensionServiceView: View { |
126 | 136 | } |
127 | 137 | } |
128 | 138 | .padding() |
129 | | - .onAppear { |
130 | | - checkStatus() |
131 | | - } |
132 | | - } |
133 | | - |
134 | | - func checkStatus() { |
135 | | - Task { |
136 | | - try await Task.sleep(nanoseconds: 2_000_000_000) |
137 | | - isRunningAction = true |
138 | | - defer { isRunningAction = false } |
139 | | - do { |
140 | | - let service = try getService() |
141 | | - xpcServiceVersion = try await service.getXPCServiceVersion().version |
142 | | - isAccessibilityPermissionGranted = try await service |
143 | | - .getXPCServiceAccessibilityPermission() |
144 | | - } catch { |
145 | | - toast(Text(error.localizedDescription), .error) |
146 | | - } |
147 | | - } |
148 | 139 | } |
149 | 140 | } |
150 | 141 |
|
@@ -298,7 +289,7 @@ struct GeneralSettingsView: View { |
298 | 289 |
|
299 | 290 | struct GeneralView_Previews: PreviewProvider { |
300 | 291 | static var previews: some View { |
301 | | - GeneralView() |
| 292 | + GeneralView(store: .init(initialState: .init(), reducer: General())) |
302 | 293 | } |
303 | 294 | } |
304 | 295 |
|
0 commit comments