[gnome-shell/wip/fmuellner/calendar-refresh: 5/15] weather: Skip loading indication when updating frequently
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/fmuellner/calendar-refresh: 5/15] weather: Skip loading indication when updating frequently
- Date: Mon, 27 Feb 2017 21:39:05 +0000 (UTC)
commit 8953b93910e63173a230452487c03eb003eb75c9
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Feb 25 01:36:47 2017 +0100
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
js/ui/weather.js | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/js/ui/weather.js b/js/ui/weather.js
index 5a621a2..1e02eb4 100644
--- a/js/ui/weather.js
+++ b/js/ui/weather.js
@@ -2,17 +2,22 @@
const Geoclue = imports.gi.Geoclue;
const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
const GWeather = imports.gi.GWeather;
const Lang = imports.lang;
const Signals = imports.signals;
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({
Name: 'WeatherClient',
_init: function() {
this._loading = false;
+ this._lastUpdate = GLib.DateTime.new_from_unix_local(0);
this._useAutoLocation = false;
this._mostRecentLocation = null;
@@ -28,7 +33,10 @@ const WeatherClient = new Lang.Class({
GWeather.Provider.YR_NO |
GWeather.Provider.OWM;
this._weatherInfo = new GWeather.Info({ enabled_providers: providers });
- this._weatherInfo.connect('updated', () => { this.emit('changed'); });
+ this._weatherInfo.connect('updated', () => {
+ this._lastUpdate = GLib.DateTime.new_now_local();
+ this.emit('changed');
+ });
this._weatherAppMon = new Util.AppSettingsMonitor('org.gnome.Weather.Application.desktop',
'org.gnome.Weather.Application');
@@ -56,7 +64,13 @@ const WeatherClient = new Lang.Class({
},
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() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]