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
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
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);
|
||
},
|
||
};
|
||
}
|