Skip to content

Commit 302245a

Browse files
committed
feat: Implement explicit quit mechanism to hide app to tray on window close instead of quitting.
1 parent a3c892e commit 302245a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

application/src/main.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ let isRecording = false;
143143

144144
// Hybrid PTT State
145145
let pressedKeys = new Set();
146+
let isExplicitQuit = false;
146147
let recordingStartTime = 0;
147148
let isLatched = false; // true if "Tapped" (latched on), false if "Holding"
148149
let isPaused = false; // To pause listener (e.g. when recording hotkey in UI)
@@ -292,8 +293,11 @@ function buildTrayMenu() {
292293
{ type: "separator" },
293294
{
294295
label: "Sair",
295-
accelerator: "CmdOrCtrl+Q",
296-
click: () => app.quit(),
296+
// accelerator: "CmdOrCtrl+Q", // Disabled to prevent global shortcut from triggering quit directly
297+
click: () => {
298+
isExplicitQuit = true;
299+
app.quit();
300+
},
297301
},
298302
]);
299303
}
@@ -1167,8 +1171,13 @@ app.on("window-all-closed", () => {
11671171
// Don't quit on window close, keep running in tray
11681172
});
11691173

1170-
app.on("before-quit", () => {
1171-
app.isQuitting = true;
1174+
app.on("before-quit", (e) => {
1175+
if (isExplicitQuit) {
1176+
app.isQuitting = true;
1177+
} else {
1178+
e.preventDefault();
1179+
mainWindow?.hide();
1180+
}
11721181
});
11731182

11741183
app.on("will-quit", () => {

0 commit comments

Comments
 (0)