mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
improve use of haptics core
This commit is contained in:
parent
424680df43
commit
1b5eb7c05c
@ -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)
|
||||
}
|
||||
}
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user