Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple instances on Mac #19

Merged
merged 4 commits into from
Oct 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions ember-electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ function createServer() {
serverInstance = backendServer(absPath)
serverInstance.start((serverPort) => {
global.serverPort = serverPort;
createWindow();
setupListeners();

if (mainWindow === null) {
createWindow();
}
});
}

Expand All @@ -67,6 +69,8 @@ function createWindow() {

// Load the ember application using our custom protocol/scheme
mainWindow.loadURL(APP_URL);

setupListeners();
}

function setupListeners() {
Expand Down Expand Up @@ -95,22 +99,16 @@ function setupListeners() {
}

app.on('window-all-closed', () => {
serverInstance.stop();
serverInstance = null;

if (process.platform !== 'darwin') {
// Using exit instead of quit for the time being
// see: https://github.com/electron/electron/issues/8862#issuecomment-294303518
app.exit();
}
});

app.on('before-quit', () => {
if (window && !window.isDestroyed() && window.isVisible()) {
window.removeAllListeners();
window.close();

setTimeout(() => app.exit(), 2000);
}
});

app.on('ready', () => {
createServer();
});
Expand All @@ -121,7 +119,7 @@ app.on('activate', () => {
if (serverInstance === null) {
createServer();
} else if (mainWindow === null) {
createWindow(serverPort);
createWindow();
}
});

Expand Down