mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-24 18:42:09 +02:00

& prevent spamming the copy action along with haptic feedback :3 should probably unify all of this cuz this is really messy
34 lines
828 B
TypeScript
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);
|
|
}
|