dateMenu: Only use nearest city when appropriate

Since commit 784c0b7e4 we use the name of the nearest city rather
than the weather station, as the latter tend to have unwieldy
and weird names.

However the nearest city may not be that near after all, in which
case the result is again surprising.

Address this by not using the nearest city name unconditionally, but
only if it appears in the station name.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2468
This commit is contained in:
Florian Müllner 2020-03-28 02:54:14 +01:00 committed by Florian Müllner
parent 793f053309
commit de16fe8dff

View File

@ -397,6 +397,20 @@ class WeatherSection extends St.Button {
layout.attach(label, 0, 0, 1, 1); layout.attach(label, 0, 0, 1, 1);
} }
_findBestLocationName(loc) {
const locName = loc.get_name();
if (loc.get_level() === GWeather.LocationLevel.CITY ||
!loc.has_coords())
return locName;
const world = GWeather.Location.get_world();
const city = world.find_nearest_city(...loc.get_coords());
const cityName = city.get_name();
return locName.includes(cityName) ? cityName : locName;
}
_updateForecasts() { _updateForecasts() {
this._forecastGrid.destroy_all_children(); this._forecastGrid.destroy_all_children();
@ -405,13 +419,8 @@ class WeatherSection extends St.Button {
return; return;
} }
let info = this._weatherClient.info; const { info } = this._weatherClient;
let loc = info.get_location(); this._titleLocation.text = this._findBestLocationName(info.location);
if (loc.get_level() !== GWeather.LocationLevel.CITY && loc.has_coords()) {
let world = GWeather.Location.get_world();
loc = world.find_nearest_city(...loc.get_coords());
}
this._titleLocation.text = loc.get_name();
if (this._weatherClient.loading) { if (this._weatherClient.loading) {
this._setStatusLabel(_("Loading…")); this._setStatusLabel(_("Loading…"));