Rate-limit next/previous room activation

This commit is contained in:
miruka 2019-08-19 18:17:59 -04:00
parent 109082c8d8
commit aba01d54e8
2 changed files with 56 additions and 2 deletions

View 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
}
}

View File

@ -52,12 +52,13 @@ HListView {
function previous() { function previous() {
decrementCurrentIndex() decrementCurrentIndex()
currentItem.item.activate() activateLimiter.requestFire()
} }
function next() { function next() {
incrementCurrentIndex() incrementCurrentIndex()
currentItem.item.activate() activateLimiter.requestFire()
} }
function toggleCollapseAccount() { function toggleCollapseAccount() {
@ -91,4 +92,11 @@ HListView {
source: "Delegate" + source: "Delegate" +
(model.type == "Account" ? "Account.qml" : "Room.qml") (model.type == "Account" ? "Account.qml" : "Room.qml")
} }
HRateLimiter {
id: activateLimiter
onFired: currentItem.item.activate()
extendOnRequestWhileCooldownActive: true
}
} }