Skip to content

Commit

Permalink
grab whatever available gamepad ID
Browse files Browse the repository at this point in the history
this fixes the page saying 'it's not Chromium' on OBS browser which is a Chromium
and that gamepad id not being found on such environment
  • Loading branch information
Dinir committed May 3, 2020
1 parent 9f7faf2 commit 6afa983
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions js/interface/controlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ControlPanel {
* @return {string}
*/
static detectBrowser () {
if (!!window.chrome && !!window.chrome.runtime) { return 'Chrome' }
// can't believe `!!window.chrome` doesn't work on OBS browser
if (/Chrome\/\d+/.test(navigator.userAgent)) { return 'Chrome' }
if (typeof InstallTrigger !== 'undefined') { return 'Firefox' }
}

Expand All @@ -55,8 +56,8 @@ class ControlPanel {
*/
static getGamepadId (idString) {
// only parse for either Chrome or Firefox environment at the moment
const matchResult = ControlPanel.detectBrowser() === 'Chrome' ?
idString.match(/ \(.*Vendor: ([0-9a-f]{4}) Product: ([0-9a-f]{4})\)/) :
const matchResult =
idString.match(/ \(.*Vendor: ([0-9a-f]{4}) Product: ([0-9a-f]{4})\)/) ||
idString.match(/([0-9a-f]{1,4})-([0-9a-f]{1,4})/)
if (matchResult) {
return {
Expand Down
13 changes: 7 additions & 6 deletions js/module/GamepadWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class GamepadWatcher {
* @return {string}
*/
static detectBrowser () {
if (!!window.chrome && !!window.chrome.runtime) { return 'Chrome' }
// can't believe `!!window.chrome` doesn't work on OBS browser
if (/Chrome\/\d+/.test(navigator.userAgent)) { return 'Chrome' }
if (typeof InstallTrigger !== 'undefined') { return 'Firefox' }
}

Expand All @@ -155,10 +156,10 @@ class GamepadWatcher {
* @param {string} idString
* @returns {{name: string, gamepadId: gamepadId}}
*/
getGamepadId (idString) {
static getGamepadId (idString) {
// only parse for either Chrome or Firefox environment at the moment
const matchResult = this.browser === 'Chrome' ?
idString.match(/ \(.*Vendor: ([0-9a-f]{4}) Product: ([0-9a-f]{4})\)/) :
const matchResult =
idString.match(/ \(.*Vendor: ([0-9a-f]{4}) Product: ([0-9a-f]{4})\)/) ||
idString.match(/([0-9a-f]{1,4})-([0-9a-f]{1,4})/)
if (matchResult) {
return {
Expand Down Expand Up @@ -198,7 +199,7 @@ class GamepadWatcher {
if (connection) {
this.gamepads[gamepad.index] = gamepad
this.gamepadId[gamepad.index] =
this.getGamepadId(gamepad.id)
GamepadWatcher.getGamepadId(gamepad.id)
} else {
delete this.gamepads[gamepad.index]
delete this.gamepadId[gamepad.index]
Expand Down Expand Up @@ -228,7 +229,7 @@ class GamepadWatcher {
if (gamepads[i]) {
this.gamepads[gamepads[i].index] = gamepads[i]
this.gamepadId[gamepads[i].index] =
this.getGamepadId(gamepads[i].id)
GamepadWatcher.getGamepadId(gamepads[i].id)
}
else {
delete this.gamepads[gamepads[i].index]
Expand Down

0 comments on commit 6afa983

Please sign in to comment.