cobalt/web/src/lib/haptics.ts
wukko 0d3044c5e6
web: add haptics for all copy actions
& prevent spamming the copy action along with haptic feedback :3

should probably unify all of this cuz this is really messy
2025-03-05 18:07:46 +06:00

34 lines
828 B
TypeScript

import { device } from "$lib/device";
// not sure if vibrations feel the same on android,
// so they're enabled only on ios 18+ for now
const useHaptics = device.is.modernIOS;
export const hapticSwitch = () => {
if (!useHaptics) return;
try {
const label = document.createElement("label");
label.ariaHidden = "true";
label.style.display = "none";
const input = document.createElement("input");
input.type = "checkbox";
input.setAttribute("switch", "");
label.appendChild(input);
document.head.appendChild(label);
label.click();
document.head.removeChild(label);
} catch {
// ignore
}
}
export const hapticConfirm = () => {
if (!useHaptics) return;
hapticSwitch();
setTimeout(() => hapticSwitch(), 120);
}