mirror of https://github.com/keeweb/keeweb
Fixed auto-type on tiling wm
parent
489eb5598c
commit
1ffb45433c
|
@ -1,10 +1,13 @@
|
|||
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());
|
||||
if (Launcher.platform() === 'linux') {
|
||||
return new AutoTypeEmitter(callback, windowID);
|
||||
}
|
||||
return new AutoTypeEmitter(callback);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { AutoTypeRunner } from 'auto-type/auto-type-runner';
|
||||
|
||||
const AutoTypeParser = function(sequence) {
|
||||
const AutoTypeParser = function(sequence, windowID) {
|
||||
this.sequence = sequence;
|
||||
this.windowID = windowID;
|
||||
this.ix = 0;
|
||||
this.states = [];
|
||||
};
|
||||
|
@ -42,7 +43,7 @@ AutoTypeParser.prototype.parse = function() {
|
|||
if (this.states.length !== 1) {
|
||||
throw 'Groups count mismatch';
|
||||
}
|
||||
return new AutoTypeRunner(this.state().ops);
|
||||
return new AutoTypeRunner(this.state().ops, this.windowID);
|
||||
};
|
||||
|
||||
AutoTypeParser.prototype.pushState = function() {
|
||||
|
|
|
@ -9,8 +9,9 @@ const emitterLogger = new Logger(
|
|||
localStorage.debugAutoType ? Logger.Level.All : Logger.Level.Warn
|
||||
);
|
||||
|
||||
const AutoTypeRunner = function(ops) {
|
||||
const AutoTypeRunner = function(ops, windowID) {
|
||||
this.ops = ops;
|
||||
this.windowID = windowID;
|
||||
this.pendingResolvesCount = 0;
|
||||
this.entry = null;
|
||||
this.now = new Date();
|
||||
|
@ -426,7 +427,7 @@ AutoTypeRunner.prototype.obfuscateOp = function(op) {
|
|||
};
|
||||
|
||||
AutoTypeRunner.prototype.run = function(callback) {
|
||||
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this));
|
||||
this.emitter = AutoTypeEmitterFactory.create(this.emitNext.bind(this), this.windowID);
|
||||
this.emitterState = {
|
||||
callback,
|
||||
stack: [],
|
||||
|
|
|
@ -59,8 +59,9 @@ const ModMap = {
|
|||
'^^': 'ctrl'
|
||||
};
|
||||
|
||||
const AutoTypeEmitter = function(callback) {
|
||||
const AutoTypeEmitter = function(callback, windowID) {
|
||||
this.callback = callback;
|
||||
this.windowID = windowID;
|
||||
this.mod = {};
|
||||
this.pendingScript = [];
|
||||
};
|
||||
|
@ -76,13 +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 ' + ModMap[mod]);
|
||||
this.pendingScript.push('keydown --window ' + this.windowID + ' ' + ModMap[mod]);
|
||||
});
|
||||
text.split('').forEach(char => {
|
||||
this.pendingScript.push('key U' + char.charCodeAt(0).toString(16));
|
||||
this.pendingScript.push(
|
||||
'key --window ' + this.windowID + ' U' + char.charCodeAt(0).toString(16)
|
||||
);
|
||||
});
|
||||
Object.keys(this.mod).forEach(mod => {
|
||||
this.pendingScript.push('keyup ' + ModMap[mod]);
|
||||
this.pendingScript.push('keyup --window ' + this.windowID + ' ' + ModMap[mod]);
|
||||
});
|
||||
this.waitComplete();
|
||||
};
|
||||
|
@ -94,14 +97,16 @@ AutoTypeEmitter.prototype.key = function(key) {
|
|||
}
|
||||
key = KeyMap[key].toString(16);
|
||||
}
|
||||
this.pendingScript.push('key --clearmodifiers ' + this.modString() + key);
|
||||
this.pendingScript.push(
|
||||
'key --clearmodifiers --window ' + this.windowID + ' ' + 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 --window ' + this.windowID + ' shift+Insert');
|
||||
this.pendingScript.push('sleep 0.5');
|
||||
this.waitComplete();
|
||||
};
|
||||
|
|
|
@ -79,7 +79,7 @@ const AutoType = {
|
|||
logger.debug('Start', sequence);
|
||||
const ts = logger.ts();
|
||||
try {
|
||||
const parser = new AutoTypeParser(sequence);
|
||||
const parser = new AutoTypeParser(sequence, this.windowID);
|
||||
const runner = parser.parse();
|
||||
logger.debug('Parsed', this.printOps(runner.ops));
|
||||
runner.resolve(result.entry, err => {
|
||||
|
@ -169,6 +169,7 @@ 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);
|
||||
|
@ -185,13 +186,13 @@ 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);
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
if (activeWindowInfo.url !== windowInfo.url) {
|
||||
logger.info(
|
||||
`Active window doesn't match: url is different. ` +
|
||||
|
@ -199,6 +200,7 @@ const AutoType = {
|
|||
);
|
||||
return callback(false, activeWindowInfo);
|
||||
}
|
||||
this.windowID = windowInfo.id;
|
||||
logger.info('Active window matches');
|
||||
callback(true, activeWindowInfo);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue