mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(location): removed the Tokyo default location, improved flow with the new auto-locate.
This commit is contained in:
@@ -159,7 +159,7 @@
|
||||
"settingsPanelSideBarCardStyle": false
|
||||
},
|
||||
"location": {
|
||||
"name": "Tokyo",
|
||||
"name": "",
|
||||
"weatherEnabled": true,
|
||||
"weatherShowEffects": true,
|
||||
"useFahrenheit": false,
|
||||
|
||||
@@ -2183,15 +2183,6 @@
|
||||
"subTab": 0,
|
||||
"subTabLabel": "common.location"
|
||||
},
|
||||
{
|
||||
"labelKey": "panels.location.location-search-label",
|
||||
"descriptionKey": "panels.location.location-search-description",
|
||||
"widget": "NTextInput",
|
||||
"tab": 17,
|
||||
"tabLabel": "panels.region.title",
|
||||
"subTab": 0,
|
||||
"subTabLabel": "common.location"
|
||||
},
|
||||
{
|
||||
"labelKey": "panels.location.auto-locate-label",
|
||||
"descriptionKey": "panels.location.auto-locate-description",
|
||||
@@ -2201,6 +2192,18 @@
|
||||
"subTab": 0,
|
||||
"subTabLabel": "common.location"
|
||||
},
|
||||
{
|
||||
"labelKey": "panels.location.location-search-label",
|
||||
"descriptionKey": "panels.location.location-search-description",
|
||||
"widget": "NTextInput",
|
||||
"tab": 17,
|
||||
"tabLabel": "panels.region.title",
|
||||
"subTab": 0,
|
||||
"subTabLabel": "common.location",
|
||||
"visibleWhen": [
|
||||
"!Settings.data.location.autoLocate"
|
||||
]
|
||||
},
|
||||
{
|
||||
"labelKey": "panels.location.weather-enabled-label",
|
||||
"descriptionKey": "panels.location.weather-enabled-description",
|
||||
|
||||
@@ -32,7 +32,6 @@ Singleton {
|
||||
readonly property string cacheDir: ensureTrailingSlash(Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/")
|
||||
|
||||
readonly property string settingsFile: Quickshell.env("NOCTALIA_SETTINGS_FILE") || (configDir + "settings.json")
|
||||
readonly property string defaultLocation: "Tokyo"
|
||||
readonly property string defaultAvatar: Quickshell.env("HOME") + "/.face"
|
||||
readonly property string defaultVideosDirectory: Quickshell.env("HOME") + "/Videos"
|
||||
readonly property string defaultWallpapersDirectory: Quickshell.env("HOME") + "/Pictures/Wallpapers"
|
||||
@@ -340,7 +339,7 @@ Singleton {
|
||||
|
||||
// location
|
||||
property JsonObject location: JsonObject {
|
||||
property string name: defaultLocation
|
||||
property string name: ""
|
||||
property bool weatherEnabled: true
|
||||
property bool weatherShowEffects: true
|
||||
property bool useFahrenheit: false
|
||||
|
||||
@@ -51,21 +51,38 @@ ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginS
|
||||
|
||||
NTextInput {
|
||||
Layout.maximumWidth: root.width / 2
|
||||
// Auto-locate
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginM
|
||||
|
||||
NToggle {
|
||||
Layout.fillWidth: true
|
||||
label: I18n.tr("panels.location.auto-locate-label")
|
||||
description: I18n.tr("panels.location.auto-locate-description")
|
||||
checked: Settings.data.location.autoLocate
|
||||
onToggled: checked => Settings.data.location.autoLocate = checked
|
||||
defaultValue: Settings.getDefaultValue("location.autoLocate")
|
||||
}
|
||||
|
||||
NButton {
|
||||
text: I18n.tr("panels.location.geolocate-now-button")
|
||||
icon: "current-location"
|
||||
enabled: !LocationService.isFetchingWeather
|
||||
onClicked: LocationService.geolocateAndApply()
|
||||
}
|
||||
}
|
||||
|
||||
NTextInput {
|
||||
visible: !Settings.data.location.autoLocate
|
||||
Layout.maximumWidth: root.width / 2
|
||||
label: I18n.tr("panels.location.location-search-label")
|
||||
description: I18n.tr("panels.location.location-search-description")
|
||||
text: Settings.data.location.name || Settings.defaultLocation
|
||||
text: Settings.data.location.name
|
||||
placeholderText: I18n.tr("panels.location.location-search-placeholder")
|
||||
onEditingFinished: {
|
||||
// Verify the location has really changed to avoid extra resets
|
||||
var newLocation = text.trim();
|
||||
// If empty, set to default location
|
||||
if (newLocation === "") {
|
||||
newLocation = Settings.defaultLocation;
|
||||
text = Settings.defaultLocation; // Update the input field to show the default
|
||||
}
|
||||
if (newLocation != Settings.data.location.name) {
|
||||
Settings.data.location.name = newLocation;
|
||||
LocationService.resetWeather();
|
||||
@@ -80,28 +97,7 @@ ColumnLayout {
|
||||
}) : ""
|
||||
pointSize: Style.fontSizeS
|
||||
color: Color.mOnSurfaceVariant
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-locate
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginM
|
||||
|
||||
NToggle {
|
||||
Layout.fillWidth: true
|
||||
label: I18n.tr("panels.location.auto-locate-label")
|
||||
description: I18n.tr("panels.location.auto-locate-description")
|
||||
checked: Settings.data.location.autoLocate
|
||||
onToggled: checked => Settings.data.location.autoLocate = checked
|
||||
defaultValue: Settings.getDefaultValue("location.autoLocate")
|
||||
}
|
||||
|
||||
NButton {
|
||||
text: I18n.tr("panels.location.geolocate-now-button")
|
||||
icon: "current-location"
|
||||
enabled: !LocationService.isFetchingWeather
|
||||
onClicked: LocationService.geolocateAndApply()
|
||||
font.italic: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ Singleton {
|
||||
}
|
||||
|
||||
if (isFetchingWeather) {
|
||||
Logger.w("Location", "Location update already in progress");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -176,7 +175,6 @@ Singleton {
|
||||
}
|
||||
|
||||
if (isFetchingWeather) {
|
||||
Logger.w("Location", "Weather is still fetching");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -194,6 +192,11 @@ Singleton {
|
||||
|
||||
// Query geocoding API to convert location name to coordinates
|
||||
function geocodeLocation(locationName, callback, errorCallback) {
|
||||
if (locationName === "") {
|
||||
isFetchingWeather = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.d("Location", "Geocoding location name");
|
||||
var geoUrl = "https://api.noctalia.dev/geocode?city=" + encodeURIComponent(locationName);
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
Reference in New Issue
Block a user