weather: Skip loading indication when updating frequently
Weather conditions - at least as far as online services are concerned - don't usually change in a couple of minutes. So when updating shortly after a previous update, assume the current conditions are still valid and trigger an update without showing a loading indication. This should help a bit with not getting stuck permanently in loading state when on a shitty network. https://bugzilla.gnome.org/show_bug.cgi?id=754031
This commit is contained in:
parent
62606c68b9
commit
0e0caee6ba
@ -2,17 +2,22 @@
|
|||||||
|
|
||||||
const Geoclue = imports.gi.Geoclue;
|
const Geoclue = imports.gi.Geoclue;
|
||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
|
const GLib = imports.gi.GLib;
|
||||||
const GWeather = imports.gi.GWeather;
|
const GWeather = imports.gi.GWeather;
|
||||||
const Lang = imports.lang;
|
const Lang = imports.lang;
|
||||||
const Signals = imports.signals;
|
const Signals = imports.signals;
|
||||||
|
|
||||||
const Util = imports.misc.util;
|
const Util = imports.misc.util;
|
||||||
|
|
||||||
|
// Minimum time between updates to show loading indication
|
||||||
|
const UPDATE_THRESHOLD = 10 * GLib.TIME_SPAN_MINUTE;
|
||||||
|
|
||||||
const WeatherClient = new Lang.Class({
|
const WeatherClient = new Lang.Class({
|
||||||
Name: 'WeatherClient',
|
Name: 'WeatherClient',
|
||||||
|
|
||||||
_init: function() {
|
_init: function() {
|
||||||
this._loading = false;
|
this._loading = false;
|
||||||
|
this._lastUpdate = GLib.DateTime.new_from_unix_local(0);
|
||||||
|
|
||||||
this._useAutoLocation = false;
|
this._useAutoLocation = false;
|
||||||
this._mostRecentLocation = null;
|
this._mostRecentLocation = null;
|
||||||
@ -29,6 +34,7 @@ const WeatherClient = new Lang.Class({
|
|||||||
GWeather.Provider.OWM;
|
GWeather.Provider.OWM;
|
||||||
this._weatherInfo = new GWeather.Info({ enabled_providers: providers });
|
this._weatherInfo = new GWeather.Info({ enabled_providers: providers });
|
||||||
this._weatherInfo.connect_after('updated', () => {
|
this._weatherInfo.connect_after('updated', () => {
|
||||||
|
this._lastUpdate = GLib.DateTime.new_now_local();
|
||||||
this.emit('changed');
|
this.emit('changed');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,7 +64,13 @@ const WeatherClient = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
update: function() {
|
update: function() {
|
||||||
this._loadInfo();
|
let now = GLib.DateTime.new_now_local();
|
||||||
|
// Update without loading indication if the current info is recent enough
|
||||||
|
if (this._weatherInfo.is_valid() &&
|
||||||
|
now.difference(this._lastUpdate) < UPDATE_THRESHOLD)
|
||||||
|
this._weatherInfo.update();
|
||||||
|
else
|
||||||
|
this._loadInfo();
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadInfo: function() {
|
_loadInfo: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user