mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-29 18:08:28 +00:00

Some checks failed
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
Run tests / check lockfile correctness (push) Has been cancelled
Run tests / web sanity check (push) Has been cancelled
Run tests / api sanity check (push) Has been cancelled
bub fix
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { get } from "svelte/store";
|
|
import { device } from "$lib/device";
|
|
import settings from "$lib/state/settings";
|
|
|
|
const canUseHaptics = () => {
|
|
return device.supports.haptics && !get(settings).accessibility.disableHaptics;
|
|
}
|
|
|
|
export const hapticSwitch = () => {
|
|
if (!canUseHaptics()) 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 (!canUseHaptics()) return;
|
|
|
|
hapticSwitch();
|
|
setTimeout(() => hapticSwitch(), 120);
|
|
}
|
|
|
|
export const hapticError = () => {
|
|
if (!canUseHaptics()) return;
|
|
|
|
hapticSwitch();
|
|
setTimeout(() => hapticSwitch(), 120);
|
|
setTimeout(() => hapticSwitch(), 240);
|
|
}
|