mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 17:38:31 +00:00
web/haptics: don't use haptics if disabled in settings
This commit is contained in:
parent
8af4c69be3
commit
712318612d
@ -11,7 +11,6 @@ const device = {
|
|||||||
iPhone: false,
|
iPhone: false,
|
||||||
iPad: false,
|
iPad: false,
|
||||||
iOS: false,
|
iOS: false,
|
||||||
modernIOS: false,
|
|
||||||
android: false,
|
android: false,
|
||||||
mobile: false,
|
mobile: false,
|
||||||
},
|
},
|
||||||
@ -26,6 +25,7 @@ const device = {
|
|||||||
supports: {
|
supports: {
|
||||||
share: false,
|
share: false,
|
||||||
directDownload: false,
|
directDownload: false,
|
||||||
|
haptics: false,
|
||||||
},
|
},
|
||||||
userAgent: "sveltekit server",
|
userAgent: "sveltekit server",
|
||||||
}
|
}
|
||||||
@ -55,7 +55,6 @@ if (browser) {
|
|||||||
iPhone,
|
iPhone,
|
||||||
iPad,
|
iPad,
|
||||||
iOS,
|
iOS,
|
||||||
modernIOS,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
device.browser = {
|
device.browser = {
|
||||||
@ -71,6 +70,10 @@ if (browser) {
|
|||||||
device.supports = {
|
device.supports = {
|
||||||
share: navigator.share !== undefined,
|
share: navigator.share !== undefined,
|
||||||
directDownload: !(installed && iOS),
|
directDownload: !(installed && iOS),
|
||||||
|
|
||||||
|
// not sure if vibrations feel the same on android,
|
||||||
|
// so they're enabled only on ios 18+ for now
|
||||||
|
haptics: modernIOS,
|
||||||
};
|
};
|
||||||
|
|
||||||
device.userAgent = navigator.userAgent;
|
device.userAgent = navigator.userAgent;
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
|
import { get } from "svelte/store";
|
||||||
import { device } from "$lib/device";
|
import { device } from "$lib/device";
|
||||||
|
import settings from "$lib/state/settings";
|
||||||
|
|
||||||
// not sure if vibrations feel the same on android,
|
const canUseHaptics = () => {
|
||||||
// so they're enabled only on ios 18+ for now
|
return device.supports.haptics && !get(settings).appearance.disableHaptics;
|
||||||
const useHaptics = device.is.modernIOS;
|
}
|
||||||
|
|
||||||
export const hapticSwitch = () => {
|
export const hapticSwitch = () => {
|
||||||
if (!useHaptics) return;
|
if (!canUseHaptics()) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const label = document.createElement("label");
|
const label = document.createElement("label");
|
||||||
@ -26,7 +28,7 @@ export const hapticSwitch = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const hapticConfirm = () => {
|
export const hapticConfirm = () => {
|
||||||
if (!useHaptics) return;
|
if (!canUseHaptics()) return;
|
||||||
|
|
||||||
hapticSwitch();
|
hapticSwitch();
|
||||||
setTimeout(() => hapticSwitch(), 120);
|
setTimeout(() => hapticSwitch(), 120);
|
||||||
|
Loading…
Reference in New Issue
Block a user