improve use of haptics core

This commit is contained in:
SrGooglo 2023-06-14 16:47:32 +00:00
parent 424680df43
commit 1b5eb7c05c
2 changed files with 28 additions and 10 deletions

View File

@ -1,5 +1,12 @@
import Core from "evite/src/core"
const vibrationPatterns = {
light: [10],
medium: [50],
heavy: [80],
error: [100, 30, 100, 30, 100],
}
export default class HapticsCore extends Core {
static refName = "haptics"
static namespace = "haptics"
@ -7,8 +14,12 @@ export default class HapticsCore extends Core {
"settings"
]
static get isGlobalDisabled() {
return app.cores.settings.get("haptic_feedback")
static isGlobalDisabled() {
return app.cores.settings.is("haptic_feedback", false)
}
async onInitialize() {
document.addEventListener("click", this.handleClickEvent)
}
public = {
@ -16,13 +27,25 @@ export default class HapticsCore extends Core {
vibrate: this.vibrate.bind(this),
}
vibrate(...args) {
const disabled = this.isGlobalDisabled
handleClickEvent = (event) => {
const button = event.target.closest("button") || event.target.closest(".ant-btn")
if (button) {
this.vibrate("light")
}
}
vibrate(pattern = "light") {
const disabled = HapticsCore.isGlobalDisabled()
if (disabled) {
return false
}
return navigator.vibrate(...args)
if (typeof pattern === "string") {
pattern = vibrationPatterns[pattern]
}
return navigator.vibrate(pattern)
}
}

View File

@ -3,7 +3,6 @@ import { Howl } from "howler"
import config from "config"
import axios from "axios"
import store from "store"
import { Haptics, ImpactStyle } from "@capacitor/haptics"
export default class SoundCore extends Core {
static refName = "sound"
@ -81,10 +80,6 @@ export default class SoundCore extends Core {
return this.public.useUIAudio(button.getAttribute("aria-checked") === "true" ? "component.slider_down" : "component.slider_up")
}
if (app.cores.settings.get("haptic_feedback")) {
Haptics.impact({ style: ImpactStyle.Light })
}
return this.public.useUIAudio("generic_click")
}
}