@@ -59,6 +59,7 @@ struct AboutView: View {
59
59
@State private var showCheckFailed = false
60
60
@State private var showDownloadFailed = false
61
61
@State private var showInstallFailed = false
62
+ @State private var showSwitchToDebug = false
62
63
@State private var confirmUninstall = false
63
64
@State private var removeUserData = false
64
65
@State private var uninstalling = false
@@ -77,7 +78,13 @@ struct AboutView: View {
77
78
. font ( . title)
78
79
79
80
Spacer ( ) . frame ( height: gapSize)
80
- Text ( arch)
81
+
82
+ HStack {
83
+ Text ( arch)
84
+ if isDebug {
85
+ Text ( " Debug " )
86
+ }
87
+ }
81
88
82
89
Spacer ( ) . frame ( height: gapSize)
83
90
urlButton ( String ( commit. prefix ( 7 ) ) , sourceRepo + " /commit/ " + commit)
@@ -110,7 +117,7 @@ struct AboutView: View {
110
117
if viewModel. state == . notChecked {
111
118
checkUpdate ( )
112
119
} else if viewModel. state == . available {
113
- update ( )
120
+ update ( debug : isDebug )
114
121
}
115
122
} label: {
116
123
if viewModel. state == . notChecked || viewModel. state == . upToDate {
@@ -139,7 +146,7 @@ struct AboutView: View {
139
146
VStack {
140
147
Text ( " Update available " )
141
148
Button {
142
- update ( )
149
+ update ( debug : isDebug )
143
150
} label: {
144
151
Text ( " Update now " )
145
152
} . buttonStyle ( . borderedProminent)
@@ -151,11 +158,50 @@ struct AboutView: View {
151
158
} . padding ( )
152
159
}
153
160
161
+ if isDebug {
162
+ Button {
163
+ update ( debug: false )
164
+ } label: {
165
+ Text ( " Switch to Release " )
166
+ } . disabled (
167
+ viewModel. state == . downloading || viewModel. state == . installing
168
+ )
169
+ } else {
170
+ Button {
171
+ showSwitchToDebug = true
172
+ } label: {
173
+ Text ( " Switch to Debug " )
174
+ } . disabled (
175
+ viewModel. state == . downloading || viewModel. state == . installing
176
+ ) . sheet (
177
+ isPresented: $showSwitchToDebug
178
+ ) {
179
+ VStack {
180
+ Text ( " Switch to debug only if Fctix5 crashes and you want to help debug. " )
181
+ HStack {
182
+ Button {
183
+ showSwitchToDebug = false
184
+ } label: {
185
+ Text ( " Cancel " )
186
+ }
187
+ Button {
188
+ update ( debug: true )
189
+ showSwitchToDebug = false
190
+ } label: {
191
+ Text ( " OK " )
192
+ } . buttonStyle ( . borderedProminent)
193
+ }
194
+ } . padding ( )
195
+ }
196
+ }
197
+
154
198
Button {
155
199
confirmUninstall = true
156
200
} label: {
157
201
Text ( " Uninstall " )
158
- } . sheet (
202
+ } . disabled (
203
+ viewModel. state == . downloading || viewModel. state == . installing
204
+ ) . sheet (
159
205
isPresented: $confirmUninstall
160
206
) {
161
207
VStack {
@@ -272,15 +318,16 @@ struct AboutView: View {
272
318
} . resume ( )
273
319
}
274
320
275
- func update( ) {
321
+ func update( debug : Bool ) {
276
322
viewModel. state = . downloading
277
323
checkPluginUpdate ( { success, nativePlugins, dataPlugins in
278
- let updater = Updater ( main: true , nativePlugins: nativePlugins, dataPlugins: dataPlugins)
324
+ let updater = Updater (
325
+ main: true , debug: debug, nativePlugins: nativePlugins, dataPlugins: dataPlugins)
279
326
updater. update (
280
327
// Install plugin in a best-effort manner. No need to check plugin status.
281
328
onFinish: { result, _, _ in
282
329
if result {
283
- install ( )
330
+ install ( debug : debug )
284
331
} else {
285
332
viewModel. state = . available
286
333
showDownloadFailed = true
@@ -292,7 +339,7 @@ struct AboutView: View {
292
339
} )
293
340
}
294
341
295
- func install( ) {
342
+ func install( debug : Bool ) {
296
343
viewModel. state = . installing
297
344
let conditions = NSMutableDictionary ( )
298
345
conditions. setValue ( " com.apple.keylayout.ABC " , forKey: kTISPropertyInputSourceID as String )
@@ -303,7 +350,7 @@ struct AboutView: View {
303
350
TISSelectInputSource ( inputSource)
304
351
}
305
352
}
306
- let path = cacheDir. appendingPathComponent ( mainFileName) . localPath ( )
353
+ let path = cacheDir. appendingPathComponent ( debug ? mainDebugFileName : mainFileName) . localPath ( )
307
354
// Necessary to put it in background, otherwise sudo UI will hang if it has been canceled once.
308
355
DispatchQueue . global ( ) . async {
309
356
if !sudo( " update " , path, updateLog) {
0 commit comments