Skip to content

Commit

Permalink
opt: Optimized update checking
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsMEMZ committed Oct 12, 2024
1 parent 902b092 commit 1e0ff27
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
7 changes: 7 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -3591,6 +3591,7 @@
}
},
"Home.update.%@.%@" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
Expand Down Expand Up @@ -8689,6 +8690,9 @@
}
}
}
},
"声音外放" : {

},
"大" : {
"localizations" : {
Expand Down Expand Up @@ -9491,6 +9495,9 @@
}
}
}
},
"版本 %@ 现已可用" : {

},
"状态" : {
"localizations" : {
Expand Down
126 changes: 47 additions & 79 deletions MeowBili/Errors/NetwokFixView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,42 +164,34 @@ struct NetworkFixView: View {
networkState = 1
DarockKit.Network.shared.requestString("https://apple.com.cn") { _, isSuccess in
if isSuccess {
checkDarock()
darockAPIState = 1
DarockKit.Network.shared.requestString("https://api.darock.top") { respStr, isSuccess in
if isSuccess {
if respStr.apiFixed() == "OK" {
darockAPIState = 3
} else {
darockAPIState = 4
}
} else {
darockAPIState = 1
}
bilibiliAPIState = 2
DarockKit.Network.shared.requestString("https://api.bilibili.com/") { _, isSuccess in
if isSuccess {
bilibiliAPIState = 3
} else {
bilibiliAPIState = 2
}
}
isTroubleshooting = false
}
networkState = 3
} else {
networkState = 2
isTroubleshooting = false
}
}
}

func checkDarock() {
darockAPIState = 1
DarockKit.Network.shared.requestString("https://api.darock.top") { respStr, isSuccess in
if isSuccess {
if respStr.apiFixed() == "OK" {
darockAPIState = 3
} else {
darockAPIState = 4
}
} else {
darockAPIState = 1
}
checkBilibili()
}
}

func checkBilibili() {
bilibiliAPIState = 2
DarockKit.Network.shared.requestString("https://api.bilibili.com/") { _, isSuccess in
if isSuccess {
bilibiliAPIState = 3
} else {
bilibiliAPIState = 2
}
}
isTroubleshooting = false
}
}
}, label: {
Text(isTroubleshooting ? "Troubleshoot.troubleshooting" : "Troubleshoot.re-troubleshoot")
Expand Down Expand Up @@ -264,63 +256,39 @@ struct NetworkFixView: View {
networkState = 1
DarockKit.Network.shared.requestString("https://baidu.com") { _, isSuccess in
if isSuccess {
checkDarock()
networkState = 3
} else {
networkState = 2
isTroubleshooting = false
}
}
}
}

/* func checkDarockTest() {
Timer.scheduledTimer(withTimeInterval: 5, repeats: false) { timer in
timer.invalidate()
darockAPIState = 1
DarockKit.Network.shared.requestString("https://baidu.com") { _, isSuccess in
if isSuccess {
darockAPIState = 3
} else {
darockAPIState = 2
isTroubleshooting = false
}
}
}
} */

func checkDarock() {
darockAPIState = 1
DarockKit.Network.shared.requestString("https://api.darock.top") { respStr, isSuccess in
Timer.scheduledTimer(withTimeInterval: 2.5, repeats: false) { timer in
if isSuccess {
if respStr.apiFixed() == "OK" {
darockAPIState = 3
} else {
darockAPIState = 4
darockAPIState = 1
DarockKit.Network.shared.requestString("https://api.darock.top") { respStr, isSuccess in
Timer.scheduledTimer(withTimeInterval: 2.5, repeats: false) { timer in
if isSuccess {
if respStr.apiFixed() == "OK" {
darockAPIState = 3
} else {
darockAPIState = 4
isTroubleshooting = false
}
} else {
darockAPIState = 4
isTroubleshooting = false
}
timer.invalidate()
}
bilibiliAPIState = 2
DarockKit.Network.shared.requestString("https://api.bilibili.com/") { _, isSuccess in
if isSuccess {
bilibiliAPIState = 3
} else {
bilibiliAPIState = 2
}
}
isTroubleshooting = false
}
networkState = 3
} else {
darockAPIState = 4
networkState = 2
isTroubleshooting = false
}
timer.invalidate()
}
checkBilibili()
}

}

func checkBilibili() {
bilibiliAPIState = 2
DarockKit.Network.shared.requestString("https://api.bilibili.com/") { _, isSuccess in
if isSuccess {
bilibiliAPIState = 3
} else {
bilibiliAPIState = 2
}
}
isTroubleshooting = false
}
}
.onDisappear {
Expand Down
55 changes: 34 additions & 21 deletions MeowBili/InMain/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct MainView: View {
@State var isNetworkFixPresented = false
@State var isFirstLoaded = false
@State var newMajorVer = ""
@State var newBuildVer = ""
@State var isNewVerAvailable = false
@State var isShowDisableNewVerTip = false
@State var isLoadingNew = false
@State var isFailedToLoad = false
Expand All @@ -190,24 +190,20 @@ struct MainView: View {
.bold()
})
}
if newMajorVer != "" && newBuildVer != "" {
let nowMajorVer = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let nowBuildVer = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
if (nowMajorVer < newMajorVer || Int(nowBuildVer) ?? 1 < Int(newBuildVer) ?? 1) && updateTipIgnoreVersion != "\(newMajorVer)\(newBuildVer)" {
VStack {
Text("Home.update.\(newMajorVer).\(newBuildVer)")
if isShowDisableNewVerTip {
Text("Home.update.skip")
.font(.system(size: 12))
.foregroundColor(.gray)
}
if newMajorVer != "" && isNewVerAvailable && updateTipIgnoreVersion != newMajorVer {
VStack {
Text("版本 \(newMajorVer) 现已可用")
if isShowDisableNewVerTip {
Text("Home.update.skip")
.font(.system(size: 12))
.foregroundColor(.gray)
}
.onTapGesture {
if isShowDisableNewVerTip {
updateTipIgnoreVersion = "\(newMajorVer)\(newBuildVer)"
} else {
isShowDisableNewVerTip = true
}
}
.onTapGesture {
if isShowDisableNewVerTip {
updateTipIgnoreVersion = newMajorVer
} else {
isShowDisableNewVerTip = true
}
}
}
Expand Down Expand Up @@ -328,9 +324,26 @@ struct MainView: View {
}
}
DarockKit.Network.shared.requestString("https://fapi.darock.top:65535/bili/newver") { respStr, isSuccess in
if isSuccess && respStr.apiFixed().contains("|") {
newMajorVer = String(respStr.apiFixed().split(separator: "|")[0])
newBuildVer = String(respStr.apiFixed().split(separator: "|")[1])
if isSuccess {
let spdVer = respStr.apiFixed().split(separator: ".")
if 3...4 ~= spdVer.count {
newMajorVer = respStr.apiFixed()
if let x = Int(spdVer[0]), let y = Int(spdVer[1]), let z = Int(spdVer[2]) {
if let _url = Bundle.main.url(forResource: "SemanticVersion", withExtension: "drkdatas"),
let currVerSpd = (try? String(contentsOf: _url))?.split(separator: "\n")[0].split(separator: "."),
3...4 ~= currVerSpd.count {
if let cx = Int(currVerSpd[0]), let cy = Int(currVerSpd[1]), let cz = Int(currVerSpd[2]) {
if x > cx {
isNewVerAvailable = true
} else if x == cx && y > cy {
isNewVerAvailable = true
} else if x == cx && y == cy && z > cz {
isNewVerAvailable = true
}
}
}
}
}
}
}
}
Expand Down

0 comments on commit 1e0ff27

Please sign in to comment.