Rate-limit next/previous room activation
This commit is contained in:
parent
109082c8d8
commit
aba01d54e8
46
src/qml/Base/HRateLimiter.qml
Normal file
46
src/qml/Base/HRateLimiter.qml
Normal file
|
@ -0,0 +1,46 @@
|
|||
import QtQuick 2.12
|
||||
|
||||
QtObject {
|
||||
property int cooldown: 250
|
||||
property bool extendOnRequestWhileCooldownActive: false
|
||||
|
||||
property bool firePending: false
|
||||
|
||||
readonly property Timer timer: Timer {
|
||||
property bool extended: false
|
||||
|
||||
interval: cooldown
|
||||
onTriggered: {
|
||||
if (firePending) {
|
||||
if (extendOnRequestWhileCooldownActive && ! extended) {
|
||||
firePending = false
|
||||
extended = true
|
||||
running = true
|
||||
return
|
||||
}
|
||||
|
||||
fired()
|
||||
firePending = false
|
||||
extended = false
|
||||
} else if (extended) {
|
||||
fired()
|
||||
extended = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
signal requestFire()
|
||||
signal fired()
|
||||
|
||||
onRequestFire: {
|
||||
if (timer.running) {
|
||||
firePending = true
|
||||
return
|
||||
}
|
||||
|
||||
fired()
|
||||
firePending = false
|
||||
timer.running = true
|
||||
}
|
||||
}
|
|
@ -52,12 +52,13 @@ HListView {
|
|||
|
||||
function previous() {
|
||||
decrementCurrentIndex()
|
||||
currentItem.item.activate()
|
||||
activateLimiter.requestFire()
|
||||
|
||||
}
|
||||
|
||||
function next() {
|
||||
incrementCurrentIndex()
|
||||
currentItem.item.activate()
|
||||
activateLimiter.requestFire()
|
||||
}
|
||||
|
||||
function toggleCollapseAccount() {
|
||||
|
@ -91,4 +92,11 @@ HListView {
|
|||
source: "Delegate" +
|
||||
(model.type == "Account" ? "Account.qml" : "Room.qml")
|
||||
}
|
||||
|
||||
|
||||
HRateLimiter {
|
||||
id: activateLimiter
|
||||
onFired: currentItem.item.activate()
|
||||
extendOnRequestWhileCooldownActive: true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user