mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 08:07:18 +02:00
Fix exception with navigator.vibrate() on start up
This commit is contained in:
parent
11ef014c74
commit
057da5b3ea
@ -128,19 +128,19 @@ function setupStreamSettingsDialog() {
|
|||||||
{
|
{
|
||||||
pref: PrefKey.CONTROLLER_ENABLE_VIBRATION,
|
pref: PrefKey.CONTROLLER_ENABLE_VIBRATION,
|
||||||
unsupported: !VibrationManager.supportControllerVibration(),
|
unsupported: !VibrationManager.supportControllerVibration(),
|
||||||
onChange: VibrationManager.updateGlobalVars,
|
onChange: () => VibrationManager.updateGlobalVars(),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
pref: PrefKey.CONTROLLER_DEVICE_VIBRATION,
|
pref: PrefKey.CONTROLLER_DEVICE_VIBRATION,
|
||||||
unsupported: !VibrationManager.supportDeviceVibration(),
|
unsupported: !VibrationManager.supportDeviceVibration(),
|
||||||
onChange: VibrationManager.updateGlobalVars,
|
onChange: () => VibrationManager.updateGlobalVars(),
|
||||||
},
|
},
|
||||||
|
|
||||||
(VibrationManager.supportControllerVibration() || VibrationManager.supportDeviceVibration()) && {
|
(VibrationManager.supportControllerVibration() || VibrationManager.supportDeviceVibration()) && {
|
||||||
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
pref: PrefKey.CONTROLLER_VIBRATION_INTENSITY,
|
||||||
unsupported: !VibrationManager.supportDeviceVibration(),
|
unsupported: !VibrationManager.supportDeviceVibration(),
|
||||||
onChange: VibrationManager.updateGlobalVars,
|
onChange: () => VibrationManager.updateGlobalVars(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,7 @@ export class VibrationManager {
|
|||||||
return !!window.navigator.vibrate;
|
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_ENABLE_CONTROLLER_VIBRATION = VibrationManager.supportControllerVibration() ? getPref(PrefKey.CONTROLLER_ENABLE_VIBRATION) : false;
|
||||||
window.BX_VIBRATION_INTENSITY = getPref(PrefKey.CONTROLLER_VIBRATION_INTENSITY) / 100;
|
window.BX_VIBRATION_INTENSITY = getPref(PrefKey.CONTROLLER_VIBRATION_INTENSITY) / 100;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ export class VibrationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stop vibration
|
// Stop vibration
|
||||||
window.navigator.vibrate(0);
|
stopVibration && window.navigator.vibrate(0);
|
||||||
|
|
||||||
const value = getPref(PrefKey.CONTROLLER_DEVICE_VIBRATION);
|
const value = getPref(PrefKey.CONTROLLER_DEVICE_VIBRATION);
|
||||||
let enabled;
|
let enabled;
|
||||||
@ -134,10 +134,10 @@ export class VibrationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static initialSetup() {
|
static initialSetup() {
|
||||||
window.addEventListener('gamepadconnected', VibrationManager.updateGlobalVars);
|
window.addEventListener('gamepadconnected', e => VibrationManager.updateGlobalVars());
|
||||||
window.addEventListener('gamepaddisconnected', VibrationManager.updateGlobalVars);
|
window.addEventListener('gamepaddisconnected', e => VibrationManager.updateGlobalVars());
|
||||||
|
|
||||||
VibrationManager.updateGlobalVars();
|
VibrationManager.updateGlobalVars(false);
|
||||||
|
|
||||||
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => {
|
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => {
|
||||||
const dataChannel = (e as any).dataChannel;
|
const dataChannel = (e as any).dataChannel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user