Commit 26c9fc2b authored by Jeremy Bokobza's avatar Jeremy Bokobza

to close the underlying node, replaced the window.beforeunload event by an...

to close the underlying node, replaced the window.beforeunload event by an http request at electron level
parent 6e31783a
......@@ -48,7 +48,23 @@ function createWindow() {
// when you should delete the corresponding element.
mainWindow = null;
});
// Emitted when the window is going to close.
mainWindow.on('close', function () {
var http = require('http');
const options = {
hostname: 'localhost',
port: 5000,
path: '/api/node/shutdown',
method: 'POST'
};
const req = http.request(options, (res) => {});
req.write('');
req.end();
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
......
import { Component, OnInit, HostListener } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ApiService } from './shared/services/api.service';
......@@ -26,23 +26,4 @@ export class AppComponent implements OnInit {
this.loading = false;
this.router.navigate(['/login']);
}
@HostListener('window:unload')
unloadHandler() {
this.apiService.shutdownNode().subscribe(
response => {},
error => {
if (error.status === 0) {
alert("Error closing application. please close the dotnet process manually.");
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
}
}
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment