Browse Source

fixed error message show position, added launcher hiding on game start

Veloe 1 year ago
parent
commit
af38af260a

+ 2 - 1
VeloeMinecraftLauncher/App.axaml.cs

@@ -3,6 +3,7 @@ using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Markup.Xaml;
 using Avalonia.Markup.Xaml.Styling;
 using Avalonia.Themes.Fluent;
+using Avalonia.Threading;
 using VeloeMinecraftLauncher.ViewModels;
 using VeloeMinecraftLauncher.Views;
 
@@ -21,7 +22,7 @@ namespace VeloeMinecraftLauncher
             {
                 desktop.MainWindow = new MainWindow
                 {
-                    DataContext = new MainWindowViewModel(),
+                    DataContext = new MainWindowViewModel(() => Dispatcher.UIThread.InvokeAsync(() =>desktop.MainWindow.WindowState = Avalonia.Controls.WindowState.Minimized), () => Dispatcher.UIThread.InvokeAsync(() => desktop.MainWindow.WindowState = Avalonia.Controls.WindowState.Normal)),
                 };
             }
 

+ 1 - 1
VeloeMinecraftLauncher/VeloeMinecraftLauncher.csproj

@@ -11,7 +11,7 @@
 		<StartupObject>VeloeMinecraftLauncher.Program</StartupObject>
 		<PlatformTarget>x64</PlatformTarget>
 		<AssemblyVersion>1.5.1.73</AssemblyVersion>
-		<FileVersion>1.5.1.73</FileVersion>
+		<FileVersion>1.5.1.77</FileVersion>
 		<Configurations>Debug;Release</Configurations>
 	</PropertyGroup>
 	<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

+ 14 - 6
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -217,6 +217,12 @@ public class MainWindowViewModel : ViewModelBase
         
     }
 
+    public MainWindowViewModel(Action hide, Action show) : this()
+    {
+        _hide = hide;
+        _show = show;
+    }
+
     System.Timers.Timer _consoleOutputTimer = new(250);
 
     private HubConnection? _connection;
@@ -231,6 +237,9 @@ public class MainWindowViewModel : ViewModelBase
     private string _startButtonOutput = string.Empty;
     private CancellationTokenSource _tokenSource = new();
 
+    private Action _hide = () => { };
+    private Action _show = () => { };
+
     LatestLauncherVersion? _latestLauncherInfo;
     DownloadedVersion? _downloadedVersion;
     DownloadedVersion? _startedVersion;
@@ -493,7 +502,7 @@ public class MainWindowViewModel : ViewModelBase
                 ProcessStartInfo proc;
                 proc = new ProcessStartInfo
                 {
-                    UseShellExecute = false,
+                    UseShellExecute = false,                    
                     RedirectStandardOutput = true,
                     RedirectStandardError = true,
                     CreateNoWindow = true,
@@ -532,6 +541,7 @@ public class MainWindowViewModel : ViewModelBase
                         _startedVersion = DownloadedVersion;
                         minecraft.Start();
 
+                        _hide();
                         minecraft.Exited += ProcessExited;
 
                         minecraft.BeginOutputReadLine();
@@ -621,6 +631,8 @@ public class MainWindowViewModel : ViewModelBase
 
             StartButtonOutput = "";
             IsNoGameRunning = true;
+
+            _show();
             if (minecraftProcess.ExitCode is not (0 or 2))
                 OpenErrorWindow(new JavaProcessException($"Minecraft process exited with an error code {minecraftProcess.ExitCode}.\nCheck log in game folder or launcher console.", $"{Settings.minecraftForlderPath}versions/{_startedVersion?.Version ?? "NULL"}/crash-reports"));
             else if (minecraftProcess.ExitCode is 2)
@@ -850,11 +862,7 @@ public class MainWindowViewModel : ViewModelBase
                 serverPanelModel.Players = $"{status.NumPlayers}/{status.MaxPlayers}";
                 serverPanelModel.Tip = String.Empty;
                 if (UInt16.Parse(status.NumPlayers ?? "0") > 0)
-                    foreach (var player in status.Players ?? new())
-                    {
-                        serverPanelModel.Tip += player;
-                        serverPanelModel.Tip += "\n";
-                    }
+                    serverPanelModel.Tip = string.Join('\n',status.Players);
                 else
                     serverPanelModel.Tip = "No players.";
             }      

+ 1 - 0
VeloeMinecraftLauncher/ViewModels/ViewModelBase.cs

@@ -100,6 +100,7 @@ public class ViewModelBase : ReactiveValidationObject
                 var ErrorMessageViewModel = new MessageWindowViewModel(message, "Error message", logfile: logfile);
                 var ErrorMessage = new MessageWindow()
                 {
+                    WindowStartupLocation = WindowStartupLocation.CenterOwner,
                     DataContext = ErrorMessageViewModel
                 };
                 //TODO change it to binding