Add delay for network connection checking based on pull request #190.

Many thanks to franglais12 .
merge-requests/218/head
Jens Lody 7 years ago
parent f7ee98d164
commit 835e396cba
  1. 33
      src/extension.js

@ -353,6 +353,11 @@ const OpenweatherMenuButton = new Lang.Class({
this._network_monitor_connection = undefined; this._network_monitor_connection = undefined;
} }
if (this._timeoutCheckConnectionState)
Mainloop.source_remove(this._timeoutCheckConnectionState);
this._timeoutCheckConnectionState = undefined;
if (this._settingsC) { if (this._settingsC) {
this._settings.disconnect(this._settingsC); this._settings.disconnect(this._settingsC);
this._settingsC = undefined; this._settingsC = undefined;
@ -506,17 +511,27 @@ const OpenweatherMenuButton = new Lang.Class({
}, },
_checkConnectionState: function() { _checkConnectionState: function() {
let url = this.getWeatherProviderURL(); if (this._timeoutCheckConnectionState) {
let address = Gio.NetworkAddress.parse_uri(url, 80); Mainloop.source_remove(this._timeoutCheckConnectionState);
let cancellable = Gio.Cancellable.new(); this._timeoutCheckConnectionState = undefined;
}
let interval = 1250;
this._oldConnected = this._connected; this._oldConnected = this._connected;
this._connected = false; this._connected = false;
try {
this._network_monitor.can_reach_async(address, cancellable, Lang.bind(this, this._asyncReadyCallback)); this._timeoutCheckConnectionState = Mainloop.timeout_add(interval, Lang.bind(this, function() {
} catch (err) { let url = this.getWeatherProviderURL();
let title = _("Can not connect to %s").format(url); let address = Gio.NetworkAddress.parse_uri(url, 80);
log(title + '\n' + err.message); let cancellable = Gio.Cancellable.new();
} try {
this._network_monitor.can_reach_async(address, cancellable, Lang.bind(this, this._asyncReadyCallback));
} catch (err) {
let title = _("Can not connect to %s").format(url);
log(title + '\n' + err.message);
}
return false;
}));
}, },
_asyncReadyCallback: function(nm, res) { _asyncReadyCallback: function(nm, res) {

Loading…
Cancel
Save