using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Windowing; using Windows.Graphics; using DashCaddy.Desktop.ViewModels; using DashCaddy.Desktop.Services; using Serilog; namespace DashCaddy.Desktop; public sealed partial class App : Application { public static MainViewModel MainViewModel { get; private set; } public static DockerService DockerService { get; private set; } public static ApiClient ApiClient { get; private set; } public static CaddyConfigGenerator CaddyGenerator { get; private set; } public static DnsClient DnsClient { get; private set; } public App() { InitializeComponent(); ConfigureLogging(); InitializeServices(); } private void ConfigureLogging() { var logPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DashCaddy", "logs", "dashcaddy-.log"); Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.File(logPath, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 30) .WriteTo.Debug() .CreateLogger(); } private void InitializeServices() { var apiBaseUrl = "http://localhost:3001"; var dockerEndpoint = "npipe://./pipe/docker_engine"; // Windows named pipe DockerService = new DockerService(dockerEndpoint); ApiClient = new ApiClient(apiBaseUrl); CaddyGenerator = new CaddyConfigGenerator(); DnsClient = new DnsClient(apiBaseUrl); MainViewModel = new MainViewModel(DockerService, ApiClient, CaddyGenerator, DnsClient); } protected override void OnLaunched(LaunchActivatedEventArgs args) { var window = new MainWindow(); window.Activate(); // Center window on screen CenterWindow(window); // Set minimum size var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window); var windowId = Win32Interop.GetWindowIdFromWindow(hWnd); var appWindow = AppWindow.GetFromWindowId(windowId); appWindow.Resize(new SizeInt32(1200, 800)); } private static void CenterWindow(Window window) { var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window); var windowId = Win32Interop.GetWindowIdFromWindow(hWnd); var appWindow = AppWindow.GetFromWindowId(windowId); var displayArea = DisplayArea.GetFromWindowId(windowId, DisplayAreaFallback.Nearest); var center = displayArea.WorkArea.CenterPoint; var width = 1200; var height = 800; appWindow.MoveAndResize(new RectInt32( center.X - width / 2, center.Y - height / 2, width, height)); } }