Skip to content

Commit bbf3101

Browse files
committed
fix: latest debug to latest release
1 parent c032d14 commit bbf3101

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

src/config/about.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct AboutView: View {
5959
@State private var uninstallFailed = false
6060
// The value is based on check update, and is only used for upgrading to release.
6161
// If upgrading/switching to debug, always use latest regardless of this value.
62+
// If switching from latest debug to latest release, this value is nil.
6263
@State private var targetTag: String? = nil
6364
// If current version is latest, this is still true (for build type switch).
6465
@State private var latestAvailable = false
@@ -343,7 +344,11 @@ struct AboutView: View {
343344

344345
func update(debug: Bool) {
345346
// See comment of targetTag.
346-
guard let tag = debug && latestAvailable ? "latest" : targetTag else {
347+
guard
348+
let tag = getTag(
349+
currentDebug: isDebug, targetDebug: debug, latestAvailable: latestAvailable,
350+
targetTag: targetTag)
351+
else {
347352
FCITX_ERROR("Calling update with nil tag")
348353
return
349354
}

src/config/tag.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
func getTag(currentDebug: Bool, targetDebug: Bool, latestAvailable: Bool, targetTag: String?)
2+
-> String?
3+
{
4+
if targetDebug && latestAvailable {
5+
return "latest"
6+
}
7+
if targetTag != nil {
8+
return targetTag
9+
}
10+
if currentDebug && !targetDebug && latestAvailable {
11+
return "latest"
12+
}
13+
return nil
14+
}

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ target_compile_options(KeySwift PUBLIC
3636
)
3737
target_link_libraries(KeySwift Keycode)
3838
add_test(NAME KeySwift COMMAND KeySwift)
39+
40+
add_executable(TagSwift testtag.swift
41+
${PROJECT_SOURCE_DIR}/src/config/tag.swift
42+
)
43+
add_test(NAME TagSwift COMMAND TagSwift)

tests/testtag.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Foundation
2+
3+
@_cdecl("main")
4+
func main() -> Int {
5+
// targetTag can be nil, version or latest. When latestAvailable is false, targetTag can't be latest.
6+
// So it's a combination of 2*2*5 = 20 cases.
7+
8+
// Release to Release
9+
// latest >> stable = current
10+
assert(getTag(currentDebug: false, targetDebug: false, latestAvailable: false, targetTag: nil) == nil)
11+
// latest >> stable > current
12+
assert(getTag(currentDebug: false, targetDebug: false, latestAvailable: false, targetTag: "1") == "1")
13+
// latest = current
14+
assert(getTag(currentDebug: false, targetDebug: false, latestAvailable: true, targetTag: nil) == nil)
15+
// stable > current
16+
assert(getTag(currentDebug: false, targetDebug: false, latestAvailable: true, targetTag: "1") == "1")
17+
// latest > current >= stable
18+
assert(getTag(currentDebug: false, targetDebug: false, latestAvailable: true, targetTag: "latest") == "latest")
19+
20+
// Release to Debug
21+
// latest >> stable = current
22+
let _ = getTag(currentDebug: false, targetDebug: true, latestAvailable: false, targetTag: nil) // Switch button not clickable.
23+
// latest >> stable > current
24+
let _ = getTag(currentDebug: false, targetDebug: true, latestAvailable: false, targetTag: "1") // Switch button not clickable.
25+
// latest = current
26+
assert(getTag(currentDebug: false, targetDebug: true, latestAvailable: true, targetTag: nil) == "latest")
27+
// stable > current
28+
assert(getTag(currentDebug: false, targetDebug: true, latestAvailable: true, targetTag: "1") == "latest")
29+
// latest > current >= stable
30+
assert(getTag(currentDebug: false, targetDebug: true, latestAvailable: true, targetTag: "latest") == "latest")
31+
32+
// Debug to Release
33+
// latest >> stable = current
34+
let _ = getTag(currentDebug: true, targetDebug: false, latestAvailable: false, targetTag: nil) // We don't provide debug stable.
35+
// latest >> stable > current
36+
assert(getTag(currentDebug: true, targetDebug: false, latestAvailable: false, targetTag: "1") == "1")
37+
// latest = current
38+
assert(getTag(currentDebug: true, targetDebug: false, latestAvailable: true, targetTag: nil) == "latest")
39+
// stable > current
40+
assert(getTag(currentDebug: true, targetDebug: false, latestAvailable: true, targetTag: "1") == "1")
41+
// latest > current >= stable
42+
assert(getTag(currentDebug: true, targetDebug: false, latestAvailable: true, targetTag: "latest") == "latest")
43+
44+
// Debug to Debug
45+
// latest >> stable = current
46+
let _ = getTag(currentDebug: true, targetDebug: true, latestAvailable: false, targetTag: nil) // We don't provide debug stable.
47+
// latest >> stable > current
48+
let _ = getTag(currentDebug: true, targetDebug: true, latestAvailable: false, targetTag: "1") // Update button not clickable.
49+
// latest = current
50+
let _ = getTag(currentDebug: true, targetDebug: true, latestAvailable: true, targetTag: nil) // Update button not clickable.
51+
// stable > current
52+
assert(getTag(currentDebug: true, targetDebug: true, latestAvailable: true, targetTag: "1") == "latest")
53+
// latest > current >= stable
54+
assert(getTag(currentDebug: true, targetDebug: true, latestAvailable: true, targetTag: "latest") == "latest")
55+
56+
return 0
57+
}

0 commit comments

Comments
 (0)