-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (40 loc) · 1.45 KB
/
Program.cs
File metadata and controls
47 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using ElectronNET.API;
using ElectronWebsiteWrapper;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables("ElectronWebsiteWrapper_");
builder.Services.AddRazorPages();
builder.Services.AddElectron();
builder.Services.AddOptions<AppSettings>()
.Bind(builder.Configuration)
.Validate(
settings => !string.IsNullOrWhiteSpace(settings.Url) && Uri.TryCreate(settings.Url, UriKind.Absolute, out _),
"The 'Url' configuration value must be a non-empty, valid absolute URI (e.g. https://www.example.com).")
.ValidateOnStart();
WebApplication? app = null;
builder.UseElectron(args,
async () =>
{
var settings = app!.Services.GetRequiredService<IOptions<AppSettings>>().Value;
var browserWindow = await Electron.WindowManager.CreateWindowAsync(settings.Url);
browserWindow.OnPageTitleUpdated += _ => browserWindow.SetTitle("ElectronWebsiteWrapper");
if (OperatingSystem.IsWindows())
{
browserWindow.SetMenuBarVisibility(false);
}
browserWindow.Maximize();
#if DEBUG
browserWindow.WebContents.OpenDevTools();
#endif
browserWindow.OnReadyToShow += () => browserWindow.Show();
});
app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
await app.RunAsync();