diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index df1eeccdae1..035520bb414 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -157,6 +157,28 @@ describe('app module', function () { }) }) + describe('app.makeSingleInstance', function () { + it('prevents the second launch of app', function (done) { + this.timeout(120000) + const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton') + // First launch should exit with 0. + let secondLaunched = false + const first = ChildProcess.spawn(remote.process.execPath, [appPath]) + first.once('exit', (code) => { + assert.ok(secondLaunched) + assert.equal(code, 0) + done() + }) + // Second launch should exit with 1. + const second = ChildProcess.spawn(remote.process.execPath, [appPath]) + second.once('exit', (code) => { + assert.ok(!secondLaunched) + assert.equal(code, 1) + secondLaunched = true + }) + }) + }) + describe('app.relaunch', function () { let server = null const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch' diff --git a/spec/fixtures/api/singleton/main.js b/spec/fixtures/api/singleton/main.js new file mode 100644 index 00000000000..1cf75c4a664 --- /dev/null +++ b/spec/fixtures/api/singleton/main.js @@ -0,0 +1,13 @@ +const {app} = require('electron') + +process.on('uncaughtException', () => { + app.exit(2) +}) + +const shouldExit = app.makeSingleInstance(() => { + process.nextTick(() => app.exit(0)) +}) + +if (shouldExit) { + app.exit(1) +} diff --git a/spec/fixtures/api/singleton/package.json b/spec/fixtures/api/singleton/package.json new file mode 100644 index 00000000000..ebf7c8f4892 --- /dev/null +++ b/spec/fixtures/api/singleton/package.json @@ -0,0 +1,5 @@ +{ + "name": "electron-app-singleton", + "main": "main.js" +} +