diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ada5559..b4ebf695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,12 @@ Release date: TBD #### Windows - Update Mattermost icon for desktop notifications in Windows 10. +- An existing application instance will be reused instead of starting another instance. #### Linux (Beta) - Added an option to make the taskbar icon flash on new messages - Added the badge to count mentions for Unity. +- An existing application instance will be reused instead of starting another instance. #### OS X - Added an option to toggle the red dot icon for unread messages (default is on). @@ -31,7 +33,6 @@ Release date: TBD ### Bug Fixes - ## Release v1.3.0 Release date: 2016-07-18 diff --git a/src/main.js b/src/main.js index df4433ac..9a3b5c52 100644 --- a/src/main.js +++ b/src/main.js @@ -128,6 +128,17 @@ const trayImages = function() { }(); var willAppQuit = false; +// If there is already an instance, activate the window in the existing instace and quit this one +if (app.makeSingleInstance((commandLine, workingDirectory) => { + // Someone tried to run a second instance, we should focus our window. + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore(); + else mainWindow.show(); + } + })) { + app.quit() +} + function shouldShowTrayIcon() { if (process.platform === 'win32') { return true; diff --git a/test/specs/app_test.js b/test/specs/app_test.js index a9660578..261bd896 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -61,4 +61,21 @@ describe('application', function() { config.version.should.equal(settings.version); }); }); + + it('should be stopped when the app instance already exists', function(done) { + this.app.start().then(() => { + const secondApp = env.getSpectronApp(); + secondApp.start().then(() => { + clearTimeout(timer); + return secondApp.stop(); + }).then(() => { + done(new Error('Second app instance exists')); + }); + // In the correct case, 'start().then' is not called. + // So need to use setTimeout in order to finish this test. + const timer = setTimeout(() => { + done(); + }, 3000); + }); + }); });