Skip to content

Commit

Permalink
add feature flag for single instance (see standardnotes#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjocoleman committed Jun 8, 2019
1 parent c14a157 commit b52fdd6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/index.js
Expand Up @@ -152,13 +152,28 @@ app.on('activate', function() {
updateManager.checkForUpdate();
});

const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
// feature flag: https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#appmakesingleinstance
const hasRequestSingleInstanceLock = app.requestSingleInstanceLock ? true : false;
let isSecondInstance = null;

const handleSecondInstance = (argv, cwd) => {
if (win) {
if (win.isMinimized()) win.restore()
win.focus()
}
})
}

if (hasRequestSingleInstanceLock) {
isSecondInstance = !app.requestSingleInstanceLock()

app.on('second-instance', (event, argv, cwd) => {
handleSecondInstance(argv, cwd)
})
} else {
isSecondInstance = app.makeSingleInstance((argv, cwd) => {
handleSecondInstance(argv, cwd)
})
}

app.on('ready', function(){

Expand Down

0 comments on commit b52fdd6

Please sign in to comment.