@@ -32,14 +32,6 @@ func disableInputMethod() {
32
32
}
33
33
}
34
34
35
- struct Object : Codable {
36
- let sha : String
37
- }
38
-
39
- struct Tag : Codable {
40
- let object : Object
41
- }
42
-
43
35
enum UpdateState {
44
36
case notChecked // Clickable "Check update"
45
37
case checking // Disabled "Checking"
@@ -56,6 +48,7 @@ struct AboutView: View {
56
48
@State private var downloadProgress = 0.0
57
49
58
50
@State private var showUpToDate = false
51
+ @State private var showSystemNotSupported = false
59
52
@State private var showCheckFailed = false
60
53
@State private var showDownloadFailed = false
61
54
@State private var showInstallFailed = false
@@ -64,6 +57,7 @@ struct AboutView: View {
64
57
@State private var removeUserData = false
65
58
@State private var uninstalling = false
66
59
@State private var uninstallFailed = false
60
+ @State private var targetTag : String ? = nil
67
61
68
62
var body : some View {
69
63
VStack {
@@ -87,7 +81,11 @@ struct AboutView: View {
87
81
}
88
82
89
83
Spacer ( ) . frame ( height: gapSize)
90
- urlButton ( String ( commit. prefix ( 7 ) ) , sourceRepo + " /commit/ " + commit)
84
+ if releaseTag == " latest " {
85
+ urlButton ( String ( commit. prefix ( 7 ) ) , sourceRepo + " /commit/ " + commit)
86
+ } else {
87
+ urlButton ( releaseTag, sourceRepo + " /tree/ " + releaseTag)
88
+ }
91
89
92
90
Spacer ( ) . frame ( height: gapSize)
93
91
Text ( getDate ( ) )
@@ -117,7 +115,7 @@ struct AboutView: View {
117
115
if viewModel. state == . notChecked {
118
116
checkUpdate ( )
119
117
} else if viewModel. state == . available {
120
- update ( debug: isDebug)
118
+ update ( debug: isDebug && targetTag == " latest " )
121
119
}
122
120
} label: {
123
121
if viewModel. state == . notChecked || viewModel. state == . upToDate {
@@ -144,9 +142,15 @@ struct AboutView: View {
144
142
}
145
143
) {
146
144
VStack {
147
- Text ( " Update available " )
145
+ if let tag = targetTag { // Should always be true.
146
+ if tag == " latest " {
147
+ Text ( " Latest (unstable) version available " )
148
+ } else {
149
+ Text ( " Version \( tag) available " )
150
+ }
151
+ }
148
152
Button {
149
- update ( debug: isDebug)
153
+ update ( debug: isDebug && targetTag == " latest " )
150
154
} label: {
151
155
Text ( " Update now " )
152
156
} . buttonStyle ( . borderedProminent)
@@ -164,20 +168,21 @@ struct AboutView: View {
164
168
} label: {
165
169
Text ( " Switch to Release " )
166
170
} . disabled (
167
- viewModel. state == . downloading || viewModel. state == . installing
171
+ targetTag == nil || viewModel. state == . downloading || viewModel. state == . installing
168
172
)
169
173
} else {
170
174
Button {
171
175
showSwitchToDebug = true
172
176
} label: {
173
177
Text ( " Switch to Debug " )
174
178
} . disabled (
175
- viewModel. state == . downloading || viewModel. state == . installing
179
+ targetTag != " latest " || viewModel. state == . downloading
180
+ || viewModel. state == . installing
176
181
) . sheet (
177
182
isPresented: $showSwitchToDebug
178
183
) {
179
184
VStack {
180
- Text ( " Switch to debug only if Fctix5 crashes and you want to help debug. " )
185
+ Text ( " Switch to debug only if Fcitx5 crashes and you want to help debug. " )
181
186
HStack {
182
187
Button {
183
188
showSwitchToDebug = false
@@ -250,6 +255,11 @@ struct AboutView: View {
250
255
displayMode: . hud, type: . complete( Color . green) ,
251
256
title: NSLocalizedString ( " Fcitx5 is up to date " , comment: " " ) )
252
257
}
258
+ . toast ( isPresenting: $showSystemNotSupported) {
259
+ AlertToast (
260
+ displayMode: . hud, type: . error( Color . red) ,
261
+ title: NSLocalizedString ( " Your system version is no longer supported " , comment: " " ) )
262
+ }
253
263
. toast ( isPresenting: $showCheckFailed) {
254
264
AlertToast (
255
265
displayMode: . hud, type: . error( Color . red) ,
@@ -292,37 +302,43 @@ struct AboutView: View {
292
302
}
293
303
294
304
func checkUpdate( ) {
295
- guard
296
- // https://api.github.com/repos/fcitx-contrib/fcitx5-macos/git/ref/tags/latest
297
- // GitHub API may be blocked in China and is unstable in general.
298
- let url = URL (
299
- string: " \( sourceRepo) /releases/download/latest/meta.json " )
300
- else {
301
- return
302
- }
303
305
viewModel. state = . checking
304
- URLSession . shared. dataTask ( with: url) { data, response, error in
305
- if let data = data,
306
- let tag = try ? JSONDecoder ( ) . decode ( Tag . self, from: data)
307
- {
308
- if tag. object. sha == commit {
309
- viewModel. state = . upToDate
310
- showUpToDate = true
311
- } else {
306
+ checkMainUpdate { success, latestCompatible, latest, stable in
307
+ if success {
308
+ if let stable = stable {
309
+ // latest >= stable > current
310
+ targetTag = stable. tag
312
311
viewModel. state = . availableSheet
312
+ } else {
313
+ if !latestCompatible {
314
+ viewModel. state = . upToDate
315
+ showSystemNotSupported = true
316
+ } else if latest == nil {
317
+ // latest == current >= stable
318
+ viewModel. state = . upToDate
319
+ showUpToDate = true
320
+ } else {
321
+ // latest > current >= stable
322
+ targetTag = " latest "
323
+ viewModel. state = . availableSheet
324
+ }
313
325
}
314
326
} else {
315
327
viewModel. state = . notChecked
316
328
showCheckFailed = true
317
329
}
318
- } . resume ( )
330
+ }
319
331
}
320
332
321
333
func update( debug: Bool ) {
334
+ guard let tag = targetTag else {
335
+ FCITX_ERROR ( " Calling update with nil tag " )
336
+ return
337
+ }
322
338
viewModel. state = . downloading
323
- checkPluginUpdate ( { success, nativePlugins, dataPlugins in
339
+ checkPluginUpdate ( tag ) { success, nativePlugins, dataPlugins in
324
340
let updater = Updater (
325
- main: true , debug: debug, nativePlugins: nativePlugins, dataPlugins: dataPlugins)
341
+ tag : tag , main: true , debug: debug, nativePlugins: nativePlugins, dataPlugins: dataPlugins)
326
342
updater. update (
327
343
// Install plugin in a best-effort manner. No need to check plugin status.
328
344
onFinish: { result, _, _ in
@@ -336,7 +352,7 @@ struct AboutView: View {
336
352
onProgress: { progress in
337
353
downloadProgress = progress
338
354
} )
339
- } )
355
+ }
340
356
}
341
357
342
358
func install( debug: Bool ) {
0 commit comments