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:
parent
5f3abbd6d8
commit
a3654c65a5
2 changed files with 68 additions and 23 deletions
|
@ -23,7 +23,7 @@ function Inspector(controller) {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshTorrents = function () {
|
refreshTorrents = function (callback) {
|
||||||
var fields,
|
var fields,
|
||||||
ids = $.map(data.torrents.slice(0), function (t) {
|
ids = $.map(data.torrents.slice(0), function (t) {
|
||||||
return t.getId();
|
return t.getId();
|
||||||
|
@ -36,7 +36,7 @@ function Inspector(controller) {
|
||||||
$.merge(fields, Torrent.Fields.InfoExtra);
|
$.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) {
|
this.setTorrents = function (torrents) {
|
||||||
var d = data;
|
var d = data,
|
||||||
|
that = this;
|
||||||
|
|
||||||
// update the inspector when a selected torrent's data changes.
|
// update the inspector when a selected torrent's data changes.
|
||||||
$(d.torrents).unbind('dataChanged.inspector');
|
$(d.torrents).unbind('dataChanged.inspector');
|
||||||
|
@ -859,8 +860,17 @@ function Inspector(controller) {
|
||||||
d.torrents = torrents;
|
d.torrents = torrents;
|
||||||
|
|
||||||
// periodically ask for updates to the inspector's torrents
|
// periodically ask for updates to the inspector's torrents
|
||||||
clearInterval(d.refreshInterval);
|
clearTimeout(d.refreshTimeout);
|
||||||
d.refreshInterval = setInterval($.proxy(refreshTorrents, this), 2000);
|
|
||||||
|
function callback() {
|
||||||
|
refreshTorrents(rescheduleTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rescheduleTimeout() {
|
||||||
|
d.refreshTimeout = setTimeout(callback, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
rescheduleTimeout();
|
||||||
refreshTorrents();
|
refreshTorrents();
|
||||||
|
|
||||||
// refresh the inspector's UI
|
// refresh the inspector's UI
|
||||||
|
|
|
@ -113,12 +113,16 @@ Transmission.prototype = {
|
||||||
this.updateButtonsSoon();
|
this.updateButtonsSoon();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadDaemonPrefs: function (async) {
|
loadDaemonPrefs: function (async, callback) {
|
||||||
this.remote.loadDaemonPrefs(function (data) {
|
this.remote.loadDaemonPrefs(function (data) {
|
||||||
var o = data['arguments'];
|
var o = data['arguments'];
|
||||||
Prefs.getClutchPrefs(o);
|
Prefs.getClutchPrefs(o);
|
||||||
this.updateGuiFromSession(o);
|
this.updateGuiFromSession(o);
|
||||||
this.sessionProperties = o;
|
this.sessionProperties = o;
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}, this, async);
|
}, this, async);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -632,14 +636,23 @@ Transmission.prototype = {
|
||||||
|
|
||||||
// turn the periodic ajax session refresh on & off
|
// turn the periodic ajax session refresh on & off
|
||||||
togglePeriodicSessionRefresh: function (enabled) {
|
togglePeriodicSessionRefresh: function (enabled) {
|
||||||
clearInterval(this.sessionInterval);
|
var that = this,
|
||||||
delete this.sessionInterval;
|
msec = 8000;
|
||||||
if (enabled) {
|
|
||||||
var callback = $.proxy(this.loadDaemonPrefs, this);
|
|
||||||
var 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 () {
|
toggleTurtleClicked: function () {
|
||||||
|
@ -829,8 +842,18 @@ Transmission.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTorrents: function (ids, fields) {
|
updateTorrents: function (ids, fields, callback) {
|
||||||
this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
|
var that = this;
|
||||||
|
|
||||||
|
function f(updates, removedIds) {
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
that.updateFromTorrentGet(updates, removedIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.remote.updateTorrents(ids, fields, f);
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshTorrents: function () {
|
refreshTorrents: function () {
|
||||||
|
@ -1676,20 +1699,32 @@ Transmission.prototype = {
|
||||||
|
|
||||||
// turn the periodic ajax stats refresh on & off
|
// turn the periodic ajax stats refresh on & off
|
||||||
togglePeriodicStatsRefresh: function (enabled) {
|
togglePeriodicStatsRefresh: function (enabled) {
|
||||||
clearInterval(this.statsInterval);
|
var that = this,
|
||||||
delete this.statsInterval;
|
msec = 5000;
|
||||||
|
|
||||||
|
function callback() {
|
||||||
|
that.loadDaemonStats(undefined, rescheduleTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rescheduleTimeout() {
|
||||||
|
that.statsTimeout = setTimeout(callback, msec);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(this.statsTimeout);
|
||||||
|
delete this.statsTimeout;
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
var callback = $.proxy(this.loadDaemonStats, this);
|
rescheduleTimeout();
|
||||||
var msec = 5000;
|
}
|
||||||
|
|
||||||
this.statsInterval = setInterval(callback, msec);
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loadDaemonStats: function (async) {
|
loadDaemonStats: function (async, callback) {
|
||||||
this.remote.loadDaemonStats(function (data) {
|
this.remote.loadDaemonStats(function (data) {
|
||||||
this.updateStats(data['arguments']);
|
this.updateStats(data['arguments']);
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}, this, async);
|
}, this, async);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue