node-mac-recorder 2.22.16 → 2.22.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,15 @@
3
3
  const fs = require("fs");
4
4
  const { resolveCursorDisplayInfo } = require("./displayInfo");
5
5
 
6
- const TEXT_INPUT_SAMPLE_MS = 95;
6
+ const IS_ELECTRON = !!(
7
+ process &&
8
+ process.versions &&
9
+ process.versions.electron
10
+ );
11
+
12
+ const TEXT_INPUT_SAMPLE_MS = IS_ELECTRON ? 280 : 95;
13
+
14
+ const TEXT_INPUT_GRACE_MS = IS_ELECTRON ? 3200 : 600;
7
15
 
8
16
  function shouldCaptureCursorSample(lastCapturedData, currentData) {
9
17
  if (!lastCapturedData) {
@@ -78,6 +86,13 @@ function tryAppendTextInput(
78
86
  if (typeof nativeBinding.getTextInputSnapshot !== "function") {
79
87
  return;
80
88
  }
89
+ if (timestamp < TEXT_INPUT_GRACE_MS) {
90
+ return;
91
+ }
92
+ const ct = position.cursorType || "";
93
+ if (ct !== "text" && ct !== "vertical-text") {
94
+ return;
95
+ }
81
96
  const wall = Date.now();
82
97
  if (wall - (recorder._tiSampleWallMs || 0) < TEXT_INPUT_SAMPLE_MS) {
83
98
  return;
@@ -172,6 +187,47 @@ function tryAppendTextInput(
172
187
  }
173
188
  }
174
189
 
190
+ function queueDeferredTextInputSample(
191
+ recorder,
192
+ nativeBinding,
193
+ filepath,
194
+ position,
195
+ timestamp,
196
+ ) {
197
+ if (typeof nativeBinding.getTextInputSnapshot !== "function") {
198
+ return;
199
+ }
200
+ if (timestamp < TEXT_INPUT_GRACE_MS) {
201
+ return;
202
+ }
203
+ const ct = position.cursorType || "";
204
+ if (ct !== "text" && ct !== "vertical-text") {
205
+ return;
206
+ }
207
+ if (recorder._tiDeferredPending) {
208
+ return;
209
+ }
210
+ recorder._tiDeferredPending = true;
211
+ const pos = {
212
+ x: position.x,
213
+ y: position.y,
214
+ cursorType: position.cursorType,
215
+ eventType: position.eventType,
216
+ };
217
+ const ts = timestamp;
218
+ setImmediate(() => {
219
+ recorder._tiDeferredPending = false;
220
+ if (!recorder.cursorCaptureFile || recorder.cursorCaptureFile !== filepath) {
221
+ return;
222
+ }
223
+ try {
224
+ tryAppendTextInput(recorder, nativeBinding, filepath, pos, ts);
225
+ } catch {
226
+ /* ignore */
227
+ }
228
+ });
229
+ }
230
+
175
231
  async function startCursorCapture(recorder, nativeBinding, intervalOrFilepath, options = {}) {
176
232
  let filepath;
177
233
  let interval = 20;
@@ -228,6 +284,7 @@ async function startCursorCapture(recorder, nativeBinding, intervalOrFilepath, o
228
284
  recorder.cursorCaptureSessionTimestamp = recorder.sessionTimestamp;
229
285
  recorder._tiSampleWallMs = 0;
230
286
  recorder._lastTextInputEmitted = null;
287
+ recorder._tiDeferredPending = false;
231
288
 
232
289
  recorder.cursorCaptureInterval = setInterval(() => {
233
290
  try {
@@ -348,7 +405,7 @@ async function startCursorCapture(recorder, nativeBinding, intervalOrFilepath, o
348
405
  recorder.lastCapturedData = { ...cursorData };
349
406
  }
350
407
 
351
- tryAppendTextInput(
408
+ queueDeferredTextInputSample(
352
409
  recorder,
353
410
  nativeBinding,
354
411
  filepath,
@@ -388,6 +445,7 @@ async function stopCursorCapture(recorder) {
388
445
  recorder.cursorDisplayInfo = null;
389
446
  recorder._tiSampleWallMs = 0;
390
447
  recorder._lastTextInputEmitted = null;
448
+ recorder._tiDeferredPending = false;
391
449
 
392
450
  recorder.emit("cursorCaptureStopped");
393
451
  resolve(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mac-recorder",
3
- "version": "2.22.16",
3
+ "version": "2.22.17",
4
4
  "description": "Native macOS screen recording package for Node.js applications",
5
5
  "main": "index.js",
6
6
  "keywords": [