From df8b5f4f6f29b3a8ed49de1d780d85cbeb2ab757 Mon Sep 17 00:00:00 2001 From: Rami Sabbagh Date: Wed, 11 Aug 2021 18:33:24 +0300 Subject: [PATCH] Remove the nstroke argument (Issue #3) --- lib/device.ts | 8 ++++---- lib/native.ts | 4 ++-- src/binding.cc | 10 +++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/device.ts b/lib/device.ts index bc6285a..dc5a4c5 100644 --- a/lib/device.ts +++ b/lib/device.ts @@ -33,12 +33,12 @@ export class Device { 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 { diff --git a/lib/native.ts b/lib/native.ts index 157e3d2..5b38c92 100644 --- a/lib/native.ts +++ b/lib/native.ts @@ -258,12 +258,12 @@ export interface InterceptionNative { /** * Sends a stroke under a specific device. */ - send(context: Context, device: DeviceId, stroke: TStroke, nstroke: number): boolean; + send(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(context: Context, device: DeviceId, nstroke: number): TStroke | null; + receive(context: Context, device: DeviceId): TStroke | null; /** * Gets the hardware id of a specific device, which may help on disambiguation of device input. diff --git a/src/binding.cc b/src/binding.cc index 8c954b6..d902cab 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -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>().Data(); InterceptionDevice device = info[1].As().Uint32Value(); - InterceptionDevice nstroke = info[3].As().Uint32Value(); InterceptionStroke stroke; Object strokeObj = info[2].As(); 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); } @@ -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>().Data(); InterceptionDevice device = info[1].As().Uint32Value(); - InterceptionDevice nstroke = info[2].As().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);