From 41f42fc37435e81378454b8b481eca936d5d19a1 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Mon, 29 Aug 2022 22:17:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=9B=9E=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=E8=AE=B0=E5=BD=95=E6=96=B9=E5=BC=8F=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E8=AE=B0=E5=BD=95=E5=89=AA=E8=B4=B4?= =?UTF-8?q?=E6=9D=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/public/preload.js b/public/preload.js index f17727c..0bd7a67 100644 --- a/public/preload.js +++ b/public/preload.js @@ -134,31 +134,20 @@ const pbpaste = async () => { }) } -const sleep = async (timeout) => { - return new Promise((res) => { - setTimeout(() => { - res() - }, timeout) - }) -} - const watchClipboard = async (db, fn) => { let prev = db.dataBase.data[0] || {} - const callBack = async () => - pbpaste() - .then((item) => { - item.id = crypto.createHash('md5').update(item.data).digest('hex') - if (item && prev.id != item.id) { - // 剪切板元素 与最近一次复制内容不同 - prev = item - fn(item) - } else { - // 剪切板元素 与上次复制内容相同 - } - }) - .then(() => sleep(250)) - .then(() => callBack()) - callBack() + setInterval(() => { + pbpaste().then((item) => { + item.id = crypto.createHash('md5').update(item.data).digest('hex') + if (item && prev.id != item.id) { + // 剪切板元素 与最近一次复制内容不同 + prev = item + fn(item) + } else { + // 剪切板元素 与上次复制内容相同 + } + }) + }, 250) } const copy = (item) => {