From 6307f0351ef9243aae192f17ebfef359f448d3c9 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Fri, 16 Jan 2026 22:43:10 -0600 Subject: [PATCH] Fix startup of launcher Fixes #391 --- LANCommander.Launcher/Program.cs | 135 ++++++++++-------- LANCommander.Launcher/UI/App.Main.razor | 2 +- .../UI/Pages/Authenticate/Index.razor | 1 + .../UI/Windows/AuthWindow.razor | 33 +++++ .../UI/Windows/AuthWindow.razor.scss | 12 ++ .../UI/Windows/MainWindow.razor | 47 +----- LANCommander.Launcher/UI/_Imports.razor.scss | 1 + 7 files changed, 124 insertions(+), 107 deletions(-) create mode 100644 LANCommander.Launcher/UI/Windows/AuthWindow.razor create mode 100644 LANCommander.Launcher/UI/Windows/AuthWindow.razor.scss diff --git a/LANCommander.Launcher/Program.cs b/LANCommander.Launcher/Program.cs index e23b32f8..0f9bb525 100644 --- a/LANCommander.Launcher/Program.cs +++ b/LANCommander.Launcher/Program.cs @@ -12,71 +12,86 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Photino.Blazor; using Photino.Blazor.CustomWindow.Extensions; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; +using LANCommander.UI.Extensions; -var builder = PhotinoBlazorAppBuilder.CreateDefault(args); -// Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel. -builder.Services.AddLogging(loggingBuilder => loggingBuilder.AddStandardLogging()); -builder.Services.AddOpenTelemetryDefaults("Launcher", false); +namespace LANCommander.Launcher; -// Configure services -builder.AddSettings(); -builder.Services.AddCustomWindow(); -builder.Services.AddAntDesign(); -builder.Services.AddSingleton(); -builder.Services.AddLANCommanderClient(); -builder.Services.AddLANCommanderLauncher(); - -// Configure root component -builder.RootComponents.Add("app"); - -var app = builder.Build(); - -var logger = app.Services.GetRequiredService>(); - -logger.LogInformation("Starting launcher | Version: {Version}", UpdateService.GetCurrentVersion()); - -// Configure main window -app.RegisterMainWindow() - .RegisterMediaHandler() - .RegisterNotificationHandler() - .RegisterImportHandler() - .RestoreWindowPosition(); - -// Initialize application -using var scope = app.Services.CreateScope(); - -var connectionClient = scope.ServiceProvider.GetRequiredService(); -var settingsProvider = scope.ServiceProvider.GetRequiredService>(); -var databaseContext = scope.ServiceProvider.GetRequiredService(); - -await connectionClient.ConnectAsync(); - -if (!await connectionClient.PingAsync()) - await connectionClient.EnableOfflineModeAsync(); - -if (settingsProvider.CurrentValue.Games.InstallDirectories.Length == 0) +class Program { - settingsProvider.Update(static s => s.Games.InstallDirectories = GetOSPlatform() switch + [STAThread] + static void Main(string[] args) { - var platform when platform == OSPlatform.Windows => [Path.Combine(Path.GetPathRoot(AppContext.BaseDirectory) ?? "C:", "Games")], - var platform when platform == OSPlatform.Linux => [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")], - var platform when platform == OSPlatform.OSX => [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")], - _ => throw new NotSupportedException("Unsupported OS platform") - }); -} + var builder = PhotinoBlazorAppBuilder.CreateDefault(args); + // Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel. + builder.Services.AddLogging(loggingBuilder => loggingBuilder.AddStandardLogging()); + builder.Services.AddOpenTelemetryDefaults("Launcher", false); + + // Configure services + builder.AddSettings(); + builder.Services.AddCustomWindow(); + builder.Services.AddAntDesign(); + builder.Services.AddSingleton(); + builder.Services.AddLANCommanderUI(); + builder.Services.AddLANCommanderClient(); + builder.Services.AddLANCommanderLauncher(); + + // Configure root component + builder.RootComponents.Add("app"); -await databaseContext.Database.MigrateAsync(); + var app = builder.Build(); -app.Run(); + var logger = app.Services.GetRequiredService>(); -static OSPlatform GetOSPlatform() -{ - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return OSPlatform.Windows; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - return OSPlatform.Linux; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - return OSPlatform.OSX; - throw new NotSupportedException("Unsupported OS platform"); + logger.LogInformation("Starting launcher | Version: {Version}", UpdateService.GetCurrentVersion()); + + // Configure main window + app.RegisterMainWindow() + .RegisterMediaHandler() + .RegisterNotificationHandler() + .RegisterImportHandler() + .RestoreWindowPosition(); + + // Initialize application + using var scope = app.Services.CreateScope(); + + var connectionClient = scope.ServiceProvider.GetRequiredService(); + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var databaseContext = scope.ServiceProvider.GetRequiredService(); + + Task.Run(async () => + { + connectionClient.ConnectAsync().Wait(); + + if (!await connectionClient.PingAsync()) + await connectionClient.EnableOfflineModeAsync(); + }).Wait(); + + if (settingsProvider.CurrentValue.Games.InstallDirectories.Length == 0) + { + settingsProvider.Update(static s => s.Games.InstallDirectories = GetOSPlatform() switch + { + var platform when platform == OSPlatform.Windows => [Path.Combine(Path.GetPathRoot(AppContext.BaseDirectory) ?? "C:", "Games")], + var platform when platform == OSPlatform.Linux => [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")], + var platform when platform == OSPlatform.OSX => [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")], + _ => throw new NotSupportedException("Unsupported OS platform") + }); + } + + if (databaseContext.Database.GetPendingMigrations().Any()) + databaseContext.Database.Migrate(); + + app.Run(); + + static OSPlatform GetOSPlatform() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return OSPlatform.Windows; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return OSPlatform.Linux; + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + return OSPlatform.OSX; + throw new NotSupportedException("Unsupported OS platform"); + } + } } \ No newline at end of file diff --git a/LANCommander.Launcher/UI/App.Main.razor b/LANCommander.Launcher/UI/App.Main.razor index 957c6ee2..47119e61 100644 --- a/LANCommander.Launcher/UI/App.Main.razor +++ b/LANCommander.Launcher/UI/App.Main.razor @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/LANCommander.Launcher/UI/Pages/Authenticate/Index.razor b/LANCommander.Launcher/UI/Pages/Authenticate/Index.razor index 5772ac59..e147e8c1 100644 --- a/LANCommander.Launcher/UI/Pages/Authenticate/Index.razor +++ b/LANCommander.Launcher/UI/Pages/Authenticate/Index.razor @@ -1,3 +1,4 @@ @page "/Authenticate" +@layout AuthWindow \ No newline at end of file diff --git a/LANCommander.Launcher/UI/Windows/AuthWindow.razor b/LANCommander.Launcher/UI/Windows/AuthWindow.razor new file mode 100644 index 00000000..9ea88db0 --- /dev/null +++ b/LANCommander.Launcher/UI/Windows/AuthWindow.razor @@ -0,0 +1,33 @@ +@using Photino.Blazor.CustomWindow.Components +@namespace LANCommander.Launcher.UI +@inherits LayoutComponentBase +@inject AuthenticationClient AuthenticationClient +@inject NavigationManager NavigationManager +@inject LocalizationService LocalizationService + + + + + + + @Body + + + + + + + + + + + + + +@code { + protected override async Task OnInitializedAsync() + { + if (await AuthenticationClient.ValidateTokenAsync()) + NavigationManager.NavigateTo("/Library"); + } +} \ No newline at end of file diff --git a/LANCommander.Launcher/UI/Windows/AuthWindow.razor.scss b/LANCommander.Launcher/UI/Windows/AuthWindow.razor.scss new file mode 100644 index 00000000..a1f340cd --- /dev/null +++ b/LANCommander.Launcher/UI/Windows/AuthWindow.razor.scss @@ -0,0 +1,12 @@ +.auth-window { + .pb-custom-window-content { + top: 0 !important; + left: 0 !important; + right: 0 !important; + bottom: 0 !important; + display: flex; + flex-direction: column; + height: 100% !important; + width: 100% !important; + } +} \ No newline at end of file diff --git a/LANCommander.Launcher/UI/Windows/MainWindow.razor b/LANCommander.Launcher/UI/Windows/MainWindow.razor index 412cebac..aae5e55e 100644 --- a/LANCommander.Launcher/UI/Windows/MainWindow.razor +++ b/LANCommander.Launcher/UI/Windows/MainWindow.razor @@ -102,11 +102,7 @@ ImportHandler ImportHandler; ImportHandler.ImportProgressEventArgs ImportStatus = new(); private ImportProgress _importProgress => ImportService.Progress; - - string RandomQuip = ""; - - string[] _crashQuips; - + protected override async Task OnInitializedAsync() { ConnectionClient.OnOfflineModeEnabled += OnOfflineModeChanged; @@ -119,40 +115,6 @@ await ImportManagerService.RequestImport(); await InvokeAsync(StateHasChanged); } - - _crashQuips = new[] - { - LocalizationService.GetString("CrashQuip_YouDied"), - LocalizationService.GetString("CrashQuip_Snake"), - LocalizationService.GetString("CrashQuip_Wasted"), - LocalizationService.GetString("CrashQuip_MajorFracture"), - LocalizationService.GetString("CrashQuip_PastIsGapingHole"), - LocalizationService.GetString("CrashQuip_TownCenterDestroyed"), - LocalizationService.GetString("CrashQuip_ForcesUnderAttack"), - LocalizationService.GetString("CrashQuip_LostLead"), - LocalizationService.GetString("CrashQuip_TerroristsWin"), - LocalizationService.GetString("CrashQuip_WarNeverChanges"), - LocalizationService.GetString("CrashQuip_DiedOfDysentery"), - LocalizationService.GetString("CrashQuip_FailedToRestoreBooks"), - LocalizationService.GetString("CrashQuip_PlayerSplattered"), - LocalizationService.GetString("CrashQuip_BlameISP"), - LocalizationService.GetString("CrashQuip_BabaNoMore"), - LocalizationService.GetString("CrashQuip_GuestsLost"), - LocalizationService.GetString("CrashQuip_DarknessOvercome"), - LocalizationService.GetString("CrashQuip_GordonFreemanTerminated"), - LocalizationService.GetString("CrashQuip_MissionFailedSpotted"), - LocalizationService.GetString("CrashQuip_CriticalDamageEject"), - LocalizationService.GetString("CrashQuip_MinionsUnhappy"), - LocalizationService.GetString("CrashQuip_EmpireTriumphed"), - LocalizationService.GetString("CrashQuip_QuestEndedFailure"), - LocalizationService.GetString("CrashQuip_EatenByGrue"), - LocalizationService.GetString("CrashQuip_NoMessWithLoWang"), - LocalizationService.GetString("CrashQuip_SamKilled"), - LocalizationService.GetString("CrashQuip_AlienBastardsPay") - }; - - var randIndex = new Random().Next(0, _crashQuips.Length - 1); - RandomQuip = _crashQuips[randIndex]; } private async void OnConnect(object? sender, EventArgs e) @@ -177,13 +139,6 @@ await InvokeAsync(StateHasChanged); } - async Task CopyError(Exception ex) - { - await JS.InvokeVoidAsync("navigator.clipboard.writeText", ex.Message + "\n" + ex.StackTrace); - - MessageService.Info(LocalizationService.GetString("ErrorCopiedToClipboard")); - } - async Task Connect() { Connecting = true; diff --git a/LANCommander.Launcher/UI/_Imports.razor.scss b/LANCommander.Launcher/UI/_Imports.razor.scss index b8b07c13..7b927817 100644 --- a/LANCommander.Launcher/UI/_Imports.razor.scss +++ b/LANCommander.Launcher/UI/_Imports.razor.scss @@ -1,4 +1,5 @@ @forward 'Windows/Window'; +@forward 'Windows/AuthWindow.razor'; @forward 'Windows/MainWindow.razor'; @forward 'Windows/ChatWindow.razor';