diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index 8474f9e..49a1f03 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -7,20 +7,20 @@ using System; namespace ElectronNET.API { - public class App + public static class App { - private readonly Socket _socket; - private readonly JsonSerializer _jsonSerializer; + private static Socket _socket; + private static JsonSerializer _jsonSerializer; - public App(int width, int height, bool show) + public static void OpenWindow(int width, int height, bool show) { _jsonSerializer = new JsonSerializer() { ContractResolver = new CamelCasePropertyNamesContractResolver() }; - var socket = IO.Socket("http://localhost:3000"); - socket.On(Socket.EVENT_CONNECT, () => + _socket = IO.Socket("http://localhost:3000"); + _socket.On(Socket.EVENT_CONNECT, () => { Console.WriteLine("Verbunden!"); @@ -30,9 +30,13 @@ namespace ElectronNET.API Show = show }; - socket.Emit("createBrowserWindow", JObject.FromObject(browserWindowOptions, _jsonSerializer)); - socket.Emit("createNotification"); + _socket.Emit("createBrowserWindow", JObject.FromObject(browserWindowOptions, _jsonSerializer)); }); } + + public static void CreateNotification(NotificationOptions notificationOptions) + { + _socket.Emit("createNotification", JObject.FromObject(notificationOptions, _jsonSerializer)); + } } } diff --git a/ElectronNET.WebApp/Controllers/HomeController.cs b/ElectronNET.WebApp/Controllers/HomeController.cs index 26715e4..64ba301 100644 --- a/ElectronNET.WebApp/Controllers/HomeController.cs +++ b/ElectronNET.WebApp/Controllers/HomeController.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using ElectronNET.API; +using ElectronNET.API.Entities; namespace ElectronNET.WebApp.Controllers { @@ -12,5 +14,15 @@ namespace ElectronNET.WebApp.Controllers { return View(); } + + public IActionResult SayHello() + { + App.CreateNotification(new NotificationOptions { + Title = "Hallo Robert", + Body = "Nachricht von ASP.NET Core App" + }); + + return RedirectToAction("Index"); + } } } \ No newline at end of file diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index 7b5f6b4..63b3d10 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -35,7 +35,7 @@ namespace ElectronNET.WebApp template: "{controller=Home}/{action=Index}/{id?}"); }); - var electronApp = new App(800, 600, true); + App.OpenWindow(800, 600, true); } } } diff --git a/ElectronNET.WebApp/Views/Home/Index.cshtml b/ElectronNET.WebApp/Views/Home/Index.cshtml index 31477d6..997debd 100644 --- a/ElectronNET.WebApp/Views/Home/Index.cshtml +++ b/ElectronNET.WebApp/Views/Home/Index.cshtml @@ -6,6 +6,9 @@