Avoid multiple calls of weatherprovider url, if the network-changed signal is recieived multiple times for some reasons (probably once per network device).

merge-requests/218/head
Jens Lody 9 years ago
parent 0160a63ad0
commit e96c470dec
  1. 12
      src/extension.js

@ -443,6 +443,7 @@ const OpenweatherMenuButton = new Lang.Class({
let url = this.getWeatherProviderURL(); let url = this.getWeatherProviderURL();
let address = Gio.NetworkAddress.parse_uri(url, 80); let address = Gio.NetworkAddress.parse_uri(url, 80);
let cancellable = Gio.Cancellable.new(); let cancellable = Gio.Cancellable.new();
this._oldConnected = this._connected;
this._connected = false; this._connected = false;
try { try {
this._connected = this._network_monitor.can_reach(address, cancellable); this._connected = this._network_monitor.can_reach(address, cancellable);
@ -452,11 +453,14 @@ const OpenweatherMenuButton = new Lang.Class({
log(title + '\n' + err.message); log(title + '\n' + err.message);
} }
if (this._connected) { if (!this._oldConnected && this._connected) {
if (!this._timeoutForecast) let now = new Date()
this.forecastWeatherCache = undefined; if (_timeCacheCurrentWeather &&
if (!this._timeoutCurrent) (Math.floor(new Date(now - _timeCacheCurrentWeather).getTime() / 1000) > this._refresh_interval_current ))
this.currentWeatherCache = undefined; this.currentWeatherCache = undefined;
if (_timeCacheForecastWeather &&
(Math.floor(new Date(now - _timeCacheForecastWeather).getTime() / 1000) > this._refresh_interval_forecast ))
this.forecastWeatherCache = undefined;
this.parseWeatherCurrent(); this.parseWeatherCurrent();
} }
}, },

Loading…
Cancel
Save