Skip to content

Commit

Permalink
Remove the nstroke argument (Issue #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rami-Sabbagh committed Aug 11, 2021
1 parent 1ff8826 commit df8b5f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class Device<TStroke extends Stroke = Stroke> {
return interception.getFilter(this.context, this.id);
}

send(stroke: TStroke, nstroke = 1): boolean {
return interception.send(this.context, this.id, stroke, nstroke);
send(stroke: TStroke): boolean {
return interception.send(this.context, this.id, stroke);
}

receive(nstroke = 1): TStroke | null {
return interception.receive(this.context, this.id, nstroke);
receive(): TStroke | null {
return interception.receive(this.context, this.id);
}

getHardwareId(): string | null {
Expand Down
4 changes: 2 additions & 2 deletions lib/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ export interface InterceptionNative {
/**
* Sends a stroke under a specific device.
*/
send<TStroke extends Stroke>(context: Context, device: DeviceId, stroke: TStroke, nstroke: number): boolean;
send<TStroke extends Stroke>(context: Context, device: DeviceId, stroke: TStroke): boolean;
/**
* Receives the stroke sent by a specific device, after waiting for it using one of the wait methods.
* @returns null on failure.
*/
receive<TStroke extends Stroke>(context: Context, device: DeviceId, nstroke: number): TStroke | null;
receive<TStroke extends Stroke>(context: Context, device: DeviceId): TStroke | null;

/**
* Gets the hardware id of a specific device, which may help on disambiguation of device input.
Expand Down
10 changes: 3 additions & 7 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,19 @@ void unwrapStroke(Env& env, Object& obj, InterceptionStroke& stroke) {
Value Send(const CallbackInfo& info) {
Env env = info.Env();

if (info.Length() < 4) throw TypeError::New(env, "Wrong number of arguments");
if (info.Length() < 3) throw TypeError::New(env, "Wrong number of arguments");
if (!info[0].IsExternal()) throw TypeError::New(env, "Invalid 'context' value");
if (!info[1].IsNumber()) throw TypeError::New(env, "Invalid 'device' value");
if (!info[2].IsObject()) throw TypeError::New(env, "Invalid 'stroke' value");
if (!info[3].IsNumber()) throw TypeError::New(env, "Invalid 'nstroke' value");

InterceptionContext context = *info[0].As<External<InterceptionContext>>().Data();
InterceptionDevice device = info[1].As<Number>().Uint32Value();
InterceptionDevice nstroke = info[3].As<Number>().Uint32Value();

InterceptionStroke stroke;
Object strokeObj = info[2].As<Object>();
unwrapStroke(env, strokeObj, stroke);

int status = interception_send(context, device, &stroke, nstroke);
int status = interception_send(context, device, &stroke, 1);
return Boolean::New(env, status ? true : false);
}

Expand All @@ -272,14 +270,12 @@ Value Receive(const CallbackInfo& info) {
if (info.Length() < 3) throw TypeError::New(env, "Wrong number of arguments");
if (!info[0].IsExternal()) throw TypeError::New(env, "Invalid 'context' value");
if (!info[1].IsNumber()) throw TypeError::New(env, "Invalid 'device' value");
if (!info[2].IsNumber()) throw TypeError::New(env, "Invalid 'nstroke' value");

InterceptionContext context = *info[0].As<External<InterceptionContext>>().Data();
InterceptionDevice device = info[1].As<Number>().Uint32Value();
InterceptionDevice nstroke = info[2].As<Number>().Uint32Value();

InterceptionStroke stroke;
int status = interception_receive(context, device, &stroke, nstroke);
int status = interception_receive(context, device, &stroke, 1);

if (status == 0) return env.Null();
return wrapStroke(env, stroke, device);
Expand Down

0 comments on commit df8b5f4

Please sign in to comment.