feat: Use single instance lock to avoid multiple instances of Vynte Connect

This commit is contained in:
2026-06-01 14:50:12 -05:00
parent a7d40d293c
commit 00dca3ba9b
+23 -17
View File
@@ -10,10 +10,29 @@ if (started) {
app.quit();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
const singleInstanceLock = app.requestSingleInstanceLock()
if (!singleInstanceLock) app.quit();
else {
app.on('second-instance', () => {
if (window) {
if (window.isMinimized()) window.restore();
window.focus();
}
});
app.on('before-quit', disconnect);
}
app.whenReady().then(() => {
createWindow();
createTray();
refreshStatus();
pollTimer = setInterval(refreshStatus, POLL_INTERVAL_MS);
});
app.on('before-quit', () => {
if (pollTimer) clearInterval(pollTimer);
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
@@ -24,8 +43,6 @@ app.on('window-all-closed', () => {
}
});
app.on('before-quit', disconnect);
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
@@ -209,17 +226,6 @@ function createTray() {
tray.on('click', showWindow);
}
app.whenReady().then(() => {
createWindow();
createTray();
refreshStatus();
pollTimer = setInterval(refreshStatus, POLL_INTERVAL_MS);
});
app.on('before-quit', () => {
if (pollTimer) clearInterval(pollTimer);
});
ipcMain.handle('status:get', () => withAutoConnect(cachedStatus));
ipcMain.handle('status:refresh', refreshStatus);
ipcMain.handle('vpn:connect', connect);