mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-04 04:42:05 -04:00
weather: fix fallback temporarily
This commit is contained in:
@@ -10,14 +10,17 @@ Singleton {
|
||||
id: root
|
||||
|
||||
readonly property bool locationAvailable: DMSService.isConnected && (DMSService.capabilities.length === 0 || DMSService.capabilities.includes("location"))
|
||||
readonly property bool valid: latitude !== 0 || longitude !== 0
|
||||
|
||||
property var latitude: 0.0
|
||||
property var longitude: 0.0
|
||||
|
||||
signal locationChanged(var data)
|
||||
|
||||
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"]
|
||||
|
||||
Component.onCompleted: {
|
||||
console.info("LocationService: Initializing...");
|
||||
getState();
|
||||
}
|
||||
|
||||
@@ -25,27 +28,68 @@ Singleton {
|
||||
target: DMSService
|
||||
|
||||
function onLocationStateUpdate(data) {
|
||||
if (locationAvailable) {
|
||||
handleStateUpdate(data);
|
||||
}
|
||||
if (!locationAvailable)
|
||||
return;
|
||||
handleStateUpdate(data);
|
||||
}
|
||||
}
|
||||
|
||||
function handleStateUpdate(data) {
|
||||
root.latitude = data.latitude;
|
||||
root.longitude = data.longitude;
|
||||
const lat = data.latitude;
|
||||
const lon = data.longitude;
|
||||
if (lat === 0 && lon === 0)
|
||||
return;
|
||||
|
||||
root.locationChanged(data)
|
||||
root.latitude = lat;
|
||||
root.longitude = lon;
|
||||
root.locationChanged(data);
|
||||
}
|
||||
|
||||
function getState() {
|
||||
if (!locationAvailable)
|
||||
if (!locationAvailable) {
|
||||
fetchIPLocation();
|
||||
return;
|
||||
}
|
||||
|
||||
DMSService.sendRequest("location.getState", null, response => {
|
||||
if (response.result) {
|
||||
if (response.result && (response.result.latitude !== 0 || response.result.longitude !== 0)) {
|
||||
handleStateUpdate(response.result);
|
||||
return;
|
||||
}
|
||||
fetchIPLocation();
|
||||
});
|
||||
}
|
||||
|
||||
function fetchIPLocation() {
|
||||
if (root.valid)
|
||||
return;
|
||||
ipLocationFetcher.running = true;
|
||||
}
|
||||
|
||||
Process {
|
||||
id: ipLocationFetcher
|
||||
command: root.lowPriorityCmd.concat(root.curlBaseCmd).concat(["http://ip-api.com/json/"])
|
||||
running: false
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const raw = text.trim();
|
||||
if (!raw || raw[0] !== "{")
|
||||
return;
|
||||
|
||||
try {
|
||||
const data = JSON.parse(raw);
|
||||
if (data.status === "fail")
|
||||
return;
|
||||
|
||||
const lat = parseFloat(data.lat);
|
||||
const lon = parseFloat(data.lon);
|
||||
if (isNaN(lat) || isNaN(lon) || (lat === 0 && lon === 0))
|
||||
return;
|
||||
|
||||
root.handleStateUpdate({ latitude: lat, longitude: lon });
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,6 +512,8 @@ Singleton {
|
||||
}
|
||||
|
||||
function getLocationFromService() {
|
||||
if (!LocationService.valid)
|
||||
return;
|
||||
getLocationFromCoords(LocationService.latitude, LocationService.longitude);
|
||||
}
|
||||
|
||||
@@ -829,9 +831,11 @@ Singleton {
|
||||
target: LocationService
|
||||
|
||||
function onLocationChanged(data) {
|
||||
if (SettingsData.useAutoLocation) {
|
||||
root.getLocationFromCoords(data.latitude, data.longitude)
|
||||
}
|
||||
if (!SettingsData.useAutoLocation)
|
||||
return;
|
||||
if (data.latitude === 0 && data.longitude === 0)
|
||||
return;
|
||||
root.getLocationFromCoords(data.latitude, data.longitude);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user