Files
interview-demo-code/frontend/spa/src/composables/useHapticFeedback.js
Nikita Kiselev 0e48b9d56d
Some checks failed
Telegram Mini App Shop Builder / Compute version metadata (push) Has been cancelled
Telegram Mini App Shop Builder / Run Frontend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run Backend tests (push) Has been cancelled
Telegram Mini App Shop Builder / Run PHP_CodeSniffer (push) Has been cancelled
Telegram Mini App Shop Builder / Build module. (push) Has been cancelled
Telegram Mini App Shop Builder / release (push) Has been cancelled
Squashed commit message
2026-03-11 22:17:44 +03:00

40 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {useSettingsStore} from "@/stores/SettingsStore.js";
/**
* Composable для безопасной работы с HapticFeedback
* Проверяет настройку haptic_enabled перед использованием
* @returns {object} Объект с методами haptic feedback, которые безопасно вызываются
*/
export function useHapticFeedback() {
const settings = useSettingsStore();
const haptic = window.Telegram?.WebApp?.HapticFeedback;
// Возвращаем обёртку с методами, которые проверяют настройку при каждом вызове
return {
impactOccurred: (style) => {
// Проверяем настройку при каждом вызове (реактивно)
const isHapticEnabled = settings.haptic_enabled !== false;
if (!haptic || !isHapticEnabled || !haptic.impactOccurred) {
return;
}
haptic.impactOccurred(style);
},
selectionChanged: () => {
// Проверяем настройку при каждом вызове (реактивно)
const isHapticEnabled = settings.haptic_enabled !== false;
if (!haptic || !isHapticEnabled || !haptic.selectionChanged) {
return;
}
haptic.selectionChanged();
},
notificationOccurred: (type) => {
// Проверяем настройку при каждом вызове (реактивно)
const isHapticEnabled = settings.haptic_enabled !== false;
if (!haptic || !isHapticEnabled || !haptic.notificationOccurred) {
return;
}
haptic.notificationOccurred(type);
},
};
}