Skip to content

Commit

Permalink
Merge pull request #20 from slxdy/clarity-improvements
Browse files Browse the repository at this point in the history
Faster startup and install confirmation
  • Loading branch information
HerpDerpinstine authored Nov 15, 2024
2 parents 334f324 + 67e3a9c commit e8e1af8
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<AvaloniaVersion>11.1.4</AvaloniaVersion>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion MelonLoader.Installer/MLManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ internal static class MLManager
private static MLVersion? localBuild;

public static List<MLVersion> Versions { get; private set; } = [];
public static bool Initialized { get; private set; }

static MLManager()
{
Expand Down
12 changes: 6 additions & 6 deletions MelonLoader.Installer/MelonLoader.Installer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -33,12 +33,12 @@
<!--Condition
below is needed to remove Avalonia.Diagnostics package from build output in Release
configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.0" />
<PackageReference Include="Avalonia" Version="11.2.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.0" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.0" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />

<PackageReference Include="Gameloop.Vdf" Version="0.6.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
7 changes: 3 additions & 4 deletions MelonLoader.Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ private static void Main(string[] args)
if (!CheckProcessLock())
return;

if (!Updater.UpdateIfPossible())
MLManager.Init();

BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

Exiting?.Invoke();
Expand Down Expand Up @@ -95,11 +92,13 @@ private static bool CheckProcessLock()

internal static void GrabAttention()
=> GrabAttention(Process.GetCurrentProcess());

private static void GrabAttention(Process process)
{
nint processHandle = process.MainWindowHandle;
var processHandle = process.MainWindowHandle;
if (WindowsUtils.IsIconic(processHandle))
WindowsUtils.ShowWindow(processHandle, 9);

WindowsUtils.SetForegroundWindow(processHandle);
WindowsUtils.BringWindowToTop(processHandle);
}
Expand Down
29 changes: 29 additions & 0 deletions MelonLoader.Installer/ViewModels/DetailsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public class DetailsViewModel(GameModel game) : ViewModelBase
{
private bool _installing;
private bool _confirmation;
private bool _offline;

public GameModel Game => game;

Expand All @@ -13,6 +15,33 @@ public bool Installing
{
_installing = value;
OnPropertyChanged(nameof(Installing));
OnPropertyChanged(nameof(CanInstall));
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool Confirmation
{
get => _confirmation;
set
{
_confirmation = value;
OnPropertyChanged(nameof(Confirmation));
OnPropertyChanged(nameof(CanInstall));
}
}

public bool Offline
{
get => _offline;
set
{
_offline = value;
OnPropertyChanged(nameof(Confirmation));
OnPropertyChanged(nameof(EnableSettings));
}
}

public bool CanInstall => !Installing && !Confirmation;
public bool EnableSettings => !Offline && !Installing;
}
12 changes: 12 additions & 0 deletions MelonLoader.Installer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ namespace MelonLoader.Installer.ViewModels;

public partial class MainViewModel : ViewModelBase
{
private static bool _ready;

public bool Ready
{
get => _ready;
set
{
_ready = value;
OnPropertyChanged(nameof(Ready));
}
}

public ObservableCollection<GameModel> Games => GameManager.Games;

public string Version => 'v' + Program.Version.ToString(3);
Expand Down
12 changes: 6 additions & 6 deletions MelonLoader.Installer/Views/DetailsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
<TextBlock Grid.Row="7" HorizontalAlignment="Center" FontSize="18" Foreground="#7FFF"
Text="{Binding Game.MLStatusText}" />
<TextBlock Grid.Row="9" HorizontalAlignment="Center" Foreground="#BFFF">Select a version</TextBlock>
<ComboBox SelectionChanged="VersionSelectHandler"
<ComboBox SelectionChanged="VersionSelectHandler" IsEnabled="{Binding EnableSettings}"
Name="VersionCombobox" Grid.Row="10" Margin="5" HorizontalAlignment="Center"
SelectedIndex="0" MaxDropDownHeight="150" />
<TextBlock Grid.Row="11" Tapped="SelectZipHandler" HorizontalAlignment="Center"
<TextBlock Grid.Row="11" Tapped="SelectZipHandler" HorizontalAlignment="Center" IsEnabled="{Binding EnableSettings}"
Foreground="Gray" TextDecorations="Underline" FontSize="13" Cursor="Hand">Or select a
zipped version</TextBlock>
<StackPanel Grid.Row="12">
<CheckBox Name="NightlyCheck"
<CheckBox Name="NightlyCheck" IsEnabled="{Binding EnableSettings}"
ToolTip.Tip="Enables bleeding-edge builds. ONLY ENABLE IF YOU KNOW WHAT YOU'RE DOING!"
Click="NightlyToggleHandler" HorizontalAlignment="Center">Enable Nightly builds</CheckBox>
<CheckBox IsEnabled="{Binding !Installing}" Name="KeepFilesCheck"
Expand All @@ -42,8 +42,8 @@
IsVisible="{Binding Game.MLInstalled}" IsChecked="True">Keep mods and settings</CheckBox>
</StackPanel>
<Grid Grid.Row="13" Margin="10" Width="300" HorizontalAlignment="Center">
<Grid IsVisible="{Binding !Installing}" ColumnDefinitions="*, auto">
<Button Click="InstallHandler" Name="InstallButton" Grid.Column="0"
<Grid IsVisible="{Binding CanInstall}" ColumnDefinitions="*, auto">
<Button Click="InstallHandler" IsEnabled="{Binding !Offline}" Name="InstallButton" Grid.Column="0"
HorizontalAlignment="Stretch" Background="#383" Height="40"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
FontSize="18">Install</Button>
Expand All @@ -52,7 +52,7 @@
Background="#833" Height="40" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center" FontSize="18">Uninstall</Button>
</Grid>
<Grid IsVisible="{Binding Installing}">
<Grid IsVisible="{Binding !CanInstall}">
<ProgressBar Name="Progress" Height="40" Background="#4383" Foreground="#383" />
<TextBlock Name="InstallStatus" HorizontalAlignment="Center"
VerticalAlignment="Center" Opacity="0.7" FontSize="14" />
Expand Down
22 changes: 10 additions & 12 deletions MelonLoader.Installer/Views/DetailsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ protected override void OnDataContextChanged(EventArgs e)

if (!MLManager.Init())
{
InstallButton.IsEnabled = false;
NightlyCheck.IsEnabled = false;
VersionCombobox.IsEnabled = false;
Model.Offline = true;
ErrorBox.Open("Failed to fetch MelonLoader releases. Ensure you're online.");
}
}
Expand Down Expand Up @@ -91,6 +89,8 @@ public void UpdateVersionInfo()
if (Model == null || VersionCombobox.SelectedItem == null)
return;

Model.Confirmation = false;

MelonIcon.Opacity = Model.Game.MLInstalled ? 1 : 0.3;

if (Model.Game.MLVersion == null)
Expand All @@ -99,7 +99,7 @@ public void UpdateVersionInfo()
return;
}

var comp = ((MLVersion)VersionCombobox.SelectedItem).Version.ComparePrecedenceTo(Model.Game.MLVersion);
var comp = ((MLVersion)VersionCombobox.SelectedItem).Version.CompareSortOrderTo(Model.Game.MLVersion);

InstallButton.Content = comp switch
{
Expand All @@ -118,8 +118,6 @@ private void InstallHandler(object sender, RoutedEventArgs args)
}

Model.Installing = true;
NightlyCheck.IsEnabled = false;
VersionCombobox.IsEnabled = false;

_ = MLManager.InstallAsync(Path.GetDirectoryName(Model.Game.Path)!, Model.Game.MLInstalled && !KeepFilesCheck.IsChecked!.Value,
(MLVersion)VersionCombobox.SelectedItem!, Model.Game.Is32Bit,
Expand All @@ -141,16 +139,18 @@ private void OnInstallFinished(string? errorMessage)
if (Model == null)
return;

Model.Installing = false;
NightlyCheck.IsEnabled = true;
VersionCombobox.IsEnabled = true;

Model.Game.ValidateGame();

Model.Installing = false;

if (errorMessage != null)
{
ErrorBox.Open(errorMessage);
return;
}

InstallStatus.Text = "Done!";
Model.Confirmation = true;
}

private void OpenDirHandler(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -205,8 +205,6 @@ private async void SelectZipHandler(object sender, TappedEventArgs args)
var path = files[0].Path.LocalPath;

Model.Installing = true;
NightlyCheck.IsEnabled = false;
VersionCombobox.IsEnabled = false;

_ = Task.Run(() => MLManager.SetLocalZip(path,
(progress, newStatus) => Dispatcher.UIThread.Post(() => OnInstallProgress(progress, newStatus)),
Expand Down
11 changes: 7 additions & 4 deletions MelonLoader.Installer/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ If you can't find your game on the list, add it manually.</TextBlock>
<Border Grid.Row="2" Background="#3223" CornerRadius="8" Margin="0 10" ClipToBounds="True">
<Grid>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Games}" Margin="10">
<ItemsControl IsVisible="{Binding Ready}" ItemsSource="{Binding Games}" Margin="10">
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:GameControl DataContext="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<TextBlock Name="NoGamesText" Foreground="#3FFF" HorizontalAlignment="Center"
<TextBlock Name="NoGamesText" IsVisible="False" Foreground="#3FFF" HorizontalAlignment="Center"
VerticalAlignment="Center" TextAlignment="Center" xml:space="preserve">
No Unity games have been found on your device.
Please add one manually using the button below.
</TextBlock>
<TextBlock Name="LoadingText" IsVisible="{Binding !Ready}" Foreground="#9FFF" FontSize="20" HorizontalAlignment="Center"
VerticalAlignment="Center" TextAlignment="Center">
Loading...
</TextBlock>
</Grid>
</Border>
<Button Grid.Row="3" HorizontalAlignment="Right" Click="AddGameManuallyHandler">Add Game
Manually</Button>
<Button Grid.Row="3" IsEnabled="{Binding Ready}" HorizontalAlignment="Right" Click="AddGameManuallyHandler">Add Game Manually</Button>
<StackPanel Height="38" Grid.Row="3" Spacing="1" Orientation="Horizontal">
<Button Click="MelonWikiLink" ToolTip.Tip="MelonWiki"
ToolTip.Placement="RightEdgeAlignedBottom" Padding="3" CornerRadius="1000"
Expand Down
27 changes: 27 additions & 0 deletions MelonLoader.Installer/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using MelonLoader.Installer.ViewModels;
using System.Collections.Specialized;

namespace MelonLoader.Installer.Views;

public partial class MainView : UserControl
{
public MainViewModel? Model => (MainViewModel?)DataContext;

public MainView()
{
InitializeComponent();
}

protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);

if (Model == null)
return;

Task.Run(InitServicesAsync);
}

private void InitServicesAsync()
{
MLManager.Init();
GameManager.Init();

Dispatcher.UIThread.Post(Init);
}

private void Init()
{
Model!.Ready = true;

OnGameListUpdate(null, null);
GameManager.Games.CollectionChanged += OnGameListUpdate;
Expand Down
5 changes: 0 additions & 5 deletions MelonLoader.Installer/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public MainWindow()

Activated += new EventHandler(OnActivation);

if (Updater.CurrentState != Updater.State.None)
GameManager.Init();

InitializeComponent();

if (Updater.CurrentState == Updater.State.Updating)
Expand Down Expand Up @@ -68,8 +65,6 @@ protected override void OnClosing(WindowClosingEventArgs e)

public void ShowMainView()
{
MLManager.Init();
GameManager.Init();
Content = new MainView();
}

Expand Down

0 comments on commit e8e1af8

Please sign in to comment.