import { MiniGamePf } from '../../../mx/tools/MiniGameHostInfo'; /** * 设备震动相关 */ export default class Vibrate { /**开关 */ public static IsEnable = true; /**是否开始震动 */ public static IsStartVibrate = false; /**当前平台 */ public static get Pf() { return MiniGamePf.api(); } /** * 极短震动(微信/抖音 type=light) */ public static vibrateShort(): void { if (this.Pf == null) return; if (!this.IsEnable) return; if (typeof this.Pf.vibrateShort !== 'function') return; if (MiniGamePf.isMy()) { this.Pf.vibrateShort({}); return; } this.Pf.vibrateShort({ type: 'light' }); } /** * 长震动 * @returns */ public static vibrateLong(): void { if (this.Pf == null) return; if (!this.IsEnable) return; this.Pf.vibrateLong(); } /** * 开始持续震动 */ public static startVibrate() { this.IsStartVibrate = true; this.loopVibrate(); } /** * 结束持续震动 */ public static stopVibrate() { this.IsStartVibrate = false; } private static loopVibrate() { this.vibrateShort(); setTimeout(() => { if (this.IsStartVibrate) this.loopVibrate(); }, 30); } }