From b16e0b0bf9689c3d29d5666f55fadf4afe5cd07b Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Tue, 3 Oct 2017 04:40:37 +0200 Subject: [PATCH] implement notification bridge --- ElectronNET.API/App.cs | 1 + .../Entities/NotificationOptions.cs | 8 ++++ ElectronNET.Host/main.js | 9 ++++- .../Controllers/HomeController.cs | 16 ++++++++ ElectronNET.WebApp/ElectronNET.WebApp.csproj | 7 ++++ ElectronNET.WebApp/ScaffoldingReadMe.txt | 39 +++++++++++++++++++ ElectronNET.WebApp/Startup.cs | 10 +++-- ElectronNET.WebApp/Views/Home/Index.cshtml | 11 ++++++ 8 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 ElectronNET.API/Entities/NotificationOptions.cs create mode 100644 ElectronNET.WebApp/Controllers/HomeController.cs create mode 100644 ElectronNET.WebApp/ScaffoldingReadMe.txt create mode 100644 ElectronNET.WebApp/Views/Home/Index.cshtml diff --git a/ElectronNET.API/App.cs b/ElectronNET.API/App.cs index ce128bb..8474f9e 100644 --- a/ElectronNET.API/App.cs +++ b/ElectronNET.API/App.cs @@ -31,6 +31,7 @@ namespace ElectronNET.API }; socket.Emit("createBrowserWindow", JObject.FromObject(browserWindowOptions, _jsonSerializer)); + socket.Emit("createNotification"); }); } } diff --git a/ElectronNET.API/Entities/NotificationOptions.cs b/ElectronNET.API/Entities/NotificationOptions.cs new file mode 100644 index 0000000..b58e954 --- /dev/null +++ b/ElectronNET.API/Entities/NotificationOptions.cs @@ -0,0 +1,8 @@ +namespace ElectronNET.API.Entities +{ + public class NotificationOptions + { + public string Title { get; set; } + public string Body { get; set; } + } +} diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 44bd0e2..88f6756 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow, Notification } = require('electron'); const io = require('socket.io')(3000); const path = require('path'); @@ -18,7 +18,7 @@ app.on('ready', () => { }); io.on('connection', (socket) => { - console.log('a user connected'); + console.log('ASP.NET Core Application connected...'); socket.on('createBrowserWindow', (options) => { console.log(options); @@ -32,5 +32,10 @@ io.on('connection', (socket) => { apiProcess = null; }); }); + + socket.on('createNotification', (options) => { + const notification = new Notification(options); + notification.show(); + }); }); diff --git a/ElectronNET.WebApp/Controllers/HomeController.cs b/ElectronNET.WebApp/Controllers/HomeController.cs new file mode 100644 index 0000000..26715e4 --- /dev/null +++ b/ElectronNET.WebApp/Controllers/HomeController.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace ElectronNET.WebApp.Controllers +{ + public class HomeController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} \ No newline at end of file diff --git a/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/ElectronNET.WebApp/ElectronNET.WebApp.csproj index 810cecd..ea1532a 100644 --- a/ElectronNET.WebApp/ElectronNET.WebApp.csproj +++ b/ElectronNET.WebApp/ElectronNET.WebApp.csproj @@ -11,6 +11,13 @@ + + + + + + + diff --git a/ElectronNET.WebApp/ScaffoldingReadMe.txt b/ElectronNET.WebApp/ScaffoldingReadMe.txt new file mode 100644 index 0000000..46370e5 --- /dev/null +++ b/ElectronNET.WebApp/ScaffoldingReadMe.txt @@ -0,0 +1,39 @@ + +ASP.NET MVC core dependencies have been added to the project. +(These dependencies include packages required to enable scaffolding) + +However you may still need to do make changes to your project. + +1. Suggested changes to Startup class: + 1.1 Add a constructor: + public IConfiguration Configuration { get; } + + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + 1.2 Add MVC services: + public void ConfigureServices(IServiceCollection services) + { + // Add framework services. + services.AddMvc(); + } + + 1.3 Configure web app to use use Configuration and use MVC routing: + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseStaticFiles(); + + app.UseMvc(routes => + { + routes.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); + } diff --git a/ElectronNET.WebApp/Startup.cs b/ElectronNET.WebApp/Startup.cs index 33b75e2..7b5f6b4 100644 --- a/ElectronNET.WebApp/Startup.cs +++ b/ElectronNET.WebApp/Startup.cs @@ -13,7 +13,7 @@ namespace ElectronNET.WebApp // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - //services.AddMvc(); + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -26,9 +26,13 @@ namespace ElectronNET.WebApp app.UseDeveloperExceptionPage(); } - app.Run(async (context) => + app.UseStaticFiles(); + + app.UseMvc(routes => { - await context.Response.WriteAsync("Hello World!"); + routes.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); }); var electronApp = new App(800, 600, true); diff --git a/ElectronNET.WebApp/Views/Home/Index.cshtml b/ElectronNET.WebApp/Views/Home/Index.cshtml new file mode 100644 index 0000000..31477d6 --- /dev/null +++ b/ElectronNET.WebApp/Views/Home/Index.cshtml @@ -0,0 +1,11 @@ + + + + + + Home + + + Hello from MVC! + +