using System; using System.IO; using System.Text.Json; using System.Windows; using Microsoft.Web.WebView2.Core; namespace Gott; public partial class MainWindow : Window { private readonly AppSettings _settings; public MainWindow() { _settings = LoadSettings(); InitializeComponent(); var screenW = SystemParameters.PrimaryScreenWidth; var screenH = SystemParameters.PrimaryScreenHeight; Width = 930; Height = screenH * 0.95; Left = (screenW - Width) / 2; Top = (screenH - Height) / 2; Loaded += async (_, _) => { await webView.EnsureCoreWebView2Async(); // Dark background to avoid white flash webView.DefaultBackgroundColor = System.Drawing.Color.FromArgb(255, 17, 17, 17); // Open external links in default browser webView.CoreWebView2.NewWindowRequested += (_, e) => { e.Handled = true; System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri) { UseShellExecute = true }); }; webView.CoreWebView2.NavigationCompleted += (_, _) => { webView.Visibility = Visibility.Visible; loader.Visibility = Visibility.Collapsed; }; webView.CoreWebView2.Navigate(_settings.Url); }; } private static AppSettings LoadSettings() { foreach (var file in new[] { "appsettings.Production.json", "appsettings.json" }) { var path = Path.Combine(AppContext.BaseDirectory, file); if (File.Exists(path)) { try { var json = File.ReadAllText(path); return JsonSerializer.Deserialize(json) ?? new(); } catch { } } } return new(); } } public class AppSettings { public string Url { get; set; } = "http://localhost:19000"; }