Fix some subtle bugs with the easter egg

Because we were trimming the log to be too long (it was trying to account for
esc), it would only work if the easter egg was the very first string typed.

Additionally, we filter out escape keys explicitly. This accounts for things
like Firefox when it blocks the file input popup, and therefore does not block
swallow the esc.

Also, clean up the array matching logic.

Fixes #395.
This commit is contained in:
Jordan Eldredge 2017-09-26 08:16:25 -07:00
parent 4445af4bc5
commit 1e38da3f52
2 changed files with 12 additions and 4 deletions

View file

@ -16,6 +16,8 @@ import {
TOGGLE_LLAMA_MODE
} from "./actionTypes";
import { arraysAreEqual } from "./utils";
export default function(winamp, { dispatch }) {
let keylog = [];
const trigger = [
@ -113,10 +115,13 @@ export default function(winamp, { dispatch }) {
}
// Easter Egg
keylog.push(e.keyCode);
keylog = keylog.slice(-10);
// TODO: Find a less stupid way to compare arrays.
if (keylog.toString() === trigger.toString()) {
// Ignore escape. Usually this get's swallowed by the browser, but not always.
if (e.keyCode !== 27) {
keylog.push(e.keyCode);
keylog = keylog.slice(-8);
}
if (arraysAreEqual(keylog, trigger)) {
dispatch({ type: TOGGLE_LLAMA_MODE });
}
});

View file

@ -105,3 +105,6 @@ export const segment = (min, max, value, newValues) => {
);
return newValues[index];
};
export const arraysAreEqual = (a, b) =>
a.length === b.length && a.every((value, i) => value === b[i]);