Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 505554d

Browse files
authored
Fix bug
1 parent 8132535 commit 505554d

3 files changed

Lines changed: 40 additions & 25 deletions

File tree

Sources/prostore/signing/DownloadSignManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Foundation
33
import Combine
44

5+
@MainActor
56
class DownloadSignManager: ObservableObject {
67
@Published var progress: Double = 0.0
78
@Published var status: String = ""

Sources/prostore/viewModelsAndHelpers/SourcesViewModel.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,32 +178,35 @@ class SourcesViewModel: ObservableObject {
178178
newSourceURL = ""
179179
}
180180

181-
func validateSource(_ source: Source) {
182-
guard let url = source.url else {
183-
validationStates[source.urlString] = .invalid(NSError(domain: "Invalid URL", code: 0, userInfo: nil))
184-
return
181+
func validateSource(_ source: Source) {
182+
guard let url = source.url else {
183+
// Create a placeholder URL for invalid URL strings to store validation state
184+
if let placeholderURL = URL(string: "invalid://" + source.urlString.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!) {
185+
validationStates[placeholderURL] = .invalid(NSError(domain: "Invalid URL", code: 0, userInfo: nil))
185186
}
186-
187-
validationStates[url] = .loading
188-
189-
var request = URLRequest(url: url)
190-
request.setValue("AppTestersListView/1.0 (iOS)", forHTTPHeaderField: "User-Agent")
191-
request.timeoutInterval = 10
192-
193-
URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
194-
DispatchQueue.main.async {
195-
if let error = error {
196-
self?.validationStates[url] = .invalid(error)
197-
} else if let httpResponse = response as? HTTPURLResponse, !(200...299).contains(httpResponse.statusCode) {
198-
let error = NSError(domain: "HTTP Error", code: httpResponse.statusCode, userInfo: nil)
199-
self?.validationStates[url] = .invalid(error)
200-
} else {
201-
self?.validationStates[url] = .valid
202-
}
203-
}
204-
}.resume()
187+
return
205188
}
206189

190+
validationStates[url] = .loading
191+
192+
var request = URLRequest(url: url)
193+
request.setValue("AppTestersListView/1.0 (iOS)", forHTTPHeaderField: "User-Agent")
194+
request.timeoutInterval = 10
195+
196+
URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
197+
DispatchQueue.main.async {
198+
if let error = error {
199+
self?.validationStates[url] = .invalid(error)
200+
} else if let httpResponse = response as? HTTPURLResponse, !(200...299).contains(httpResponse.statusCode) {
201+
let error = NSError(domain: "HTTP Error", code: httpResponse.statusCode, userInfo: nil)
202+
self?.validationStates[url] = .invalid(error)
203+
} else {
204+
self?.validationStates[url] = .valid
205+
}
206+
}
207+
}.resume()
208+
}
209+
207210
func validateAllSources() {
208211
for source in sources {
209212
validateSource(source)

Sources/prostore/views/SourcesManagerView.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ struct SourceRow: View {
143143
let source: SourcesViewModel.Source
144144
@EnvironmentObject var sourcesViewModel: SourcesViewModel
145145

146+
var validationState: SourcesViewModel.ValidationState? {
147+
// Try to get validation state from the actual URL
148+
if let url = source.url {
149+
return sourcesViewModel.validationStates[url]
150+
}
151+
// If URL is invalid, look for placeholder validation state
152+
if let placeholderURL = URL(string: "invalid://" + source.urlString.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!) {
153+
return sourcesViewModel.validationStates[placeholderURL]
154+
}
155+
return nil
156+
}
157+
146158
var body: some View {
147159
HStack {
148160
VStack(alignment: .leading, spacing: 4) {
@@ -152,8 +164,7 @@ struct SourceRow: View {
152164
.lineLimit(2)
153165
.minimumScaleFactor(0.8)
154166

155-
if let url = source.url,
156-
let validationState = sourcesViewModel.validationStates[url] {
167+
if let validationState = validationState {
157168
HStack {
158169
Image(systemName: validationState.icon)
159170
.font(.caption)

0 commit comments

Comments
 (0)