mirror of https://github.com/keeweb/keeweb
fix mac runner
parent
673094c1c3
commit
2f0b16d40c
|
@ -19,6 +19,7 @@ var AutoType = {
|
|||
enabled: !!Launcher,
|
||||
selectEntryView: false,
|
||||
pendingEvent: null,
|
||||
running: false,
|
||||
|
||||
init(appModel) {
|
||||
if (!this.enabled) {
|
||||
|
@ -32,6 +33,10 @@ var AutoType = {
|
|||
handleEvent(e) {
|
||||
let entry = e && e.entry || null;
|
||||
logger.debug('Auto type event', entry);
|
||||
if (this.running) {
|
||||
logger.debug('Already running, skipping event');
|
||||
return;
|
||||
}
|
||||
if (entry) {
|
||||
this.hideWindow(() => { this.runAndHandleResult(entry); });
|
||||
} else {
|
||||
|
@ -61,6 +66,7 @@ var AutoType = {
|
|||
},
|
||||
|
||||
run(entry, callback) {
|
||||
this.running = true;
|
||||
var sequence = entry.getEffectiveAutoTypeSeq();
|
||||
logger.debug('Start', sequence);
|
||||
var ts = logger.ts();
|
||||
|
@ -70,6 +76,7 @@ var AutoType = {
|
|||
logger.debug('Parsed', this.printOps(runner.ops));
|
||||
runner.resolve(entry, err => {
|
||||
if (err) {
|
||||
this.running = false;
|
||||
logger.error('Resolve error', err);
|
||||
return callback && callback(err);
|
||||
}
|
||||
|
@ -78,12 +85,14 @@ var AutoType = {
|
|||
try {
|
||||
runner.obfuscate();
|
||||
} catch (e) {
|
||||
this.running = false;
|
||||
logger.error('Obfuscate error', e);
|
||||
return callback && callback(e);
|
||||
}
|
||||
logger.debug('Obfuscated');
|
||||
}
|
||||
runner.run(err => {
|
||||
this.running = false;
|
||||
if (err) {
|
||||
logger.error('Run error', err);
|
||||
return callback && callback(err);
|
||||
|
@ -93,6 +102,7 @@ var AutoType = {
|
|||
});
|
||||
});
|
||||
} catch (ex) {
|
||||
this.running = false;
|
||||
logger.error('Parse error', ex);
|
||||
return callback && callback(ex);
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -8,5 +8,6 @@
|
|||
+ (void)keyPress:(unichar)ch code:(CGKeyCode)code flags:(CGEventFlags)flags;
|
||||
+ (void)keyUpDown:(unichar)ch code:(CGKeyCode)code flags:(CGEventFlags)flags down:(bool)down;
|
||||
+ (void)keyModUpDown:(CGEventFlags)flags down:(bool)down;
|
||||
+ (void)validateSystemState;
|
||||
|
||||
@end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@implementation KeyRunner
|
||||
|
||||
CGEventSourceRef eventSource = nil;
|
||||
bool keyboardStateIsValid = false;
|
||||
|
||||
+ (void)initialize {
|
||||
eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
|
@ -29,6 +30,7 @@ CGEventSourceRef eventSource = nil;
|
|||
}
|
||||
|
||||
+ (void)keyUpDown:(unichar)ch code:(CGKeyCode)code flags:(CGEventFlags)flags down:(bool)down {
|
||||
[KeyRunner validateSystemState];
|
||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(eventSource, code, down);
|
||||
if (ch) {
|
||||
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
|
||||
|
@ -40,4 +42,24 @@ CGEventSourceRef eventSource = nil;
|
|||
CFRelease(keyEvent);
|
||||
}
|
||||
|
||||
+ (void)validateSystemState {
|
||||
if (keyboardStateIsValid) {
|
||||
return;
|
||||
}
|
||||
int totalWaitTime = 10 * 1000 * 1000;
|
||||
int loopWaitTime = 10000;
|
||||
while (totalWaitTime > 0) {
|
||||
CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState);
|
||||
if ((flags & (kCGEventFlagMaskCommand | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate | kCGEventFlagMaskControl)) == 0) {
|
||||
keyboardStateIsValid = true;
|
||||
break;
|
||||
}
|
||||
usleep(loopWaitTime);
|
||||
totalWaitTime -= loopWaitTime;
|
||||
}
|
||||
if (!keyboardStateIsValid) {
|
||||
exit(8);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue