Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/desktop/src/main/managers/recording-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type RecordingMode = "idle" | "ptt" | "hands-free";
export type TerminationCode =
| "dismissed"
| "quick_release"
| "escape"
| "no_audio"
| "error";

Expand Down Expand Up @@ -110,6 +111,10 @@ export class RecordingManager extends EventEmitter {
shortcutManager.on("paste-last-transcript-triggered", async () => {
await this.pasteLatestTranscription();
});

shortcutManager.on("escape-triggered", async () => {
await this.cancelHandsFreeRecording();
});
}

private setState(newState: RecordingState): void {
Expand Down Expand Up @@ -202,6 +207,16 @@ export class RecordingManager extends EventEmitter {
}
}

public async cancelHandsFreeRecording() {
if (
this.recordingState === "recording" &&
this.recordingMode === "hands-free"
) {
logger.audio.info("Escape pressed in hands-free mode, cancelling");
await this.endRecording("escape");
}
}

// Toggle shortcut pressed
public async toggleHandsFree() {
// Double-tap detection: timer pending means quick release happened
Expand Down
16 changes: 16 additions & 0 deletions apps/desktop/src/main/managers/shortcut-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ShortcutManager extends EventEmitter {
private recheckInFlight = false;
private recheckInterval: NodeJS.Timeout | null = null;
private exactMatchState = {
escape: false,
toggleRecording: false,
pasteLastTranscript: false,
newNote: false,
Expand Down Expand Up @@ -183,6 +184,7 @@ export class ShortcutManager extends EventEmitter {
setIsRecordingShortcut(isRecording: boolean) {
this.isRecordingShortcut = isRecording;
if (isRecording) {
this.exactMatchState.escape = false;
this.exactMatchState.toggleRecording = false;
this.exactMatchState.pasteLastTranscript = false;
this.exactMatchState.newNote = false;
Expand Down Expand Up @@ -276,6 +278,12 @@ export class ShortcutManager extends EventEmitter {
return;
}

const escapeMatch = this.isEscapePressed();
if (escapeMatch && !this.exactMatchState.escape) {
this.emit("escape-triggered");
}
this.exactMatchState.escape = escapeMatch;

// Check PTT shortcut
const isPTTPressed = this.isPTTShortcutPressed();
this.emit("ptt-state-changed", isPTTPressed);
Expand All @@ -302,6 +310,14 @@ export class ShortcutManager extends EventEmitter {
this.exactMatchState.newNote = newNoteMatch;
}

private isEscapePressed(): boolean {
const activeKeysList = this.getActiveKeys();
return (
activeKeysList.length === 1 &&
getKeyFromKeycode(activeKeysList[0]!) === "Escape"
);
}

private isPTTShortcutPressed(): boolean {
const pttKeys = this.shortcuts.pushToTalk;
if (!pttKeys || pttKeys.length === 0) {
Expand Down