implement notification bridge

This commit is contained in:
Gregor Biswanger
2017-10-03 04:40:37 +02:00
parent a0a3e6fc15
commit b16e0b0bf9
8 changed files with 96 additions and 5 deletions

View File

@@ -31,6 +31,7 @@ namespace ElectronNET.API
};
socket.Emit("createBrowserWindow", JObject.FromObject(browserWindowOptions, _jsonSerializer));
socket.Emit("createNotification");
});
}
}

View File

@@ -0,0 +1,8 @@
namespace ElectronNET.API.Entities
{
public class NotificationOptions
{
public string Title { get; set; }
public string Body { get; set; }
}
}

View File

@@ -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();
});
});

View File

@@ -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();
}
}
}

View File

@@ -11,6 +11,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -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?}");
});
}

View File

@@ -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);

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Home</title>
</head>
<body>
Hello from MVC!
</body>
</html>