Skip to content

Commit

Permalink
Fix small bug when keys are released in a different order that they w…
Browse files Browse the repository at this point in the history
…ere pressed.
  • Loading branch information
hptruong93 committed Jun 11, 2018
1 parent b946372 commit 158b5ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/core/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class Config implements ILoggable {

public static final String RELEASE_VERSION = "4.0.1";
public static final String RELEASE_VERSION = "4.0.2";
private static final String CONFIG_FILE_NAME = "config.json";
public static final String EXPORTED_CONFIG_FILE_NAME = "exported_" + CONFIG_FILE_NAME;
protected static final String CURRENT_CONFIG_VERSION = "2.3";
Expand Down
7 changes: 7 additions & 0 deletions src/core/keyChain/RollingKeySeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public void addKeyStroke(KeyStroke stroke) {
}
}

/**
* @return last key stroke in the series.
*/
public KeyStroke getLast() {
return keys.getLast();
}


/**
* Get the string which would be typed out if all keys in this {@link KeySequence} are pressed in the specified order.
Expand Down
21 changes: 0 additions & 21 deletions src/core/keyChain/managers/KeySequenceManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package core.keyChain.managers;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import core.config.Config;
import core.keyChain.KeySequence;
import core.keyChain.KeyStroke;
import core.keyChain.TaskActivation;
import core.userDefinedTask.UserDefinedAction;

Expand All @@ -16,25 +14,6 @@ public KeySequenceManager(Config config) {
super(config);
}

@Override
public Set<UserDefinedAction> onKeyStrokePressed(KeyStroke stroke) {
currentRollingKeySeries.addKeyStroke(stroke);
if (!getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
public Set<UserDefinedAction> onKeyStrokeReleased(KeyStroke stroke) {
if (getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
protected boolean collisionWithAction(UserDefinedAction action, TaskActivation activation) {
for (KeySequence sequence : activation.getKeySequences()) {
Expand Down
22 changes: 0 additions & 22 deletions src/core/keyChain/managers/PhraseManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package core.keyChain.managers;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import core.config.Config;
import core.keyChain.ActivationPhrase;
import core.keyChain.KeyStroke;
import core.keyChain.TaskActivation;
import core.userDefinedTask.UserDefinedAction;

Expand All @@ -16,26 +14,6 @@ public PhraseManager(Config config) {
super(config);
}

@Override
public Set<UserDefinedAction> onKeyStrokePressed(KeyStroke stroke) {
currentRollingKeySeries.addKeyStroke(stroke);
if (!getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
public Set<UserDefinedAction> onKeyStrokeReleased(KeyStroke stroke) {
currentRollingKeySeries.addKeyStroke(stroke);
if (getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
protected boolean collisionWithAction(UserDefinedAction action, TaskActivation activation) {
for (ActivationPhrase phrase : activation.getPhrases()) {
Expand Down
26 changes: 22 additions & 4 deletions src/core/keyChain/managers/RollingKeySeriesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -31,13 +32,26 @@ public final void startListening() {
}

@Override
public abstract Set<UserDefinedAction> onKeyStrokePressed(KeyStroke stroke);
synchronized public Set<UserDefinedAction> onKeyStrokePressed(KeyStroke stroke) {
currentRollingKeySeries.addKeyStroke(stroke);
if (!getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
public abstract Set<UserDefinedAction> onKeyStrokeReleased(KeyStroke stroke);
synchronized public Set<UserDefinedAction> onKeyStrokeReleased(KeyStroke stroke) {
if (getConfig().isExecuteOnKeyReleased()) {
return considerTaskExecution(stroke);
}

return Collections.<UserDefinedAction>emptySet();
}

@Override
public final void clear() {
synchronized public final void clear() {
currentRollingKeySeries.clearKeys();
}

Expand Down Expand Up @@ -87,7 +101,11 @@ protected final Set<UserDefinedAction> considerTaskExecution(KeyStroke key) {
clear();
return null;
}
return tasksToExecute();

if (key.equals(currentRollingKeySeries.getLast())) {
return tasksToExecute();
}
return Set.of();
}

protected abstract Set<UserDefinedAction> tasksToExecute();
Expand Down

0 comments on commit 158b5ab

Please sign in to comment.