Skip to content

Commit

Permalink
Shutdown all applications on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
layerssss committed Jun 12, 2019
1 parent ff6bf20 commit 797b0bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
20 changes: 17 additions & 3 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ electron.app.on("ready", () =>
tray.setToolTip("LocalhostD is running...");
tray.on("double-click", () => app.showWindow());

const quit = async () => {
// eslint-disable-next-line no-console
console.log("quiting...");
await app.close();
electron.app.exit();
};

tray.setContextMenu(
electron.Menu.buildFromTemplate([
{
Expand All @@ -26,7 +33,7 @@ electron.app.on("ready", () =>
{
label: "Quit",
click: () => {
electron.app.exit();
quit();
}
}
])
Expand All @@ -38,13 +45,20 @@ electron.app.on("ready", () =>
app.showWindow();
});

electron.app.on("window-all-closed", () => {});
electron.app.on("window-all-closed", event => {
event.preventDefault();
});

electron.app.on("before-quit", event => {
event.preventDefault();
quit();
});

const signal = await waitDeath();

// eslint-disable-next-line no-console
console.log(`received ${signal}`);
electron.app.exit();
await quit();
})
.catch(error => {
// eslint-disable-next-line no-console
Expand Down
1 change: 1 addition & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Commander.command("server")

// eslint-disable-next-line no-console
console.log(`received ${signal}`);
await server.close();

process.exit(0);
})
Expand Down
4 changes: 4 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class App {
autoUpdater.checkForUpdatesAndNotify();
}

async close() {
await this._server.close();
}

showWindow() {
if (process.platform === "darwin") app.dock.show();
if (this._window) return this._window.focus();
Expand Down
6 changes: 2 additions & 4 deletions lib/localhostd.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ class LocalhostD {
});
} catch (error) {
throw new Error(
`${
error.message
}: Cannot find executable ${executable} in PATH (${envPath})`
`${error.message}: Cannot find executable ${executable} in PATH (${envPath})`
);
}

Expand Down Expand Up @@ -410,7 +408,7 @@ class LocalhostD {
}

async ensureDown() {
for (const application of this.state.applications)
for (const application of this._state.applications)
await this._ensureApplicationDown(application);
}

Expand Down

0 comments on commit 797b0bb

Please sign in to comment.