mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-13 00:42:49 -05:00
re-nice weather curl commands
This commit is contained in:
@@ -42,6 +42,9 @@ Singleton {
|
|||||||
property int minFetchInterval: 30000
|
property int minFetchInterval: 30000
|
||||||
property int persistentRetryCount: 0
|
property int persistentRetryCount: 0
|
||||||
|
|
||||||
|
readonly property var lowPriorityCmd: ["nice", "-n", "19", "ionice", "-c3"]
|
||||||
|
readonly property var curlBaseCmd: ["curl", "-sS", "--fail", "--connect-timeout", "3", "--max-time", "6", "--limit-rate", "100k", "--compressed"]
|
||||||
|
|
||||||
property var weatherIcons: ({
|
property var weatherIcons: ({
|
||||||
"0": "clear_day",
|
"0": "clear_day",
|
||||||
"1": "clear_day",
|
"1": "clear_day",
|
||||||
@@ -235,12 +238,13 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLocationFromCoords(lat, lon) {
|
function getLocationFromCoords(lat, lon) {
|
||||||
reverseGeocodeFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 'https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en' -H 'User-Agent: DankMaterialShell Weather Widget'"]
|
const url = "https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en"
|
||||||
|
reverseGeocodeFetcher.command = lowPriorityCmd.concat(curlBaseCmd).concat(["-H", "User-Agent: DankMaterialShell Weather Widget", url])
|
||||||
reverseGeocodeFetcher.running = true
|
reverseGeocodeFetcher.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLocationFromCity(city) {
|
function getLocationFromCity(city) {
|
||||||
cityGeocodeFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 '" + getGeocodingUrl(city) + "'"]
|
cityGeocodeFetcher.command = lowPriorityCmd.concat(curlBaseCmd).concat([getGeocodingUrl(city)])
|
||||||
cityGeocodeFetcher.running = true
|
cityGeocodeFetcher.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +278,8 @@ Singleton {
|
|||||||
|
|
||||||
root.lastFetchTime = now
|
root.lastFetchTime = now
|
||||||
root.weather.loading = true
|
root.weather.loading = true
|
||||||
weatherFetcher.command = ["bash", "-c", "curl -s --connect-timeout 10 --max-time 30 '" + apiUrl + "'"]
|
const weatherCmd = lowPriorityCmd.concat(["curl", "-sS", "--fail", "--connect-timeout", "3", "--max-time", "6", "--limit-rate", "150k", "--compressed"])
|
||||||
|
weatherFetcher.command = weatherCmd.concat([apiUrl])
|
||||||
weatherFetcher.running = true
|
weatherFetcher.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,6 +287,11 @@ Singleton {
|
|||||||
root.lastFetchTime = 0 // Reset throttle
|
root.lastFetchTime = 0 // Reset throttle
|
||||||
fetchWeather()
|
fetchWeather()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nextInterval() {
|
||||||
|
const jitter = Math.floor(Math.random() * 15000) - 7500
|
||||||
|
return Math.max(60000, root.updateInterval + jitter)
|
||||||
|
}
|
||||||
|
|
||||||
function handleWeatherSuccess() {
|
function handleWeatherSuccess() {
|
||||||
root.retryAttempts = 0
|
root.retryAttempts = 0
|
||||||
@@ -312,7 +322,7 @@ Singleton {
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: ipLocationFetcher
|
id: ipLocationFetcher
|
||||||
command: ["curl", "-s", "--connect-timeout", "5", "--max-time", "10", "http://ipinfo.io/json"]
|
command: lowPriorityCmd.concat(curlBaseCmd).concat(["http://ipinfo.io/json"])
|
||||||
running: false
|
running: false
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
@@ -533,12 +543,13 @@ Singleton {
|
|||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: updateTimer
|
id: updateTimer
|
||||||
interval: root.updateInterval
|
interval: nextInterval()
|
||||||
running: root.refCount > 0 && SettingsData.weatherEnabled
|
running: root.refCount > 0 && SettingsData.weatherEnabled
|
||||||
repeat: true
|
repeat: true
|
||||||
triggeredOnStart: true
|
triggeredOnStart: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.fetchWeather()
|
root.fetchWeather()
|
||||||
|
interval = nextInterval()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user