Files
Electron.NET/ElectronNET.WebApp/Startup.cs

119 lines
3.9 KiB
C#
Raw Normal View History

using ElectronNET.API;
2017-10-14 19:57:49 +02:00
using ElectronNET.API.Entities;
2017-10-02 20:40:28 +02:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
2017-10-02 20:40:28 +02:00
using Microsoft.Extensions.DependencyInjection;
2019-10-03 22:30:58 +02:00
using Microsoft.Extensions.Hosting;
2017-10-02 20:40:28 +02:00
namespace ElectronNET.WebApp
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
2017-10-02 20:40:28 +02:00
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
2017-10-03 04:40:37 +02:00
services.AddMvc();
2017-10-02 20:40:28 +02:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
2019-10-03 22:30:58 +02:00
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
2017-10-02 20:40:28 +02:00
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
2017-10-03 04:40:37 +02:00
app.UseStaticFiles();
2019-10-03 22:30:58 +02:00
app.UseRouting();
app.UseEndpoints(endpoints =>
2017-10-02 20:40:28 +02:00
{
2019-10-03 22:30:58 +02:00
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
2017-10-02 20:40:28 +02:00
});
2019-10-03 22:30:58 +02:00
if (HybridSupport.IsElectronActive)
2017-10-23 21:24:05 +02:00
{
ElectronBootstrap();
}
}
2017-10-19 06:01:54 +02:00
public async void ElectronBootstrap()
{
//AddDevelopmentTests();
var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
Width = 1152,
2019-05-21 03:32:18 +02:00
Height = 940,
2017-10-16 16:53:35 +02:00
Show = false
});
await browserWindow.WebContents.Session.ClearCacheAsync();
2017-10-19 06:01:54 +02:00
browserWindow.OnReadyToShow += () => browserWindow.Show();
browserWindow.SetTitle(Configuration["DemoTitleInSettings"]);
2017-10-02 20:40:28 +02:00
}
private static void AddDevelopmentTests()
{
// NOTE: on mac you will need to allow the app to post notifications when asked.
Electron.App.On("activate", (obj) =>
{
// obj should be a boolean that represents where there are active windows or not.
var hasWindows = (bool) obj;
Electron.Notification.Show(
new NotificationOptions("Activate", $"activate event has been captured. Active windows = {hasWindows}")
{
Silent = false,
});
});
Electron.Dock.SetMenu(new[]
{
new MenuItem
{
Type = MenuType.normal,
Label = "MenuItem",
Click = () =>
{
Electron.Notification.Show(new NotificationOptions(
"Dock MenuItem Click",
"A menu item added to the Dock was selected;"));
},
},
new MenuItem
{
Type = MenuType.submenu,
Label = "SubMenu",
Submenu = new[]
{
new MenuItem
{
Type = MenuType.normal,
Label = "Sub MenuItem",
Click = () =>
{
Electron.Notification.Show(new NotificationOptions(
"Dock Sub MenuItem Click",
"A menu item added to the Dock was selected;"));
},
},
}
}
});
}
2017-10-02 20:40:28 +02:00
}
}