1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 18:25:35 +00:00

Replace setInterval() with setTimeout() for web UI refresh (patch by WGH)

Fixes: TRAC-6031
This commit is contained in:
Mike Gelfand 2017-01-15 11:16:50 +03:00
parent 5f3abbd6d8
commit a3654c65a5
2 changed files with 68 additions and 23 deletions

View file

@ -23,7 +23,7 @@ function Inspector(controller) {
return false;
},
refreshTorrents = function () {
refreshTorrents = function (callback) {
var fields,
ids = $.map(data.torrents.slice(0), function (t) {
return t.getId();
@ -36,7 +36,7 @@ function Inspector(controller) {
$.merge(fields, Torrent.Fields.InfoExtra);
}
data.controller.updateTorrents(ids, fields);
data.controller.updateTorrents(ids, fields, callback);
}
},
@ -851,7 +851,8 @@ function Inspector(controller) {
****/
this.setTorrents = function (torrents) {
var d = data;
var d = data,
that = this;
// update the inspector when a selected torrent's data changes.
$(d.torrents).unbind('dataChanged.inspector');
@ -859,8 +860,17 @@ function Inspector(controller) {
d.torrents = torrents;
// periodically ask for updates to the inspector's torrents
clearInterval(d.refreshInterval);
d.refreshInterval = setInterval($.proxy(refreshTorrents, this), 2000);
clearTimeout(d.refreshTimeout);
function callback() {
refreshTorrents(rescheduleTimeout);
}
function rescheduleTimeout() {
d.refreshTimeout = setTimeout(callback, 2000);
}
rescheduleTimeout();
refreshTorrents();
// refresh the inspector's UI

View file

@ -113,12 +113,16 @@ Transmission.prototype = {
this.updateButtonsSoon();
},
loadDaemonPrefs: function (async) {
loadDaemonPrefs: function (async, callback) {
this.remote.loadDaemonPrefs(function (data) {
var o = data['arguments'];
Prefs.getClutchPrefs(o);
this.updateGuiFromSession(o);
this.sessionProperties = o;
if (callback) {
callback();
}
}, this, async);
},
@ -632,14 +636,23 @@ Transmission.prototype = {
// turn the periodic ajax session refresh on & off
togglePeriodicSessionRefresh: function (enabled) {
clearInterval(this.sessionInterval);
delete this.sessionInterval;
if (enabled) {
var callback = $.proxy(this.loadDaemonPrefs, this);
var msec = 8000;
var that = this,
msec = 8000;
this.sessionInterval = setInterval(callback, msec);
};
function callback() {
that.loadDaemonPrefs(undefined, rescheduleTimeout);
}
function rescheduleTimeout() {
that.sessionTimeout = setTimeout(callback, msec);
}
clearTimeout(this.sessionTimeout);
delete this.sessionTimeout;
if (enabled) {
rescheduleTimeout();
}
},
toggleTurtleClicked: function () {
@ -829,8 +842,18 @@ Transmission.prototype = {
}
},
updateTorrents: function (ids, fields) {
this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
updateTorrents: function (ids, fields, callback) {
var that = this;
function f(updates, removedIds) {
if (callback) {
callback();
}
that.updateFromTorrentGet(updates, removedIds);
}
this.remote.updateTorrents(ids, fields, f);
},
refreshTorrents: function () {
@ -1676,20 +1699,32 @@ Transmission.prototype = {
// turn the periodic ajax stats refresh on & off
togglePeriodicStatsRefresh: function (enabled) {
clearInterval(this.statsInterval);
delete this.statsInterval;
var that = this,
msec = 5000;
function callback() {
that.loadDaemonStats(undefined, rescheduleTimeout);
}
function rescheduleTimeout() {
that.statsTimeout = setTimeout(callback, msec);
}
clearTimeout(this.statsTimeout);
delete this.statsTimeout;
if (enabled) {
var callback = $.proxy(this.loadDaemonStats, this);
var msec = 5000;
this.statsInterval = setInterval(callback, msec);
};
rescheduleTimeout();
}
},
loadDaemonStats: function (async) {
loadDaemonStats: function (async, callback) {
this.remote.loadDaemonStats(function (data) {
this.updateStats(data['arguments']);
if (callback) {
callback();
}
}, this, async);
},