mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-27 15:02:50 -05:00
weather: switch to ip-api for auto location
This commit is contained in:
@@ -322,7 +322,7 @@ Singleton {
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: ipLocationFetcher
|
id: ipLocationFetcher
|
||||||
command: lowPriorityCmd.concat(curlBaseCmd).concat(["http://ipinfo.io/json"])
|
command: lowPriorityCmd.concat(curlBaseCmd).concat(["http://ip-api.com/json/"])
|
||||||
running: false
|
running: false
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
@@ -335,23 +335,17 @@ Singleton {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(raw)
|
const data = JSON.parse(raw)
|
||||||
const coords = data.loc
|
|
||||||
|
if (data.status === "fail") {
|
||||||
|
throw new Error("IP location lookup failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
const lat = parseFloat(data.lat)
|
||||||
|
const lon = parseFloat(data.lon)
|
||||||
const city = data.city
|
const city = data.city
|
||||||
|
|
||||||
if (!coords || !city) {
|
if (!city || isNaN(lat) || isNaN(lon)) {
|
||||||
throw new Error("Missing location data")
|
throw new Error("Missing or invalid location data")
|
||||||
}
|
|
||||||
|
|
||||||
const coordsParts = coords.split(",")
|
|
||||||
if (coordsParts.length !== 2) {
|
|
||||||
throw new Error("Invalid coordinates format")
|
|
||||||
}
|
|
||||||
|
|
||||||
const lat = parseFloat(coordsParts[0])
|
|
||||||
const lon = parseFloat(coordsParts[1])
|
|
||||||
|
|
||||||
if (isNaN(lat) || isNaN(lon)) {
|
|
||||||
throw new Error("Invalid coordinate values")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.location = {
|
root.location = {
|
||||||
|
|||||||
Reference in New Issue
Block a user