Skip to content

Commit

Permalink
Fix: Ignore first gamepad and keyboard event in browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed Sep 5, 2023
1 parent 9fc7d3c commit 9347fbe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Gamepad icons not showing in distribution version [`249640d`](https://github.com/ollm/OpenComic/commit/249640d57f3d5768661b63c0ddf8525a02e44d25)
- Go back in gamepad menus [`b2719e5`](https://github.com/ollm/OpenComic/commit/b2719e5e782659f249ce7a6ba6c8b94fe40a3407)
- Wrong detection of folder images in some cases [`425a137`](https://github.com/ollm/OpenComic/commit/425a137333114739cb4f0b1e92e4606f2c9da87c)
- Ignore first gamepad and keyboard event in browsing

## [v1.0.0-beta.2](https://github.com/ollm/OpenComic/releases/tag/v1.0.0-beta.2) (03-09-2023)

Expand Down
2 changes: 1 addition & 1 deletion scripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function activeMenu(query, query2 = false, posX = 'left', posY = 'top')
fromGamepadMenu = (posX == 'gamepad' && posY == 'gamepad') ? true : false;

shortcuts.pause();
gamepad.updateBrowsableItems('menu', true);
gamepad.updateBrowsableItems('menu');
}


Expand Down
2 changes: 0 additions & 2 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ var file = function(path) {

this._images = async function(num, files, from = false, fromReached = false, poster = false, deep = 0) {

console.log(deep);

let images = [];
let imagesNum = 0;

Expand Down
16 changes: 10 additions & 6 deletions scripts/gamepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ setInterval(pollGamepads, 500);

var hasGamepads = false;
var gamepadAF = false;
var firstGamepadEvent = true;

function pollGamepads()
{

let gamepads = navigator.getGamepads();
let _hasGamepads = false;

Expand All @@ -28,6 +28,8 @@ function pollGamepads()
gamepadAF = requestAnimationFrame(gamepadLoop);

updateBrowsableItems(currentKey, true);

firstGamepadEvent = true;
}

hasGamepads = true;
Expand Down Expand Up @@ -120,7 +122,7 @@ function gamepadLoop()
else if(status.eventNum > 1 && now - status.lastEvent > speed)
sendEvent = true;

if(sendEvent)
if(sendEvent && !firstGamepadEvent)
{
status.eventNum++;
status.lastEvent = now;
Expand Down Expand Up @@ -182,7 +184,7 @@ function gamepadLoop()
else if(status.eventNum > 1 && now - status.lastEvent > speed)
sendEvent = true;

if(sendEvent)
if(sendEvent && !firstGamepadEvent)
{
console.log('sendEvent');

Expand Down Expand Up @@ -216,6 +218,8 @@ function gamepadLoop()
}

gamepadAF = requestAnimationFrame(gamepadLoop);

firstGamepadEvent = false;
}

function reset(key = false)
Expand Down Expand Up @@ -746,9 +750,6 @@ window.addEventListener('keydown', function(event) {

hasKeyboardNavigation = true;

if(lastUpdateBrowsableItemsSkiped)
updateBrowsableItems(currentKey, true);

if(key == 8)
goBack();
else if(key == 13)
Expand All @@ -761,6 +762,9 @@ window.addEventListener('keydown', function(event) {
highlightClosestItem(1);
else if(key == 40)
highlightClosestItem(3);

if(lastUpdateBrowsableItemsSkiped)
updateBrowsableItems(currentKey, true);
}
else
{
Expand Down

0 comments on commit 9347fbe

Please sign in to comment.