Convert app-start/-stop callbacks to async/await (#3035)

supersedes https://github.com/MichMich/MagicMirror/pull/3027 and just
touches the start/stop calls.

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck
2023-02-22 18:58:00 +01:00
committed by GitHub
parent 2b792cdbb8
commit fe0b915a5d
5 changed files with 90 additions and 70 deletions

View File

@@ -157,18 +157,19 @@ app.on("activate", function () {
* Note: this is only used if running Electron. Otherwise
* core.stop() is called by process.on("SIGINT"... in `app.js`
*/
app.on("before-quit", (event) => {
app.on("before-quit", async (event) => {
Log.log("Shutting down server...");
event.preventDefault();
setTimeout(() => {
process.exit(0);
}, 3000); // Force-quit after 3 seconds.
core.stop();
await core.stop();
process.exit(0);
});
/* handle errors from self signed certificates */
/**
* Handle errors from self-signed certificates
*/
app.on("certificate-error", (event, webContents, url, error, certificate, callback) => {
event.preventDefault();
callback(true);
@@ -177,7 +178,5 @@ app.on("certificate-error", (event, webContents, url, error, certificate, callba
// Start the core application if server is run on localhost
// This starts all node helpers and starts the webserver.
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].includes(config.address)) {
core.start(function (c) {
config = c;
});
core.start().then((c) => (config = c));
}