Skip to content

Commit

Permalink
perf: change newest uid after updating
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Jul 10, 2024
1 parent 7383e2f commit 59b52e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions Hollow/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override void Initialize()
AvaloniaXamlLoader.Load(this);
_provider = ConfigureServices();

//TODO: Platform specific
Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", AppInfo.CachesDir);
AvaloniaWebViewBuilder.Initialize(default);
}
Expand Down
6 changes: 4 additions & 2 deletions Hollow/Services/GachaService/GachaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Hollow.Helpers;
using Hollow.Models;
using Hollow.Services.ConfigurationService;
using Serilog;

namespace Hollow.Services.GachaService;

Expand Down Expand Up @@ -181,8 +182,9 @@ public Response<string> TryGetAuthKey()
return authKey;
}

var targetGachaLogUrl = authKey.Data;
return new Response<string> (true) {Data = targetGachaLogUrl.Split("&authkey=")[1].Split("&")[0]};
var targetGachaLogUrl = authKey.Data.Split("&authkey=")[1].Split("&")[0];
Log.Information("Get authKey: {0}", targetGachaLogUrl);
return new Response<string> (true) {Data = targetGachaLogUrl};
}

private Response<string> GetAuthKeyFromFile(string dataPath)
Expand Down
16 changes: 9 additions & 7 deletions Hollow/ViewModels/Pages/SignalSearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Navigated()
[ObservableProperty] private bool _controlEnabled = true;

[ObservableProperty] private ObservableCollection<string> _uidList = [];
[ObservableProperty] private string _selectedUid = "";
[ObservableProperty] private string? _selectedUid;

private Dictionary<string, GachaRecords>? _gachaRecords;
private Dictionary<string, AnalyzedGachaRecords>? _analyzedGachaRecords;
Expand Down Expand Up @@ -74,7 +74,7 @@ private void RemoveCoverage()
ControlEnabled = true;
}

private async Task LoadGachaRecords()
private async Task LoadGachaRecords(string? updatedUid = null)
{
IntoCoverage();

Expand All @@ -88,7 +88,6 @@ private async Task LoadGachaRecords()
ControlEnabled = true;
return;
}
await Task.Delay(100);

// Analyze
GetGachaLogShortMessage = Lang.SignalSearch_LoadGachaRecords_Analyze;
Expand All @@ -97,8 +96,8 @@ private async Task LoadGachaRecords()
item => GachaAnalyser.FromGachaRecords(item.Value));

UidList = new ObservableCollection<string>(_gachaRecords!.Keys);
SelectedUid = UidList[0];
SelectedAnalyzedGachaRecords = _analyzedGachaRecords[UidList[0]];
SelectedUid = UidList.FirstOrDefault(uid => uid == updatedUid) ?? UidList.First();
SelectedAnalyzedGachaRecords = _analyzedGachaRecords[SelectedUid];
await Task.Delay(100);

RemoveCoverage();
Expand All @@ -107,7 +106,10 @@ private async Task LoadGachaRecords()
[RelayCommand]
private void ChangeUid()
{
SelectedAnalyzedGachaRecords = _analyzedGachaRecords![SelectedUid];
if (SelectedUid != null && _analyzedGachaRecords!.TryGetValue(SelectedUid, out var value))
{
SelectedAnalyzedGachaRecords = value;
}
}

[RelayCommand]
Expand Down Expand Up @@ -148,7 +150,7 @@ private async Task UpdateByWebCaches()
var gachaRecord = await _gachaService.TryGetGachaLogs(authKey.Data, gachaProgress);

await File.WriteAllTextAsync(Path.Combine(AppInfo.GachaRecordsDir, $"{gachaRecord.Data.Info.Uid}.json"), JsonSerializer.Serialize(gachaRecord.Data, new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }));
await LoadGachaRecords();
await LoadGachaRecords(gachaRecord.Data.Info.Uid);
RemoveCoverage();
}
}
2 changes: 1 addition & 1 deletion Hollow/Views/Pages/SignalSearch.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Spacing="15"
VerticalAlignment="Center">
<ComboBox
IsVisible="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem, Converter={x:Static ObjectConverters.IsNotNull}}"
IsVisible="{Binding UidList.Count}"
ItemsSource="{Binding UidList}"
Name="UidComboBox"
SelectedItem="{Binding SelectedUid, Mode=TwoWay}"
Expand Down

0 comments on commit 59b52e8

Please sign in to comment.