Merge branch 'b3nj5m1n-autotype-tilingwm' into develop

This commit is contained in:
antelle 2020-05-22 12:25:11 +02:00
commit b715507dd0
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
4 changed files with 26 additions and 17 deletions

View File

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

View File

@ -431,8 +431,8 @@ AutoTypeRunner.prototype.obfuscateOp = function(op) {
op.type = 'group';
};
AutoTypeRunner.prototype.run = function(callback) {
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this));
AutoTypeRunner.prototype.run = function(callback, windowId) {
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this), windowId);
this.emitterState = {
callback,
stack: [],

View File

@ -59,8 +59,13 @@ const ModMap = {
'^^': 'ctrl'
};
const AutoTypeEmitter = function(callback) {
const AutoTypeEmitter = function(callback, windowId) {
this.callback = callback;
if (typeof windowId !== 'undefined' && windowId) {
this.windowParameter = '--window ' + windowId + ' ';
} else {
this.windowParameter = '';
}
this.mod = {};
this.pendingScript = [];
};
@ -76,13 +81,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 ' + ModMap[mod]);
this.pendingScript.push('keydown ' + this.windowParameter + ModMap[mod]);
});
text.split('').forEach(char => {
this.pendingScript.push('key U' + char.charCodeAt(0).toString(16));
this.pendingScript.push(
'key ' + this.windowParameter + 'U' + char.charCodeAt(0).toString(16)
);
});
Object.keys(this.mod).forEach(mod => {
this.pendingScript.push('keyup ' + ModMap[mod]);
this.pendingScript.push('keyup ' + this.windowParameter + ModMap[mod]);
});
this.waitComplete();
};
@ -94,14 +101,16 @@ AutoTypeEmitter.prototype.key = function(key) {
}
key = KeyMap[key].toString(16);
}
this.pendingScript.push('key --clearmodifiers ' + this.modString() + key);
this.pendingScript.push(
'key --clearmodifiers ' + this.windowParameter + this.modString() + key
);
this.callback();
};
AutoTypeEmitter.prototype.copyPaste = function(text) {
this.pendingScript.push('sleep 0.5');
Launcher.setClipboardText(text);
this.pendingScript.push('key --clearmodifiers shift+Insert');
this.pendingScript.push('key --clearmodifiers ' + this.windowParameter + 'shift+Insert');
this.pendingScript.push('sleep 0.5');
this.waitComplete();
};

View File

@ -59,8 +59,8 @@ const AutoType = {
}
},
runAndHandleResult(result) {
this.run(result, err => {
runAndHandleResult(result, windowId) {
this.run(result, windowId, err => {
if (err) {
Alerts.error({
header: Locale.autoTypeError,
@ -74,7 +74,7 @@ const AutoType = {
}
},
run(result, callback) {
run(result, windowId, callback) {
this.running = true;
const sequence = result.sequence || result.entry.getEffectiveAutoTypeSeq();
const context = result.context;
@ -109,7 +109,7 @@ const AutoType = {
}
logger.debug('Complete', logger.ts(ts));
return callback && callback();
});
}, windowId);
});
} catch (ex) {
this.running = false;
@ -187,7 +187,7 @@ const AutoType = {
logger.debug('Error during active window check, something is wrong', err);
return callback(false);
}
if (activeWindowInfo.id !== 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}`
@ -228,7 +228,7 @@ const AutoType = {
const entries = evt.filter.getEntries();
if (entries.length === 1 && AppSettingsModel.directAutotype) {
this.hideWindow(() => {
this.runAndHandleResult({ entry: entries[0] });
this.runAndHandleResult({ entry: entries[0] }, evt.windowInfo.id);
});
return;
}
@ -244,7 +244,7 @@ const AutoType = {
if (result) {
this.activeWindowMatches(evt.windowInfo, (matches, activeWindowInfo) => {
if (matches) {
this.runAndHandleResult(result);
this.runAndHandleResult(result, evt.windowInfo.id);
}
});
}