1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 05:55:37 -05:00

weather: general improvements to setting

This commit is contained in:
bbedward
2025-07-28 12:57:59 -04:00
parent 3ca7e3a888
commit 4581544585
3 changed files with 38 additions and 52 deletions

View File

@@ -22,8 +22,8 @@ Singleton {
property bool useFahrenheit: false
property bool nightModeEnabled: false
property string profileImage: ""
property string weatherLocationOverride: "New York, NY"
property bool weatherLocationOverrideEnabled: false
property string weatherLocation: "New York, NY"
property string weatherCoordinates: "40.7128,-74.0060"
property bool showFocusedWindow: true
property bool showWeather: true
property bool showMusic: true
@@ -105,8 +105,8 @@ Singleton {
useFahrenheit = settings.useFahrenheit !== undefined ? settings.useFahrenheit : false;
nightModeEnabled = settings.nightModeEnabled !== undefined ? settings.nightModeEnabled : false;
profileImage = settings.profileImage !== undefined ? settings.profileImage : "";
weatherLocationOverride = settings.weatherLocationOverride !== undefined ? settings.weatherLocationOverride : "New York, NY";
weatherLocationOverrideEnabled = settings.weatherLocationOverrideEnabled !== undefined ? settings.weatherLocationOverrideEnabled : false;
weatherLocation = settings.weatherLocation !== undefined ? settings.weatherLocation : "New York, NY";
weatherCoordinates = settings.weatherCoordinates !== undefined ? settings.weatherCoordinates : "40.7128,-74.0060";
showFocusedWindow = settings.showFocusedWindow !== undefined ? settings.showFocusedWindow : true;
showWeather = settings.showWeather !== undefined ? settings.showWeather : true;
showMusic = settings.showMusic !== undefined ? settings.showMusic : true;
@@ -157,8 +157,8 @@ Singleton {
"useFahrenheit": useFahrenheit,
"nightModeEnabled": nightModeEnabled,
"profileImage": profileImage,
"weatherLocationOverride": weatherLocationOverride,
"weatherLocationOverrideEnabled": weatherLocationOverrideEnabled,
"weatherLocation": weatherLocation,
"weatherCoordinates": weatherCoordinates,
"showFocusedWindow": showFocusedWindow,
"showWeather": showWeather,
"showMusic": showMusic,
@@ -372,14 +372,10 @@ Singleton {
saveSettings();
}
// Weather location override setter
function setWeatherLocationOverride(location) {
weatherLocationOverride = location;
saveSettings();
}
function setWeatherLocationOverrideEnabled(enabled) {
weatherLocationOverrideEnabled = enabled;
// Weather location setter
function setWeatherLocation(displayName, coordinates) {
weatherLocation = displayName;
weatherCoordinates = coordinates;
saveSettings();
}

View File

@@ -114,22 +114,9 @@ ScrollView {
}
}
DankToggle {
width: parent.width
text: "Override Location"
description: "Use a specific location instead of auto-detection"
checked: Prefs.weatherLocationOverrideEnabled
onToggled: (checked) => {
return Prefs.setWeatherLocationOverrideEnabled(checked);
}
}
// Location input - only visible when override is enabled
Column {
width: parent.width
spacing: Theme.spacingS
visible: Prefs.weatherLocationOverrideEnabled
opacity: visible ? 1 : 0
spacing: Theme.spacingXS
StyledText {
text: "Location"
@@ -140,29 +127,12 @@ ScrollView {
DankLocationSearch {
width: parent.width
currentLocation: Prefs.weatherLocationOverride
placeholderText: "Search for a location..."
currentLocation: Prefs.weatherLocation
placeholderText: "New York, NY"
onLocationSelected: (displayName, coordinates) => {
Prefs.setWeatherLocationOverride(coordinates);
Prefs.setWeatherLocation(displayName, coordinates);
}
}
StyledText {
text: "Examples: \"New York\", \"Tokyo\", \"90210\""
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
wrapMode: Text.WordWrap
width: parent.width
}
Behavior on opacity {
NumberAnimation {
duration: Theme.mediumDuration
easing.type: Theme.emphasizedEasing
}
}
}
}

View File

@@ -91,7 +91,7 @@ Singleton {
}
function getWeatherUrl() {
const location = Prefs.weatherLocationOverride || "New York, NY"
const location = Prefs.weatherCoordinates || "40.7128,-74.0060"
const url = `wttr.in/${encodeURIComponent(location)}?format=j1`
console.log("Using location:", location, "URL:", url)
return url
@@ -269,10 +269,30 @@ Singleton {
}
Component.onCompleted: {
// Watch for preference changes to refetch weather
Prefs.weatherLocationOverrideChanged.connect(() => {
Prefs.weatherCoordinatesChanged.connect(() => {
console.log("Weather location changed, force refreshing weather")
Qt.callLater(root.forceRefresh)
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()
})
Prefs.weatherLocationChanged.connect(() => {
console.log("Weather location display name changed")
const currentWeather = Object.assign({}, root.weather)
root.weather = currentWeather
})
}
}