Browse Source

fix: prevent Enter from sending message during recording, play error cue

- Add 'error' cue to playCue() (sawtooth 150Hz)
- Return true instead of false on Enter during recording to consume the key
- Suppress message send when Enter is pressed while recording
master
Matteo Benedetto 2 months ago
parent
commit
5f950fc59a
  1. 9
      extensions/index.ts

9
extensions/index.ts

@ -144,11 +144,13 @@ function parseBooleanish(input: string): boolean | undefined {
return undefined; return undefined;
} }
function playCue(kind: "start" | "stop") { function playCue(kind: "start" | "stop" | "error") {
if (!config.soundsEnabled) return; if (!config.soundsEnabled) return;
const args = kind === "start" const args = kind === "start"
? ["-q", "-n", "synth", "0.05", "sine", "880", "fade", "q", "0.01", "0.05", "0.02"] ? ["-q", "-n", "synth", "0.05", "sine", "880", "fade", "q", "0.01", "0.05", "0.02"]
: ["-q", "-n", "synth", "0.04", "sine", "660:440", "fade", "q", "0.005", "0.04", "0.02"]; : kind === "stop"
? ["-q", "-n", "synth", "0.04", "sine", "660:440", "fade", "q", "0.005", "0.04", "0.02"]
: ["-q", "-n", "synth", "0.15", "sawtooth", "150", "fade", "q", "0.01", "0.15", "0.02"];
const proc = spawn("play", args, { stdio: "ignore", detached: true }); const proc = spawn("play", args, { stdio: "ignore", detached: true });
proc.on("error", () => {}); proc.on("error", () => {});
proc.unref(); proc.unref();
@ -438,8 +440,9 @@ export default function (pi: ExtensionAPI) {
Reflect.set(globalThis, VOICE_HANDLER_SYMBOL, (data: string): boolean => { Reflect.set(globalThis, VOICE_HANDLER_SYMBOL, (data: string): boolean => {
if (recording && matchesKey(data, Key.enter)) { if (recording && matchesKey(data, Key.enter)) {
keyPressed = false; keyPressed = false;
playCue("error");
void stopRecording(ctx, pi, false, true); void stopRecording(ctx, pi, false, true);
return false; return true;
} }
if (recording && config.mode === "paste" && !isKeyRelease(data) && !matchesKey(data, keyId)) { if (recording && config.mode === "paste" && !isKeyRelease(data) && !matchesKey(data, keyId)) {

Loading…
Cancel
Save