Files
dashcaddy/desktop/App.xaml.cs
T
Hermes 86e4c9fc81 wip: Windows desktop app scaffold (WinUI 3/.NET 8) + NSIS installer + docs
Owner decision pending (STATE.md DC-100 tick): adopt/ship/park.
Preserved from fragile git stash to named branch 2026-08-23.
NOTE: requires a Windows build machine (WinUI XAML compiler + MSIX do not
cross-build on Linux) — see WINDOWS_APP_BUILD.md in this tree.
Secret-scanned clean 2026-08-23 (no keys/tokens/PEM in tree).
2026-08-22 23:50:34 -07:00

84 lines
2.8 KiB
C#

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));
}
}