Addressed requested changes

This commit is contained in:
b3nj4m1n 2020-05-21 19:41:19 +02:00
parent 1ffb45433c
commit 1f83f34e55
5 changed files with 24 additions and 30 deletions

View File

@ -1,14 +1,11 @@
import { Launcher } from 'comp/launcher';
const AutoTypeEmitterFactory = {
create(callback, windowID) {
create(callback, windowId) {
if (Launcher && Launcher.autoTypeSupported) {
const { AutoTypeEmitter } = require('./emitter/auto-type-emitter-' +
Launcher.platform());
if (Launcher.platform() === 'linux') {
return new AutoTypeEmitter(callback, windowID);
}
return new AutoTypeEmitter(callback);
return new AutoTypeEmitter(callback, windowId);
}
return null;
}

View File

@ -1,8 +1,7 @@
import { AutoTypeRunner } from 'auto-type/auto-type-runner';
const AutoTypeParser = function(sequence, windowID) {
const AutoTypeParser = function(sequence) {
this.sequence = sequence;
this.windowID = windowID;
this.ix = 0;
this.states = [];
};
@ -43,7 +42,7 @@ AutoTypeParser.prototype.parse = function() {
if (this.states.length !== 1) {
throw 'Groups count mismatch';
}
return new AutoTypeRunner(this.state().ops, this.windowID);
return new AutoTypeRunner(this.state().ops);
};
AutoTypeParser.prototype.pushState = function() {

View File

@ -9,9 +9,8 @@ const emitterLogger = new Logger(
localStorage.debugAutoType ? Logger.Level.All : Logger.Level.Warn
);
const AutoTypeRunner = function(ops, windowID) {
const AutoTypeRunner = function(ops) {
this.ops = ops;
this.windowID = windowID;
this.pendingResolvesCount = 0;
this.entry = null;
this.now = new Date();
@ -426,8 +425,8 @@ AutoTypeRunner.prototype.obfuscateOp = function(op) {
op.type = 'group';
};
AutoTypeRunner.prototype.run = function(callback) {
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this), this.windowID);
AutoTypeRunner.prototype.run = function(callback, windowId) {
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this), windowId);
this.emitterState = {
callback,
stack: [],

View File

@ -59,9 +59,9 @@ const ModMap = {
'^^': 'ctrl'
};
const AutoTypeEmitter = function(callback, windowID) {
const AutoTypeEmitter = function(callback, windowId) {
this.callback = callback;
this.windowID = windowID;
this.windowId = windowId;
this.mod = {};
this.pendingScript = [];
};
@ -77,15 +77,15 @@ AutoTypeEmitter.prototype.setMod = function(mod, enabled) {
AutoTypeEmitter.prototype.text = function(text) {
this.pendingScript.push('keyup ctrl alt shift t');
Object.keys(this.mod).forEach(mod => {
this.pendingScript.push('keydown --window ' + this.windowID + ' ' + ModMap[mod]);
this.pendingScript.push('keydown --window ' + this.windowId + ' ' + ModMap[mod]);
});
text.split('').forEach(char => {
this.pendingScript.push(
'key --window ' + this.windowID + ' U' + char.charCodeAt(0).toString(16)
'key --window ' + this.windowId + ' U' + char.charCodeAt(0).toString(16)
);
});
Object.keys(this.mod).forEach(mod => {
this.pendingScript.push('keyup --window ' + this.windowID + ' ' + ModMap[mod]);
this.pendingScript.push('keyup --window ' + this.windowId + ' ' + ModMap[mod]);
});
this.waitComplete();
};
@ -98,7 +98,7 @@ AutoTypeEmitter.prototype.key = function(key) {
key = KeyMap[key].toString(16);
}
this.pendingScript.push(
'key --clearmodifiers --window ' + this.windowID + ' ' + this.modString() + key
'key --clearmodifiers --window ' + this.windowId + ' ' + this.modString() + key
);
this.callback();
};
@ -106,7 +106,7 @@ AutoTypeEmitter.prototype.key = function(key) {
AutoTypeEmitter.prototype.copyPaste = function(text) {
this.pendingScript.push('sleep 0.5');
Launcher.setClipboardText(text);
this.pendingScript.push('key --clearmodifiers --window ' + this.windowID + ' shift+Insert');
this.pendingScript.push('key --clearmodifiers --window ' + this.windowId + ' shift+Insert');
this.pendingScript.push('sleep 0.5');
this.waitComplete();
};

View File

@ -79,7 +79,7 @@ const AutoType = {
logger.debug('Start', sequence);
const ts = logger.ts();
try {
const parser = new AutoTypeParser(sequence, this.windowID);
const parser = new AutoTypeParser(sequence);
const runner = parser.parse();
logger.debug('Parsed', this.printOps(runner.ops));
runner.resolve(result.entry, err => {
@ -107,7 +107,7 @@ const AutoType = {
}
logger.debug('Complete', logger.ts(ts));
return callback && callback();
});
}, this.windowId);
});
} catch (ex) {
this.running = false;
@ -169,7 +169,6 @@ const AutoType = {
const urlMatches = urlMatcher.exec(windowInfo.title);
windowInfo.url = urlMatches && urlMatches.length > 0 ? urlMatches[0] : null;
}
this.windowID = windowInfo.id;
logger.debug('Window info', windowInfo.id, windowInfo.title, windowInfo.url);
}
return callback(err, windowInfo);
@ -186,13 +185,14 @@ const AutoType = {
logger.debug('Error during active window check, something is wrong', err);
return callback(false);
}
// if (activeWindowInfo.id !== windowInfo.id) {
// logger.info(
// `Active window doesn't match: ID is different. ` +
// `Expected ${windowInfo.id}, got ${activeWindowInfo.id}`
// );
// return callback(false, activeWindowInfo);
// }
this.windowId = windowInfo.id;
if (activeWindowInfo.id !== windowInfo.id && Launcher.platform() !== 'linux') {
logger.info(
`Active window doesn't match: ID is different. ` +
`Expected ${windowInfo.id}, got ${activeWindowInfo.id}`
);
return callback(false, activeWindowInfo);
}
if (activeWindowInfo.url !== windowInfo.url) {
logger.info(
`Active window doesn't match: url is different. ` +
@ -200,7 +200,6 @@ const AutoType = {
);
return callback(false, activeWindowInfo);
}
this.windowID = windowInfo.id;
logger.info('Active window matches');
callback(true, activeWindowInfo);
});