From e3c5e3e706506a73392e84aaa1b8cf017d2f8fc6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 23 Feb 2018 15:08:26 -0500 Subject: [PATCH] single instance app --- src/main/window.main.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/window.main.ts b/src/main/window.main.ts index a406431ca9f..8b94618e999 100644 --- a/src/main/window.main.ts +++ b/src/main/window.main.ts @@ -21,6 +21,21 @@ export class WindowMain { init(): Promise { return new Promise((resolve, reject) => { try { + const shouldQuit = app.makeSingleInstance((args, dir) => { + // Someone tried to run a second instance, we should focus our window. + if (this.win != null) { + if (this.win.isMinimized()) { + this.win.restore(); + } + this.win.focus(); + } + }); + + if (shouldQuit) { + app.quit(); + return; + } + // 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.