Skip to content

Commit

Permalink
fix: allow single code for --key-bind flag
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki authored Mar 20, 2021
1 parent 8840380 commit 117de63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ import {
} from './ocr';
import { resolveBreachProtocol, captureScreen } from './robot';
import configs from './configs.json';
import { createLogger } from './util';
import { createLogger, options } from './util';

// Default keybind: Ctrl+,(Left Ctrl+NumPad Del)
const argv = minimist(process.argv.slice(2));
const keyBind = argv['key-bind']
? argv['key-bind'].split(',').map(Number)
: [29, 83];
const log = createLogger(false);

log('Loading workers...');

loadWorkers(configs as BreachProtocolFragmentConfig[]).then((workers) => {
log('Done!');

iohook.registerShortcut(keyBind, () => main(workers));
iohook.registerShortcut(options.keyBind, () => main(workers));
iohook.start();
});

Expand Down
22 changes: 22 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import minimist from 'minimist';

export function unique<T>(value: T, index: number, array: T[]) {
return array.indexOf(value) === index;
}
Expand Down Expand Up @@ -42,3 +44,23 @@ export class Point {
export function createLogger(enable = false) {
return (...args: any[]) => (enable ? console.log.apply(this, args) : null);
}

function parseOptions(args: string[]) {
const argv = minimist(args, {
string: ['key-bind'],
});

// Default key bind: Ctrl+, (Left Ctrl+NumPad Dot)
// Table with key codes: https://github.com/torvalds/linux/blob/8b12a62a4e3ed4ae99c715034f557eb391d6b196/include/uapi/linux/input-event-codes.h#L65
let keyBind = [29, 83];

if (argv['key-bind']) {
keyBind = argv['key-bind'].split(',').filter(Boolean).map(Number);
}

return {
keyBind,
};
}

export const options = parseOptions(process.argv.slice(2));

0 comments on commit 117de63

Please sign in to comment.