Merge pull request #35 from desktop/single-instance

manage single instance of desktop app
This commit is contained in:
Josh Abernathy 2016-05-31 11:15:33 -04:00
commit f8689057e8
2 changed files with 35 additions and 0 deletions

View file

@ -53,6 +53,18 @@ export default class AppWindow {
this.send('url-action', action)
}
public isMinimized() {
return this.window.isMinimized()
}
public restore() {
this.window.restore()
}
public focus() {
this.window.focus()
}
private rendererLog(msg: string) {
this.send('log', msg)
}

View file

@ -17,6 +17,29 @@ app.on('will-finish-launching', () => {
})
})
if (process.platform !== 'darwin') {
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore()
}
mainWindow.focus()
}
// look at the second argument received, it should have the OAuth
// callback contents and code for us to complete the signin flow
if (commandLine.length > 1) {
const action = parseURL(commandLine[1])
mainWindow.sendURLAction(action)
}
});
if (shouldQuit) {
app.quit()
}
}
app.on('ready', () => {
stats.readyTime = Date.now()