Skip to content

Commit fc9d189

Browse files
committed
feat: Implement single instance application behavior and remove tray click handler for window focus.
1 parent 0a71cba commit fc9d189

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

application/src/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,6 @@ function createTray() {
291291
tray = new Tray(createTrayIcon(false));
292292
tray.setToolTip("Push to Talk");
293293
tray.setContextMenu(buildTrayMenu());
294-
295-
tray.on("click", () => {
296-
mainWindow?.show();
297-
mainWindow?.focus();
298-
});
299294
}
300295

301296
function updateTrayIcon(recording) {
@@ -1111,6 +1106,21 @@ ipcMain.handle("set-auto-launch", (event, enabled) => {
11111106
// APP LIFECYCLE
11121107
// ============================================================================
11131108

1109+
const gotTheLock = app.requestSingleInstanceLock();
1110+
1111+
if (!gotTheLock) {
1112+
app.quit();
1113+
} else {
1114+
app.on("second-instance", (event, commandLine, workingDirectory) => {
1115+
// Someone tried to run a second instance, we should focus our window.
1116+
if (mainWindow) {
1117+
if (mainWindow.isMinimized()) mainWindow.restore();
1118+
mainWindow.show();
1119+
mainWindow.focus();
1120+
}
1121+
});
1122+
}
1123+
11141124
app.whenReady().then(async () => {
11151125
// Load configuration from config.json
11161126
CONFIG = loadConfig();

0 commit comments

Comments
 (0)