Skip to content

Commit

Permalink
Merge pull request #181 from 5k-mirrors/do-not-allow-multiple-app-ins…
Browse files Browse the repository at this point in the history
…tances

Do not allow multiple app instances
  • Loading branch information
thisismydesign authored Aug 8, 2022
2 parents 53f9a96 + e521f89 commit 22a73d7
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions app/main/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,47 @@ const createWindow = () => {
});
};

app.whenReady().then(() => {
ensureEnv();
const gotTheLock = app.requestSingleInstanceLock();

// Subscribing to the listeners happens even before creating the window to be ready to actively respond to initial events coming from renderer.
initListeners();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", () => {
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});

createWindow();
app.whenReady().then(() => {
ensureEnv();

if (envIs("development")) {
setupDevelopmentWorkflow();
devLog("Development setup done");
}
// Subscribing to the listeners happens even before creating the window to be ready to actively respond to initial events coming from renderer.
initListeners();

createWindow();

if (envIs("development")) {
setupDevelopmentWorkflow();
devLog("Development setup done");
}

initRateLimiter();
initRateLimiter();

win.webContents.on("did-finish-load", () => {
win.setTitle(windows.MAIN);
win.webContents.on("did-finish-load", () => {
win.setTitle(windows.MAIN);
});
});
});

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
if (win === null) {
createWindow();
}
});
app.on("activate", () => {
if (win === null) {
createWindow();
}
});
}

0 comments on commit 22a73d7

Please sign in to comment.