1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 21:45:38 -05:00

weather auto location option

This commit is contained in:
bbedward
2025-08-05 07:34:46 -04:00
parent 4bf525ce0d
commit 54d8ca450f
3 changed files with 46 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ Singleton {
property string profileImage: ""
property string weatherLocation: "New York, NY"
property string weatherCoordinates: "40.7128,-74.0060"
property bool useAutoLocation: false
property bool showLauncherButton: true
property bool showWorkspaceSwitcher: true
property bool showFocusedWindow: true
@@ -149,6 +150,7 @@ Singleton {
profileImage = settings.profileImage !== undefined ? settings.profileImage : "";
weatherLocation = settings.weatherLocation !== undefined ? settings.weatherLocation : "New York, NY";
weatherCoordinates = settings.weatherCoordinates !== undefined ? settings.weatherCoordinates : "40.7128,-74.0060";
useAutoLocation = settings.useAutoLocation !== undefined ? settings.useAutoLocation : false;
showLauncherButton = settings.showLauncherButton !== undefined ? settings.showLauncherButton : true;
showWorkspaceSwitcher = settings.showWorkspaceSwitcher !== undefined ? settings.showWorkspaceSwitcher : true;
showFocusedWindow = settings.showFocusedWindow !== undefined ? settings.showFocusedWindow : true;
@@ -230,6 +232,7 @@ Singleton {
"profileImage": profileImage,
"weatherLocation": weatherLocation,
"weatherCoordinates": weatherCoordinates,
"useAutoLocation": useAutoLocation,
"showLauncherButton": showLauncherButton,
"showWorkspaceSwitcher": showWorkspaceSwitcher,
"showFocusedWindow": showFocusedWindow,
@@ -568,6 +571,11 @@ Singleton {
saveSettings();
}
function setAutoLocation(enabled) {
useAutoLocation = enabled;
saveSettings();
}
// Network preference setter
function setNetworkPreference(preference) {
networkPreference = preference;

View File

@@ -111,9 +111,20 @@ ScrollView {
}
}
DankToggle {
width: parent.width
text: "Auto Location"
description: "Allow wttr.in to determine location based on IP address"
checked: Prefs.useAutoLocation
onToggled: (checked) => {
return Prefs.setAutoLocation(checked);
}
}
Column {
width: parent.width
spacing: Theme.spacingXS
visible: !Prefs.useAutoLocation
StyledText {
text: "Location"

View File

@@ -92,9 +92,15 @@ Singleton {
}
function getWeatherUrl() {
if (Prefs.useAutoLocation) {
const url = "wttr.in/?format=j1"
console.log("Using auto location, URL:", url)
return url
}
const location = Prefs.weatherCoordinates || "40.7128,-74.0060"
const url = `wttr.in/${encodeURIComponent(location)}?format=j1`
console.log("Using location:", location, "URL:", url)
console.log("Using manual location:", location, "URL:", url)
return url
}
@@ -310,5 +316,25 @@ Singleton {
const currentWeather = Object.assign({}, root.weather)
root.weather = currentWeather
})
Prefs.useAutoLocationChanged.connect(() => {
console.log("Auto location setting changed, force refreshing weather")
root.weather = {
available: false,
loading: true,
temp: 0,
tempF: 0,
city: "",
wCode: "113",
humidity: 0,
wind: "",
sunrise: "06:00",
sunset: "18:00",
uv: 0,
pressure: 0
}
root.lastFetchTime = 0
root.forceRefresh()
})
}
}