Merge pull request #405 from dafergu2/master

Update application exit logic
This commit is contained in:
Gregor Biswanger
2020-05-19 13:19:47 +02:00
committed by GitHub
5 changed files with 30 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -31,7 +32,7 @@ namespace ElectronNET.API
{
BridgeConnector.Socket.On("app-window-all-closed" + GetHashCode(), () =>
{
if (!Electron.WindowManager.IsQuitOnWindowAllClosed)
if (!Electron.WindowManager.IsQuitOnWindowAllClosed || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_windowAllClosed();
}

View File

@@ -1,23 +1,28 @@
"use strict";
let isQuitWindowAllClosed = true, electronSocket;
let appWindowAllClosedEventId;
module.exports = (socket, app) => {
electronSocket = socket;
// Quit when all windows are closed.
// By default, quit when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' &&
isQuitWindowAllClosed) {
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
app.quit();
}
else if (appWindowAllClosedEventId) {
// If the user is on macOS
// - OR -
// If the user has indicated NOT to quit when all windows are closed,
// emit the event.
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
}
});
socket.on('quit-app-window-all-closed-event', (quit) => {
isQuitWindowAllClosed = quit;
});
socket.on('register-app-window-all-closed-event', (id) => {
app.on('window-all-closed', () => {
electronSocket.emit('app-window-all-closed' + id);
});
appWindowAllClosedEventId = id;
});
socket.on('register-app-before-quit-event', (id) => {
app.on('before-quit', (event) => {

File diff suppressed because one or more lines are too long

View File

@@ -1,13 +1,20 @@
let isQuitWindowAllClosed = true, electronSocket;
let appWindowAllClosedEventId;
export = (socket: SocketIO.Socket, app: Electron.App) => {
electronSocket = socket;
// Quit when all windows are closed.
// By default, quit when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' &&
isQuitWindowAllClosed) {
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
app.quit();
} else if (appWindowAllClosedEventId) {
// If the user is on macOS
// - OR -
// If the user has indicated NOT to quit when all windows are closed,
// emit the event.
electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId);
}
});
@@ -16,9 +23,7 @@ export = (socket: SocketIO.Socket, app: Electron.App) => {
});
socket.on('register-app-window-all-closed-event', (id) => {
app.on('window-all-closed', () => {
electronSocket.emit('app-window-all-closed' + id);
});
appWindowAllClosedEventId = id;
});
socket.on('register-app-before-quit-event', (id) => {

View File

@@ -62,6 +62,11 @@ app.on('ready', () => {
});
app.on('quit', async (event, exitCode) => {
await server.close();
apiProcess.kill();
});
function isSplashScreenEnabled() {
if (manifestJsonFile.hasOwnProperty('splashscreen')) {
if (manifestJsonFile.splashscreen.hasOwnProperty('imageFile')) {