diff --git a/src/modules/ui/ui.ts b/src/modules/ui/ui.ts index eb66a1f..a7486bd 100644 --- a/src/modules/ui/ui.ts +++ b/src/modules/ui/ui.ts @@ -128,19 +128,19 @@ function setupStreamSettingsDialog() { { pref: PrefKey.CONTROLLER_ENABLE_VIBRATION, unsupported: !VibrationManager.supportControllerVibration(), - onChange: VibrationManager.updateGlobalVars, + onChange: () => VibrationManager.updateGlobalVars(), }, { pref: PrefKey.CONTROLLER_DEVICE_VIBRATION, unsupported: !VibrationManager.supportDeviceVibration(), - onChange: VibrationManager.updateGlobalVars, + onChange: () => VibrationManager.updateGlobalVars(), }, (VibrationManager.supportControllerVibration() || VibrationManager.supportDeviceVibration()) && { pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY, unsupported: !VibrationManager.supportDeviceVibration(), - onChange: VibrationManager.updateGlobalVars, + onChange: () => VibrationManager.updateGlobalVars(), }, ], }, diff --git a/src/modules/vibration-manager.ts b/src/modules/vibration-manager.ts index baf91c6..7855f06 100644 --- a/src/modules/vibration-manager.ts +++ b/src/modules/vibration-manager.ts @@ -53,7 +53,7 @@ export class VibrationManager { return !!window.navigator.vibrate; } - static updateGlobalVars() { + static updateGlobalVars(stopVibration: boolean = true) { window.BX_ENABLE_CONTROLLER_VIBRATION = VibrationManager.supportControllerVibration() ? getPref(PrefKey.CONTROLLER_ENABLE_VIBRATION) : false; window.BX_VIBRATION_INTENSITY = getPref(PrefKey.CONTROLLER_VIBRATION_INTENSITY) / 100; @@ -63,7 +63,7 @@ export class VibrationManager { } // Stop vibration - window.navigator.vibrate(0); + stopVibration && window.navigator.vibrate(0); const value = getPref(PrefKey.CONTROLLER_DEVICE_VIBRATION); let enabled; @@ -134,10 +134,10 @@ export class VibrationManager { } static initialSetup() { - window.addEventListener('gamepadconnected', VibrationManager.updateGlobalVars); - window.addEventListener('gamepaddisconnected', VibrationManager.updateGlobalVars); + window.addEventListener('gamepadconnected', e => VibrationManager.updateGlobalVars()); + window.addEventListener('gamepaddisconnected', e => VibrationManager.updateGlobalVars()); - VibrationManager.updateGlobalVars(); + VibrationManager.updateGlobalVars(false); window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => { const dataChannel = (e as any).dataChannel;