From 67b59d95d4798d94ee5d107ee961908d56f34afe Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Fri, 20 Aug 2021 14:52:33 +0200 Subject: [PATCH 1/4] fix quotes --- ElectronNET.Host/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 0b33b6c..0f6f49b 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -118,7 +118,7 @@ function startSplashScreen() { let imageFile = path.join(currentBinPath, manifestJsonFile.splashscreen.imageFile); imageSize(imageFile, (error, dimensions) => { if (error) { - console.log(`load splashscreen error:`); + console.log('load splashscreen error:'); console.error(error); throw new Error(error.message); From 9daaebcef61b48c8933da54e7c8864f40821c947 Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Fri, 20 Aug 2021 14:56:47 +0200 Subject: [PATCH 2/4] Add timeout property for splashscreen --- ElectronNET.Host/main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 0f6f49b..5092f7e 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -136,13 +136,29 @@ function startSplashScreen() { alwaysOnTop: true, show: true }); + + if (manifestJsonFile.hasOwnProperty('splashscreen')) { + if (manifestJsonFile.splashscreen.hasOwnProperty('timeout')) { + var timeout = manifestJsonFile.splashscreen.timeout; + window.setTimeout((t) => { + if (splashScreen != null ) { + splashScreen.destroy(); + splashScreen = null; + } + }, timeout); + } + } + + splashScreen.setIgnoreMouseEvents(true); app.once('browser-window-created', () => { splashScreen.destroy(); + splashScreen = null; }); const loadSplashscreenUrl = path.join(__dirname, 'splashscreen', 'index.html') + '?imgPath=' + imageFile; + splashScreen.loadURL('file://' + loadSplashscreenUrl); splashScreen.once('closed', () => { From a8229f2fa957d16b034b7871be77a5d41ad49986 Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Fri, 20 Aug 2021 15:06:58 +0200 Subject: [PATCH 3/4] add internal method to emit socket events synchronously, and use it for all exit, quit and relaunch methods --- ElectronNET.API/App.cs | 11 +++++------ ElectronNET.API/AutoUpdater.cs | 2 +- ElectronNET.API/BridgeConnector.cs | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index ddc0e07..b18cfdf 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -556,7 +556,7 @@ namespace ElectronNET.API /// public void Quit() { - BridgeConnector.Emit("appQuit"); + BridgeConnector.EmitSync("appQuit"); } /// @@ -566,7 +566,7 @@ namespace ElectronNET.API /// Exits immediately with exitCode. exitCode defaults to 0. public void Exit(int exitCode = 0) { - BridgeConnector.Emit("appExit", exitCode); + BridgeConnector.EmitSync("appExit", exitCode); } /// @@ -581,7 +581,7 @@ namespace ElectronNET.API /// public void Relaunch() { - BridgeConnector.Emit("appRelaunch"); + BridgeConnector.EmitSync("appRelaunch"); } /// @@ -599,7 +599,7 @@ namespace ElectronNET.API /// Options for the relaunch. public void Relaunch(RelaunchOptions relaunchOptions) { - BridgeConnector.Emit("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer)); + BridgeConnector.EmitSync("appRelaunch", JObject.FromObject(relaunchOptions, _jsonSerializer)); } /// @@ -698,8 +698,7 @@ namespace ElectronNET.API BridgeConnector.Emit("appGetPath", pathName.GetDescription()); - return await taskCompletionSource.Task - .ConfigureAwait(false); + return await taskCompletionSource.Task.ConfigureAwait(false); } } diff --git a/ElectronNET.API/AutoUpdater.cs b/ElectronNET.API/AutoUpdater.cs index c65b657..95fe432 100644 --- a/ElectronNET.API/AutoUpdater.cs +++ b/ElectronNET.API/AutoUpdater.cs @@ -539,7 +539,7 @@ namespace ElectronNET.API /// Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`. public void QuitAndInstall(bool isSilent = false, bool isForceRunAfter = false) { - BridgeConnector.Emit("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter); + BridgeConnector.EmitSync("autoUpdaterQuitAndInstall", isSilent, isForceRunAfter); } /// diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index f4ab793..f8b06fa 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -104,6 +104,26 @@ namespace ElectronNET.API }); } + /// + /// This method is only used on places where we need to be sure the event was sent on the socket, such as Quit, Exit, Relaunch and QuitAndInstall methods + /// + /// + /// + internal static void EmitSync(string eventString, params object[] args) + { + if (App.SocketDebug) + { + Console.WriteLine($"Sending event {eventString}"); + } + + Socket.EmitAsync(eventString, args).Wait(); + + if (App.SocketDebug) + { + Console.WriteLine($"Sent event {eventString}"); + } + } + public static void Off(string eventString) { Socket.Off(eventString); From 0aab352f863949f0eff7f5a96ec01cf23ee69d87 Mon Sep 17 00:00:00 2001 From: rafael-aero Date: Fri, 20 Aug 2021 15:07:39 +0200 Subject: [PATCH 4/4] remove yield call --- ElectronNET.API/BridgeConnector.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index f8b06fa..8c7a760 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -89,7 +89,6 @@ namespace ElectronNET.API Task.Run(async () => { - await Task.Yield(); if (App.SocketDebug) { Console.WriteLine($"Sending event {eventString}");