Scraping: Add configurable URLRequest timeout
Some websites and networks may be slow. Add the option to override the request timeout of 15 seconds for search requests. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
45900d6456
commit
468d89b983
2 changed files with 35 additions and 2 deletions
|
|
@ -375,7 +375,19 @@ class ScrapingViewModel: ObservableObject {
|
|||
return nil
|
||||
}
|
||||
|
||||
let request = URLRequest(url: url, timeoutInterval: 15)
|
||||
var timeout: Double = 15
|
||||
|
||||
let disableRequestTimeout = UserDefaults.standard.bool(forKey: "Behavior.DisableRequestTimeout")
|
||||
if disableRequestTimeout {
|
||||
timeout = Double.infinity
|
||||
} else {
|
||||
let requestTimeoutSecs = UserDefaults.standard.double(forKey: "Behavior.RequestTimeoutSecs")
|
||||
if requestTimeoutSecs != 0 {
|
||||
timeout = requestTimeoutSecs
|
||||
}
|
||||
}
|
||||
|
||||
let request = URLRequest(url: url, timeoutInterval: timeout)
|
||||
|
||||
do {
|
||||
let (data, _) = try await URLSession.shared.data(for: request)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ struct SettingsView: View {
|
|||
|
||||
@AppStorage("Behavior.AutocorrectSearch") var autocorrectSearch = true
|
||||
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText = false
|
||||
@AppStorage("Behavior.DisableRequestTimeout") var disableRequestTimeout = false
|
||||
@AppStorage("Behavior.RequestTimeoutSecs") var requestTimeoutSecs: Double = 15
|
||||
|
||||
@AppStorage("Updates.AutomaticNotifs") var autoUpdateNotifs = true
|
||||
|
||||
|
|
@ -63,7 +65,10 @@ struct SettingsView: View {
|
|||
}
|
||||
}
|
||||
|
||||
Section(header: InlineHeader("Behavior")) {
|
||||
Section(
|
||||
header: InlineHeader("Behavior"),
|
||||
footer: Text("Only disable search timeout if results are slow to fetch")
|
||||
) {
|
||||
Toggle(isOn: $autocorrectSearch) {
|
||||
Text("Autocorrect search")
|
||||
}
|
||||
|
|
@ -71,6 +76,22 @@ struct SettingsView: View {
|
|||
Toggle(isOn: $usesRandomSearchText) {
|
||||
Text("Random searchbar text")
|
||||
}
|
||||
|
||||
Toggle(isOn: $disableRequestTimeout) {
|
||||
Text("Disable search timeout")
|
||||
}
|
||||
|
||||
if !disableRequestTimeout {
|
||||
HStack {
|
||||
Text("Search timeout seconds")
|
||||
|
||||
Spacer()
|
||||
|
||||
TextField("", value: $requestTimeoutSecs, formatter: NumberFormatter())
|
||||
.fixedSize()
|
||||
.keyboardType(.numberPad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: InlineHeader("Plugin management")) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue