Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify event is not null on touch.js #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 47 additions & 48 deletions lib/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,58 +129,57 @@ const Injector = ObjC.registerClass({

const app = UIApplication.sharedApplication();
const event = app['- _touchesEvent'].call(app);
event['- _clearTouches'].call(event);

const absoluteTime = mach_absolute_time();

const timestamp = [
absoluteTime.shr(32).toNumber(),
absoluteTime.and(0xffffffff).toNumber()
];

touch.setTimestamp_(CFGetSystemUptime());

const eventMask = (phase === UITouchPhaseMoved)
? kIOHIDDigitizerEventPosition
: (kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch);
const isRangeAndTouch = (phase !== UITouchPhaseEnded) ? 1 : 0;

const hidEvent = IOHIDEventCreateDigitizerFingerEvent(
kCFAllocatorDefault,
timestamp,
0,
2,
eventMask,
point[0],
point[1],
0,
0,
0,
isRangeAndTouch,
isRangeAndTouch,
0);

if ('- _setHidEvent:' in touch) {
touch['- _setHidEvent:'].call(touch, hidEvent);
}

event['- _setHIDEvent:'].call(event, hidEvent);
event['- _addTouch:forDelayedDelivery:'].call(event, touch, false);

const pool = NSAutoreleasePool.alloc().init();
try {
app.sendEvent_(event);
} finally {
pool.release();
if (event) {
oleavr marked this conversation as resolved.
Show resolved Hide resolved
event['- _clearTouches'].call(event);
const absoluteTime = mach_absolute_time();

const timestamp = [
absoluteTime.shr(32).toNumber(),
absoluteTime.and(0xffffffff).toNumber()
];

touch.setTimestamp_(CFGetSystemUptime());

const eventMask = (phase === UITouchPhaseMoved)
? kIOHIDDigitizerEventPosition
: (kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch);
const isRangeAndTouch = (phase !== UITouchPhaseEnded) ? 1 : 0;

const hidEvent = IOHIDEventCreateDigitizerFingerEvent(
kCFAllocatorDefault,
timestamp,
0,
2,
eventMask,
point[0],
point[1],
0,
0,
0,
isRangeAndTouch,
isRangeAndTouch,
0);

if ('- _setHidEvent:' in touch) {
touch['- _setHidEvent:'].call(touch, hidEvent);
}

CFRelease(hidEvent);
event['- _setHIDEvent:'].call(event, hidEvent);
event['- _addTouch:forDelayedDelivery:'].call(event, touch, false);

priv.previous = point;
if (isLastTouch) {
touch.release();
priv.touch = null;
const pool = NSAutoreleasePool.alloc().init();
try {
app.sendEvent_(event);
} finally {
pool.release();
CFRelease(hidEvent);
}
}
priv.previous = point;
if (isLastTouch) {
touch.release();
priv.touch = null;
}
}
}
}
Expand Down