This commit is contained in:
2026-09-12 13:59:12 +08:00
commit 941ce4baab
71 changed files with 13037 additions and 0 deletions

25
lib/poll-guard.js Normal file
View File

@@ -0,0 +1,25 @@
'use strict';
/**
* 轮询守卫:决定本 tick 是否进入图片分支。
*
* 背景:默认 pollClipboard 每 tick 都跑 `clipboard.readImage().getBitmap()`
* + sha1剪贴板上有 4K 截图时约 33 MB memcpy + ~40ms。先用 availableFormats()
* 探一下,文本剪贴板直接跳过图片分支,零开销。
*
* 已知残留:当剪贴板确实有大图时仍然每 tick 重哈希。彻底解决需要启发式
* 风险(尺寸相同可能漏抓变更)或订阅 clipboard-sequence-numberElectron
* 不暴露)。本次只做最稳妥的格式守卫。
*
* @param {unknown} formats 来自 clipboard.availableFormats() 的列表
* @returns {boolean} 是否需要读图片
*/
function shouldReadImage(formats) {
if (!Array.isArray(formats)) return false;
for (const f of formats) {
if (typeof f === 'string' && f.startsWith('image/')) return true;
}
return false;
}
module.exports = { shouldReadImage };