Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Mac: Fix not closing all processes when closing app from dock #1130

Merged
merged 1 commit into from
Feb 21, 2019
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
47 changes: 29 additions & 18 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ if (process.platform === "darwin") {
app.dock.setIcon(getIconPath());
}

const performShutdownTasks = async ({ truffleIntegration, chain }) => {
// don't quit the app before the updater can do its thing
const service = getAutoUpdateService();
if (service == null || !service.isRestartingForUpdate) {
mainWindow = null;

if (truffleIntegration) {
await truffleIntegration.stopWatching();
}

if (chain.isServerStarted()) {
await chain.stopServer();
}

chain.stopProcess();
truffleIntegration.stopProcess();
app.quit();
}
};

app.on("ready", () => {
// workaround for electron race condition, causing hang on startup.
// see https://github.com/electron/electron/issues/9179 for more info
Expand All @@ -111,25 +131,16 @@ app.on("ready", () => {
let workspace;
let startupMode = STARTUP_MODE.NORMAL;

app.on("window-all-closed", async () => {
// don't quit the app before the updater can do its thing
const service = getAutoUpdateService();
if (service == null || !service.isRestartingForUpdate) {
mainWindow = null;

if (truffleIntegration) {
await truffleIntegration.stopWatching();
}

if (chain.isServerStarted()) {
await chain.stopServer();
}
app.on(
"window-all-closed",
async () => await performShutdownTasks({ truffleIntegration, chain }),
);

chain.stopProcess();
truffleIntegration.stopProcess();
app.quit();
}
});
// Mac: event emitted by closing app from dock
app.on(
"will-quit",
async () => await performShutdownTasks({ truffleIntegration, chain }),
);

truffleIntegration.on("error", async error => {
if (mainWindow) {
Expand Down