buddy-workbench 0.1.97 → 0.1.98
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.
package/package.json
CHANGED
|
@@ -12,6 +12,8 @@ import { readWindowsClipboard } from './windows.js';
|
|
|
12
12
|
|
|
13
13
|
const execFileAsync = promisify(execFile);
|
|
14
14
|
const previewLimit = 2000;
|
|
15
|
+
const macClipboardCommandMaxBuffer = 100 * 1024 * 1024;
|
|
16
|
+
const macClipboardCommandTimeout = 10 * 1000;
|
|
15
17
|
let lastValue = '';
|
|
16
18
|
let lastImageHash = '';
|
|
17
19
|
let suppressImageCaptureUntil = 0;
|
|
@@ -101,7 +103,10 @@ async function getMacClipboardImageData() {
|
|
|
101
103
|
}
|
|
102
104
|
`;
|
|
103
105
|
try {
|
|
104
|
-
const { stdout } = await execFileAsync('osascript', ['-l', 'JavaScript', '-e', jsaScript], {
|
|
106
|
+
const { stdout } = await execFileAsync('osascript', ['-l', 'JavaScript', '-e', jsaScript], {
|
|
107
|
+
timeout: macClipboardCommandTimeout,
|
|
108
|
+
maxBuffer: macClipboardCommandMaxBuffer
|
|
109
|
+
});
|
|
105
110
|
const str = stdout.trim();
|
|
106
111
|
markClipboardSuccess('macOS image clipboard read (osascript)');
|
|
107
112
|
if (!str) return null;
|
|
@@ -140,7 +145,11 @@ if let data = pb.data(forType: .png) {
|
|
|
140
145
|
}
|
|
141
146
|
`;
|
|
142
147
|
try {
|
|
143
|
-
const { stdout } = await execFileAsync('swift', ['-e', swiftCode], {
|
|
148
|
+
const { stdout } = await execFileAsync('swift', ['-e', swiftCode], {
|
|
149
|
+
encoding: 'buffer',
|
|
150
|
+
timeout: macClipboardCommandTimeout,
|
|
151
|
+
maxBuffer: macClipboardCommandMaxBuffer
|
|
152
|
+
});
|
|
144
153
|
if (stdout && stdout.length > 0) {
|
|
145
154
|
markClipboardSuccess('macOS image clipboard read (Swift)');
|
|
146
155
|
swiftClipboardRetryAt = 0;
|
|
@@ -169,7 +178,10 @@ if let data = pb.data(forType: .png) {
|
|
|
169
178
|
"";
|
|
170
179
|
}
|
|
171
180
|
`;
|
|
172
|
-
const { stdout } = await execFileAsync('osascript', ['-l', 'JavaScript', '-e', jsaScript], {
|
|
181
|
+
const { stdout } = await execFileAsync('osascript', ['-l', 'JavaScript', '-e', jsaScript], {
|
|
182
|
+
timeout: macClipboardCommandTimeout,
|
|
183
|
+
maxBuffer: macClipboardCommandMaxBuffer
|
|
184
|
+
});
|
|
173
185
|
const str = stdout.trim();
|
|
174
186
|
if (str) {
|
|
175
187
|
markClipboardSuccess('macOS image clipboard fallback read (osascript)');
|
|
@@ -387,11 +399,11 @@ export async function captureClipboard() {
|
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
401
|
|
|
390
|
-
lastImageHash = hash;
|
|
391
402
|
if (!isDuplicate) {
|
|
392
403
|
try {
|
|
393
404
|
const mozjpegBuf = await compressMozjpeg(imageData.rgbaBuf, imageData.width, imageData.height, 75);
|
|
394
405
|
saveClipboardImage(mozjpegBuf, 'jpg', hash);
|
|
406
|
+
lastImageHash = hash;
|
|
395
407
|
markClipboardSuccess('image compression or save (WASM/JPEG)', 'image save');
|
|
396
408
|
} catch (error) {
|
|
397
409
|
logClipboardError('image compression or save (WASM/JPEG)', error);
|
|
@@ -399,12 +411,15 @@ export async function captureClipboard() {
|
|
|
399
411
|
if (rawBuf) {
|
|
400
412
|
try {
|
|
401
413
|
saveClipboardImage(rawBuf, 'png', hash);
|
|
414
|
+
lastImageHash = hash;
|
|
402
415
|
markClipboardSuccess('raw image save after compression fallback', 'image save');
|
|
403
416
|
} catch (fallbackError) {
|
|
404
417
|
logClipboardError('raw image save after compression fallback', fallbackError);
|
|
405
418
|
}
|
|
406
419
|
}
|
|
407
420
|
}
|
|
421
|
+
} else {
|
|
422
|
+
lastImageHash = hash;
|
|
408
423
|
}
|
|
409
424
|
}
|
|
410
425
|
} else if (imageData.rawBuffer && imageData.rawBuffer.length > 0) {
|
|
@@ -424,14 +439,16 @@ export async function captureClipboard() {
|
|
|
424
439
|
}
|
|
425
440
|
}
|
|
426
441
|
|
|
427
|
-
lastImageHash = hash;
|
|
428
442
|
if (!isDuplicate) {
|
|
429
443
|
try {
|
|
430
444
|
saveClipboardImage(imageData.rawBuffer, 'png', hash);
|
|
445
|
+
lastImageHash = hash;
|
|
431
446
|
markClipboardSuccess('image save');
|
|
432
447
|
} catch (error) {
|
|
433
448
|
logClipboardError('image save', error);
|
|
434
449
|
}
|
|
450
|
+
} else {
|
|
451
|
+
lastImageHash = hash;
|
|
435
452
|
}
|
|
436
453
|
}
|
|
437
454
|
}
|
|
@@ -439,7 +456,22 @@ export async function captureClipboard() {
|
|
|
439
456
|
}
|
|
440
457
|
}
|
|
441
458
|
|
|
442
|
-
export function startClipboardCapture() {
|
|
459
|
+
export function startClipboardCapture() {
|
|
460
|
+
let captureInProgress = false;
|
|
461
|
+
const capture = async () => {
|
|
462
|
+
if (captureInProgress) return;
|
|
463
|
+
captureInProgress = true;
|
|
464
|
+
try {
|
|
465
|
+
await captureClipboard();
|
|
466
|
+
} finally {
|
|
467
|
+
captureInProgress = false;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
void capture();
|
|
472
|
+
const timer = setInterval(() => { void capture(); }, 2000);
|
|
473
|
+
timer.unref();
|
|
474
|
+
}
|
|
443
475
|
|
|
444
476
|
export async function markClipboardCopied(date, id) {
|
|
445
477
|
let targetDate = date;
|