Skip to content

Commit 9347fbe

Browse files
committed
Fix: Ignore first gamepad and keyboard event in browsing
1 parent 9fc7d3c commit 9347fbe

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Gamepad icons not showing in distribution version [`249640d`](https://github.com/ollm/OpenComic/commit/249640d57f3d5768661b63c0ddf8525a02e44d25)
1616
- Go back in gamepad menus [`b2719e5`](https://github.com/ollm/OpenComic/commit/b2719e5e782659f249ce7a6ba6c8b94fe40a3407)
1717
- Wrong detection of folder images in some cases [`425a137`](https://github.com/ollm/OpenComic/commit/425a137333114739cb4f0b1e92e4606f2c9da87c)
18+
- Ignore first gamepad and keyboard event in browsing
1819

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

scripts/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ function activeMenu(query, query2 = false, posX = 'left', posY = 'top')
531531
fromGamepadMenu = (posX == 'gamepad' && posY == 'gamepad') ? true : false;
532532

533533
shortcuts.pause();
534-
gamepad.updateBrowsableItems('menu', true);
534+
gamepad.updateBrowsableItems('menu');
535535
}
536536

537537

scripts/file-manager.js

-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ var file = function(path) {
252252

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

255-
console.log(deep);
256-
257255
let images = [];
258256
let imagesNum = 0;
259257

scripts/gamepad.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ setInterval(pollGamepads, 500);
22

33
var hasGamepads = false;
44
var gamepadAF = false;
5+
var firstGamepadEvent = true;
56

67
function pollGamepads()
78
{
8-
99
let gamepads = navigator.getGamepads();
1010
let _hasGamepads = false;
1111

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

3030
updateBrowsableItems(currentKey, true);
31+
32+
firstGamepadEvent = true;
3133
}
3234

3335
hasGamepads = true;
@@ -120,7 +122,7 @@ function gamepadLoop()
120122
else if(status.eventNum > 1 && now - status.lastEvent > speed)
121123
sendEvent = true;
122124

123-
if(sendEvent)
125+
if(sendEvent && !firstGamepadEvent)
124126
{
125127
status.eventNum++;
126128
status.lastEvent = now;
@@ -182,7 +184,7 @@ function gamepadLoop()
182184
else if(status.eventNum > 1 && now - status.lastEvent > speed)
183185
sendEvent = true;
184186

185-
if(sendEvent)
187+
if(sendEvent && !firstGamepadEvent)
186188
{
187189
console.log('sendEvent');
188190

@@ -216,6 +218,8 @@ function gamepadLoop()
216218
}
217219

218220
gamepadAF = requestAnimationFrame(gamepadLoop);
221+
222+
firstGamepadEvent = false;
219223
}
220224

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

747751
hasKeyboardNavigation = true;
748752

749-
if(lastUpdateBrowsableItemsSkiped)
750-
updateBrowsableItems(currentKey, true);
751-
752753
if(key == 8)
753754
goBack();
754755
else if(key == 13)
@@ -761,6 +762,9 @@ window.addEventListener('keydown', function(event) {
761762
highlightClosestItem(1);
762763
else if(key == 40)
763764
highlightClosestItem(3);
765+
766+
if(lastUpdateBrowsableItemsSkiped)
767+
updateBrowsableItems(currentKey, true);
764768
}
765769
else
766770
{

0 commit comments

Comments
 (0)