Add WPF/WebView2 desktop host project
- Program.cs with application bootstrap and DI setup - index.html entry point with Blazor WebView - Application stylesheet
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using Duempelkas.Infrastructure;
|
||||
using Duempelkas.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Photino.Blazor;
|
||||
|
||||
namespace Duempelkas.Desktop;
|
||||
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);
|
||||
|
||||
var dbPath = Path.Combine(AppContext.BaseDirectory, "duempelkas.db");
|
||||
appBuilder.Services.AddInfrastructure($"Data Source={dbPath}");
|
||||
|
||||
appBuilder.RootComponents.Add<Duempelkas.App.Components.App>("app");
|
||||
|
||||
var app = appBuilder.Build();
|
||||
|
||||
app.MainWindow.StartUrl = PhotinoWebViewManager.AppBaseUri;
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<FinanceDbContext>();
|
||||
db.Database.Migrate();
|
||||
}
|
||||
|
||||
// Load saved window size or use defaults
|
||||
var settingsPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Duempelkas", "window.json");
|
||||
|
||||
int savedWidth = 1280, savedHeight = 768;
|
||||
if (File.Exists(settingsPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(settingsPath);
|
||||
var doc = System.Text.Json.JsonDocument.Parse(json);
|
||||
savedWidth = doc.RootElement.GetProperty("width").GetInt32();
|
||||
savedHeight = doc.RootElement.GetProperty("height").GetInt32();
|
||||
}
|
||||
catch { /* use defaults on parse error */ }
|
||||
}
|
||||
|
||||
app.MainWindow
|
||||
.SetTitle("Dümpelkas – Kassenbuch")
|
||||
.SetSize(savedWidth, savedHeight)
|
||||
.SetUseOsDefaultSize(false);
|
||||
|
||||
// Persist window size on resize
|
||||
app.MainWindow.RegisterSizeChangedHandler((_, size) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(settingsPath)!;
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(settingsPath,
|
||||
System.Text.Json.JsonSerializer.Serialize(new { width = size.Width, height = size.Height }));
|
||||
}
|
||||
catch { /* ignore save errors */ }
|
||||
});
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
|
||||
{
|
||||
app.MainWindow.ShowMessage("Schwerwiegender Fehler", error.ExceptionObject.ToString());
|
||||
};
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user