native auto-type methods

This commit is contained in:
antelle 2021-01-30 14:16:32 +01:00
parent f54b8e00e1
commit 674311cb4b
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 76 additions and 0 deletions

View File

@ -212,6 +212,30 @@ if (Launcher) {
value = NativeModules.makeXoredValue(value);
const decrypted = await ipcRenderer.invoke('hardware-decrypt', value, touchIdPrompt);
return NativeModules.readXoredValue(decrypted);
},
kbdGetActiveWindow(options) {
return this.call('kbd-get-active-window', options);
},
kbdGetActivePid() {
return this.call('kbd-get-active-pid');
},
kbdShowWindow(win) {
return this.call('kbd-show-window', win);
},
kbdText(str) {
return this.call('kbd-text', str);
},
kbdKeyPress(code, modifiers) {
return this.call('kbd-key-press', code, modifiers);
},
kbdShortcut(code, modifiers) {
return this.call('kbd-shortcut', code, modifiers);
}
};

View File

@ -4,6 +4,7 @@ const { reqNative } = require('./scripts/util/req-native');
const YubiKeyVendorIds = [0x1050];
const attachedYubiKeys = [];
let usbListenerRunning = false;
let autoType;
startListener();
@ -100,6 +101,49 @@ const messageHandlers = {
reject(e);
}
});
},
'kbd-get-active-window'(options) {
return getAutoType().activeWindow(options);
},
'kbd-get-active-pid'() {
return getAutoType().activePid();
},
'kbd-show-window'(win) {
return getAutoType().showWindow(win);
},
'kbd-text'(str) {
return getAutoType().text(str);
},
'kbd-key-press'(code, modifiers) {
const { KeyCode, Modifier } = reqNative('keyboard-auto-type');
code = KeyCode[code];
if (!code) {
throw new Error(`Bad code: ${code}`);
}
let modifier = Modifier.None;
if (modifiers) {
for (const mod of modifiers) {
if (!Modifier[mod]) {
throw new Error(`Bad modifier: ${mod}`);
}
modifier |= Modifier[mod];
}
}
return getAutoType().keyPress(code, modifier);
},
'kbd-shortcut'(code) {
const { KeyCode } = reqNative('keyboard-auto-type');
code = KeyCode[code];
if (!code) {
throw new Error(`Bad code: ${code}`);
}
return getAutoType().shortcut(code);
}
};
@ -134,6 +178,14 @@ function reportYubiKeys() {
callback('yubikeys', attachedYubiKeys.length);
}
function getAutoType() {
if (!autoType) {
const keyboardAutoType = reqNative('keyboard-auto-type');
autoType = new keyboardAutoType.AutoType();
}
return autoType;
}
function startListener() {
process.on('message', ({ callId, cmd, args }) => {
Promise.resolve()