2022-12-08 19:09:46 -05:00
|
|
|
import Vue from "vue";
|
|
|
|
import { Haptics, ImpactStyle, NotificationType } from "@capacitor/haptics"
|
2022-04-08 18:07:31 -05:00
|
|
|
|
|
|
|
const hapticsImpactHeavy = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.impact({ style: ImpactStyle.Heavy })
|
2022-04-08 18:07:31 -05:00
|
|
|
}
|
2023-01-08 15:32:15 -06:00
|
|
|
Vue.prototype.$hapticsImpactHeavy = hapticsImpactHeavy
|
2022-04-08 18:07:31 -05:00
|
|
|
|
|
|
|
const hapticsImpactMedium = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.impact({ style: ImpactStyle.Medium })
|
2022-04-08 18:07:31 -05:00
|
|
|
}
|
|
|
|
Vue.prototype.$hapticsImpactMedium = hapticsImpactMedium
|
|
|
|
|
|
|
|
const hapticsImpactLight = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.impact({ style: ImpactStyle.Light })
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsImpactLight = hapticsImpactLight
|
|
|
|
|
|
|
|
const hapticsVibrate = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.vibrate()
|
|
|
|
}
|
2023-01-08 15:32:15 -06:00
|
|
|
Vue.prototype.$hapticsVibrate = hapticsVibrate
|
2022-04-08 18:07:31 -05:00
|
|
|
|
|
|
|
const hapticsNotificationSuccess = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.notification({ type: NotificationType.Success })
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsNotificationSuccess = hapticsNotificationSuccess
|
|
|
|
|
|
|
|
const hapticsNotificationWarning = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.notification({ type: NotificationType.Warning })
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsNotificationWarning = hapticsNotificationWarning
|
|
|
|
|
|
|
|
const hapticsNotificationError = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.notification({ type: NotificationType.Error })
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsNotificationError = hapticsNotificationError
|
|
|
|
|
|
|
|
const hapticsSelectionStart = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.selectionStart()
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsSelectionStart = hapticsSelectionStart
|
|
|
|
|
|
|
|
const hapticsSelectionChanged = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.selectionChanged()
|
|
|
|
}
|
2022-04-08 18:07:31 -05:00
|
|
|
Vue.prototype.$hapticsSelectionChanged = hapticsSelectionChanged
|
|
|
|
|
|
|
|
const hapticsSelectionEnd = async () => {
|
2022-12-08 19:09:46 -05:00
|
|
|
await Haptics.selectionEnd()
|
|
|
|
}
|
|
|
|
Vue.prototype.$hapticsSelectionEnd = hapticsSelectionEnd
|
2023-01-08 15:32:15 -06:00
|
|
|
|
|
|
|
export default ({ store }, inject) => {
|
|
|
|
inject('hapticsImpact', () => {
|
|
|
|
const hapticFeedback = store.state.globals.hapticFeedback
|
|
|
|
if (hapticFeedback === 'OFF') return
|
|
|
|
if (hapticFeedback === 'LIGHT') return hapticsImpactLight()
|
|
|
|
if (hapticFeedback === 'MEDIUM') return hapticsImpactMedium()
|
|
|
|
return hapticsImpactHeavy()
|
|
|
|
})
|
|
|
|
}
|