mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
Merge pull request #129 from sidorares/cache_extensions
Cache X11 extensions
This commit is contained in:
commit
ba6d6f63a2
2 changed files with 53 additions and 3 deletions
22
lib/xcore.js
22
lib/xcore.js
|
|
@ -114,6 +114,7 @@ XClient.prototype.init = function(stream)
|
||||||
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
||||||
this.eventParsers = {};
|
this.eventParsers = {};
|
||||||
this.errorParsers = {};
|
this.errorParsers = {};
|
||||||
|
this._extensions = {};
|
||||||
|
|
||||||
this.importRequestsFromTemplates(this, coreRequests);
|
this.importRequestsFromTemplates(this, coreRequests);
|
||||||
|
|
||||||
|
|
@ -553,9 +554,24 @@ XClient.prototype.startHandshake = function() {
|
||||||
|
|
||||||
XClient.prototype.require = function(extName, callback)
|
XClient.prototype.require = function(extName, callback)
|
||||||
{
|
{
|
||||||
var ext = require('./ext/' + extName);
|
var self = this;
|
||||||
ext.requireExt(this.display, callback);
|
var ext = this._extensions[extName];
|
||||||
}
|
if (ext) {
|
||||||
|
return process.nextTick(function() {
|
||||||
|
callback(null, ext);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ext = require('./ext/' + extName);
|
||||||
|
ext.requireExt(this.display, function(err, _ext) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
self._extensions[extName] = _ext;
|
||||||
|
callback(null, _ext);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.createClient = function(options, initCb)
|
module.exports.createClient = function(options, initCb)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
34
test/cache-extensions.js
Normal file
34
test/cache-extensions.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
var x11 = require('../lib');
|
||||||
|
var should = require('should');
|
||||||
|
|
||||||
|
describe('requiring an X11 extension on same connection', function() {
|
||||||
|
before(function(done) {
|
||||||
|
var self = this;
|
||||||
|
var client = x11.createClient(function(err, dpy) {
|
||||||
|
should.not.exist(err);
|
||||||
|
self.X = dpy.client;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', function (err) {
|
||||||
|
console.error('Error : ', err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be cached', function(done) {
|
||||||
|
var self = this;
|
||||||
|
this.X.require('xtest', function(err, randr) {
|
||||||
|
should.not.exist(err);
|
||||||
|
self.X.require('xtest', function(err, randr1) {
|
||||||
|
should.not.exist(err);
|
||||||
|
randr.should.equal(randr1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
this.X.terminate();
|
||||||
|
this.X.on('end', done);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue