mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-06 00:18:39 +00:00
extend the Deluge.Events class to include support for subscribing to the remote events
This commit is contained in:
parent
daab4aade6
commit
b164fef0c5
2 changed files with 38 additions and 7 deletions
|
@ -39,7 +39,6 @@ Copyright:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
Events = Ext.extend(Ext.util.Observable, {
|
Events = Ext.extend(Ext.util.Observable, {
|
||||||
constructor: function() {
|
constructor: function() {
|
||||||
Events.superclass.constructor.call(this);
|
Events.superclass.constructor.call(this);
|
||||||
|
@ -47,8 +46,39 @@ Copyright:
|
||||||
|
|
||||||
addListener: function(eventName, fn, scope, o) {
|
addListener: function(eventName, fn, scope, o) {
|
||||||
this.addEvents(eventName);
|
this.addEvents(eventName);
|
||||||
|
if (/[A-Z]/.test(eventName.substring(0, 1))) {
|
||||||
|
Deluge.Client.web.register_event_listener(eventName);
|
||||||
|
}
|
||||||
Events.superclass.addListener.call(this, eventName, fn, scope, o);
|
Events.superclass.addListener.call(this, eventName, fn, scope, o);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
poll: function() {
|
||||||
|
Deluge.Client.web.get_events({
|
||||||
|
success: this.onPollSuccess,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
start: function() {
|
||||||
|
this.poll = this.poll.bind(this);
|
||||||
|
this.running = setInterval(this.poll, 2000);
|
||||||
|
this.poll();
|
||||||
|
},
|
||||||
|
|
||||||
|
stop: function() {
|
||||||
|
if (this.running) {
|
||||||
|
clearInterval(this.running);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onPollSuccess: function(events) {
|
||||||
|
if (!events) return;
|
||||||
|
Ext.each(events, function(event) {
|
||||||
|
var name = event[0], args = event[1];
|
||||||
|
args.splice(0, 0, name);
|
||||||
|
this.fireEvent.apply(this, args);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Events.prototype.on = Events.prototype.addListener
|
Events.prototype.on = Events.prototype.addListener
|
||||||
Events.prototype.fire = Events.prototype.fireEvent
|
Events.prototype.fire = Events.prototype.fireEvent
|
||||||
|
|
|
@ -82,6 +82,7 @@ Deluge.UI = {
|
||||||
|
|
||||||
Deluge.Client.on('connected', function(e) {
|
Deluge.Client.on('connected', function(e) {
|
||||||
Deluge.Login.show();
|
Deluge.Login.show();
|
||||||
|
Deluge.Events.start();
|
||||||
}, this, {single: true});
|
}, this, {single: true});
|
||||||
|
|
||||||
this.update = this.update.bind(this);
|
this.update = this.update.bind(this);
|
||||||
|
@ -156,11 +157,11 @@ Deluge.UI = {
|
||||||
* Stop the Deluge UI polling the server and clear the interface.
|
* Stop the Deluge UI polling the server and clear the interface.
|
||||||
*/
|
*/
|
||||||
stop: function() {
|
stop: function() {
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
clearInterval(this.running);
|
clearInterval(this.running);
|
||||||
this.running = false;
|
this.running = false;
|
||||||
Deluge.Torrents.getStore().loadData([]);
|
Deluge.Torrents.getStore().loadData([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue