Skip to content

Commit

Permalink
QRCode // Only throw network broken errors if happened 20 times.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Sep 12, 2024
1 parent 734dad1 commit bd51fe3
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct GetCookieQRCodeView: View {
guard let ticket = viewModel.qrCodeAndTicket?.ticket else { return }
let task = Task { @MainActor [weak viewModel] in
loopTask: while case .automatically = viewModel?.scanningConfirmationStatus {
var counter = 0
guard let viewModel = viewModel else { break loopTask }
do {
let status = try await HoYo.queryQRCodeStatus(
Expand All @@ -68,8 +69,13 @@ struct GetCookieQRCodeView: View {
}
try await Task.sleep(nanoseconds: 3 * 1_000_000_000) // 3sec.
} catch {
viewModel.error = error
break loopTask
if error._code != NSURLErrorNetworkConnectionLost || counter >= 20 {
viewModel.error = error
counter = 0
break loopTask
} else {
counter += 1
}
}
}
viewModel?.scanningConfirmationStatus = .idle
Expand Down

0 comments on commit bd51fe3

Please sign in to comment.