From e2b7a71c8e410aaad98350a14f88e674b697b805 Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 3 Mar 2022 03:52:34 +0100 Subject: [PATCH] fixed combo delay --- config.json | 1 + libs/keyfilter.js | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 535999f..ce36057 100644 --- a/config.json +++ b/config.json @@ -16,6 +16,7 @@ ], "event": "EV_KEY", "type": "keydown", + "delay": 3000, "command": "notify-send", "args": [ "combo", diff --git a/libs/keyfilter.js b/libs/keyfilter.js index f614654..02e2dcd 100644 --- a/libs/keyfilter.js +++ b/libs/keyfilter.js @@ -142,7 +142,8 @@ class Keyfilter { this.currentCombo = { key: key, type: event.type, - start: new Date().getTime(), + delay: event.delay, + timestamp: new Date().getTime(), done: [key], remaining: JSON.parse(JSON.stringify(event.combo)), finished: this.hasComboFinished() @@ -167,6 +168,7 @@ class Keyfilter { return false; } this.currentCombo.key = parsedEvent.key; + this.currentCombo.timestamp = new Date().getTime(); this.currentCombo.done.push(parsedEvent.key); this.currentCombo.remaining.shift(); this.currentCombo.finished = this.hasComboFinished(); @@ -178,10 +180,11 @@ class Keyfilter { this.currentCombo.remaining.length === 0; } hasComboTimedOut() { - return this.currentCombo !== undefined && + const result = this.currentCombo !== undefined && this.currentCombo.delay !== undefined && - this.currentCombo.start !== undefined && - new Date().getTime() - this.currentCombo.start > this.currentCombo.delay; + this.currentCombo.timestamp !== undefined && + new Date().getTime() - this.currentCombo.timestamp > this.currentCombo.delay; + return result; } resetCurrentCombo() { this.currentCombo = undefined;