auto-type emitter impl stub

This commit is contained in:
antelle 2016-04-09 18:07:53 +03:00
parent e35d5eb9ae
commit aa8af8eaa3
4 changed files with 49 additions and 5 deletions

View File

@ -0,0 +1,12 @@
'use strict';
var Launcher = require('../../comp/launcher');
var AutoTypeEmitterImplFactory = {
create: function() {
var AutoTypeEmitterImpl = require('./emitter-impl/auto-type-emitter-impl-' + Launcher.platform());
return new AutoTypeEmitterImpl();
}
};
module.exports = AutoTypeEmitterImplFactory;

View File

@ -1,6 +1,8 @@
'use strict';
var Logger = require('../../util/logger');
var Logger = require('../../util/logger'),
Launcher = require('../launcher'),
AutoTypeEmitterImplFactory = require('./auto-type-emitter-impl-factory');
var logger = new Logger('auto-type-emitter');
logger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.Warn);
@ -8,6 +10,8 @@ logger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.War
var AutoTypeEmitter = function(callback) {
this.callback = callback;
this.mod = {};
this.impl = AutoTypeEmitterImplFactory.create();
this.delay = 0;
};
AutoTypeEmitter.prototype.setMod = function(mod, enabled) {
@ -17,36 +21,39 @@ AutoTypeEmitter.prototype.setMod = function(mod, enabled) {
} else {
delete this.mod[mod];
}
this.impl.setMod(mod, enabled);
};
AutoTypeEmitter.prototype.text = function(text) {
logger.debug('Text', text);
this.callback();
setTimeout(this.impl.text.bind(this.impl, text, this.callback), this.delay);
};
AutoTypeEmitter.prototype.key = function(key) {
logger.debug('Key', key);
this.callback();
setTimeout(this.impl.key.bind(this.impl, key, this.callback), this.delay);
};
AutoTypeEmitter.prototype.wait = function(time) {
logger.debug('Wait', time);
this.callback();
setTimeout(this.callback, time);
};
AutoTypeEmitter.prototype.setDelay = function(delay) {
logger.debug('Set delay', delay);
this.delay = delay || 0;
this.callback();
};
AutoTypeEmitter.prototype.copyText = function(text) {
logger.debug('Copy text', text);
Launcher.setClipboardText(text);
this.callback();
};
AutoTypeEmitter.prototype.waitComplete = function() {
logger.debug('Wait complete');
this.callback();
this.impl.waitComplete(this.callback);
};
module.exports = AutoTypeEmitter;

View File

@ -0,0 +1,21 @@
'use strict';
var AutoTypeEmitterImpl = function() {
};
AutoTypeEmitterImpl.prototype.setMod = function(mod, enabled) {
};
AutoTypeEmitterImpl.prototype.text = function(text, callback) {
callback();
};
AutoTypeEmitterImpl.prototype.key = function(key, callback) {
callback();
};
AutoTypeEmitterImpl.prototype.waitComplete = function(callback) {
callback();
};
module.exports = AutoTypeEmitterImpl;

View File

@ -2,6 +2,7 @@
var Backbone = require('backbone'),
Locale = require('../util/locale');
var Launcher;
if (window.process && window.process.versions && window.process.versions.electron) {
@ -112,6 +113,9 @@ if (window.process && window.process.versions && window.process.versions.electro
},
openWindow: function(opts) {
return this.remReq('app').openWindow(opts);
},
platform: function() {
return process.platform;
}
};
Backbone.on('launcher-exit-request', function() {