diff --git a/skeleton/app.js b/skeleton/app.js index 44cb7ece..5a522955 100644 --- a/skeleton/app.js +++ b/skeleton/app.js @@ -128,19 +128,29 @@ export default class App { applySingleInstance() { if ('singleInstance' in this.settings && this.settings.singleInstance) { this.l.verbose('setting single instance mode'); - const isSecondInstance = app.makeSingleInstance(() => { - // Someone tried to run a second instance, we should focus our window. - if (this.window) { - if (this.window.isMinimized()) { - this.window.restore(); + if (semver.lt(process.versions.electron, '4.0.0')) { //https://www.electronjs.org/docs/all#appmakesingleinstance + const isSecondInstance = app.makeSingleInstance(() => { + // Someone tried to run a second instance, we should focus our window. + if (this.window) { + if (this.window.isMinimized()) { + this.window.restore(); + } + this.window.focus(); } - this.window.focus(); - } - }); - - if (isSecondInstance) { - this.l.warn('current instance was terminated because another instance is running'); - app.quit(); + }); + } else { + app.requestSingleInstanceLock() + const isSecondInstance = app.on('second-instance', () => { + // Someone tried to run a second instance, we should focus our window. + if (this.window) { + if (this.window.isMinimized()) { + this.window.restore(); + } + this.window.focus(); + } + this.l.warn('current instance was terminated because another instance is running'); + app.quit(); + }); } } }