Skip to content

Commit

Permalink
mods page opens instantly
Browse files Browse the repository at this point in the history
  • Loading branch information
phasephasephase committed Jan 1, 2024
1 parent 3f1f11e commit d1cc7d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion JiayiLauncher/Features/Game/Minecraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ await Task.Run(() =>

try
{
if (JiayiSettings.Instance!.OverrideModuleRequirement
if (JiayiSettings.Instance.OverrideModuleRequirement
&& Process.Modules.Count > JiayiSettings.Instance.ModuleRequirement[2])
break;

Expand Down
5 changes: 3 additions & 2 deletions JiayiLauncher/Features/Mods/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Net.Http;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using JiayiLauncher.Features.Stats;
using JiayiLauncher.Utils;

Expand Down Expand Up @@ -31,7 +32,7 @@ public Mod(string name, string path, List<string>? supportedVersions = null)
// for speed
private HttpResponseMessage? _response;

public bool IsValid()
public async Task<bool> IsValid()
{
if (InternetManager.OfflineMode) return true;
if (_response != null) return _response.IsSuccessStatusCode;
Expand All @@ -43,7 +44,7 @@ public bool IsValid()

try
{
using var response = InternetManager.Client.Send(request);
using var response = await InternetManager.Client.SendAsync(request);
_response = response;
return response.IsSuccessStatusCode;
}
Expand Down
13 changes: 11 additions & 2 deletions JiayiLauncher/Shared/Components/Mods/JiayiModCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<strong>@Mod.Name</strong>

<div class="right">
@if (!Mod.IsValid())
@if (!_isValid)
{
@if (Mod.FromInternet)
{
Expand Down Expand Up @@ -57,7 +57,7 @@
</div>
<p class="mod-version">Works on @(string.Join(", ", Mod.SupportedVersions).ToLower())</p>
<div class="mod-controls">
@if (Mod.IsValid())
@if (_isValid)
{
if (Mod.FromInternet && InternetManager.OfflineMode)
{
Expand Down Expand Up @@ -92,10 +92,19 @@
public IModalService ModalService { get; set; } = default!;

private bool _launching;
private bool _isValid = true;
private string _showLoadingBar => _launching ? "0.2" : "0";

private JiayiButton? _launchButton;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;

_isValid = await Mod.IsValid();
StateHasChanged();
}

private async Task LaunchClicked()
{
if (Launcher.Launching) return;
Expand Down

0 comments on commit d1cc7d4

Please sign in to comment.