From 46028c70653d387800dc14c5763804137528e89e Mon Sep 17 00:00:00 2001 From: VectorShell Date: Sat, 13 Jun 2026 02:16:27 +0000 Subject: [PATCH] feat(pet): single-click petting, simplify multi-click handling - Single click emits pet:clicked. - Double click opens prompt window. - Remove triple-click handling and shorten click timeout. --- apps/desktop/pet-preload.cjs | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/apps/desktop/pet-preload.cjs b/apps/desktop/pet-preload.cjs index e7bda11b..3026c0b2 100644 --- a/apps/desktop/pet-preload.cjs +++ b/apps/desktop/pet-preload.cjs @@ -94,7 +94,7 @@ ipcRenderer.on("openpets:pet-content-state", (_event, state) => { const getInteractiveTarget = (event) => { const target = document.elementFromPoint(event.clientX, event.clientY); - return target && target.closest(".pet-hitbox, .pet-shell, .bubble, .scale-handle"); + return target && target.closest(".pet-hitbox, .pet-shell, .bubble"); }; const reportInteractiveHit = (interactive, source, force = false) => { @@ -140,7 +140,7 @@ ipcRenderer.on("openpets:pet-probe-hit-test", (_event, point) => { const clientX = point.clientX; const clientY = point.clientY; const target = document.elementFromPoint(clientX, clientY); - reportInteractiveHit(Boolean(target && target.closest(".pet-hitbox, .pet-shell, .bubble, .scale-handle")) || dragging || scaling, typeof point.reason === "string" ? point.reason.slice(0, 80) : "probe", true); + reportInteractiveHit(Boolean(target && target.closest(".pet-hitbox, .pet-shell, .bubble")) || dragging || scaling, typeof point.reason === "string" ? point.reason.slice(0, 80) : "probe", true); }); // --- Plugin bubble interactions (actions, inline inputs) ------------------- @@ -187,18 +187,43 @@ const sendPetEvent = (name, payload) => { }; const installPetSenses = () => { + let clickCount = 0; + let clickTimer = null; + let firstClickEvent = null; + + const resetClickTimer = () => { + if (clickTimer) { + clearTimeout(clickTimer); + clickTimer = null; + } + }; + + const flushClicks = () => { + resetClickTimer(); + if (clickCount === 1) { + sendPetEvent("pet:clicked", {}); + } else if (clickCount === 2 && firstClickEvent) { + sendPetEvent("pet:doubleClicked", {}); + requestPromptWindow(firstClickEvent); + } + clickCount = 0; + firstClickEvent = null; + }; + document.addEventListener("click", (event) => { if (event.button !== 0) return; const target = event.target; if (!(target instanceof Element)) return; if (!target.closest(".pet-hitbox, .pet-shell")) return; if (Date.now() < suppressClickUntil) return; - sendPetEvent("pet:clicked", {}); - }); - document.addEventListener("dblclick", (event) => { - const target = event.target; - if (!(target instanceof Element) || !target.closest(".pet-hitbox, .pet-shell")) return; - sendPetEvent("pet:doubleClicked", {}); + + clickCount += 1; + if (clickCount === 1) { + firstClickEvent = event; + } + resetClickTimer(); + + clickTimer = setTimeout(flushClicks, 200); }); document.addEventListener("mouseover", (event) => { const target = event.target; @@ -387,7 +412,6 @@ const installMouseInterop = () => { if (handleBubbleInteraction(event)) return; dismissBubble(event); }); - document.addEventListener("dblclick", requestPromptWindow); installPetSenses(); let dragStartPoint = null; -- 2.45.3