Skip to content

Commit ff5c0ca

Browse files
authored
[UX] Put game file cleanup button to navigation bar (#857)
* [UX] Put game file cleanup button to navigation bar As FileCleanupPage is not really a "page" rather an overlay, we manually invoke the overlay the same way as the QS invokes them and force the NavigationViewControl to select the last item/page back so the UI literally says "nothing happened here" i havent slept all night because my dumbass brain so help me * Add trycatch on filescleanup navigator * Avoid sending error to Sentry twice note to self: SendException already send the exception data to Sentry yes, i'm the one who made it do that in the first place
1 parent 3230f77 commit ff5c0ca

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

CollapseLauncher/XAMLs/MainApp/MainPage.Navigation.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using CollapseLauncher.Extension;
2+
using CollapseLauncher.Helper.Loading;
23
using CollapseLauncher.Helper.Metadata;
34
using CollapseLauncher.Interfaces;
45
using CollapseLauncher.Pages;
56
using CommunityToolkit.WinUI;
67
using Hi3Helper;
8+
using Hi3Helper.SentryHelper;
79
using Microsoft.UI;
810
using Microsoft.UI.Input;
911
using Microsoft.UI.Xaml;
@@ -15,6 +17,7 @@
1517
using System.Threading.Tasks;
1618
using static CollapseLauncher.InnerLauncherConfig;
1719
using static CollapseLauncher.Statics.GamePropertyVault;
20+
using static Hi3Helper.Locale;
1821
using static Hi3Helper.Logger;
1922
using static Hi3Helper.Shared.Region.LauncherConfig;
2023

@@ -51,6 +54,7 @@ void Impl()
5154
FontIcon IconCaches = new FontIcon { Glyph = m_isWindows11 ? "" : "" };
5255
FontIcon IconGameSettings = new FontIcon { Glyph = "" };
5356
FontIcon IconAppSettings = new FontIcon { Glyph = "" };
57+
FontIcon IconFilesCleanup = new FontIcon { Glyph = "" };
5458

5559
if (m_appMode == AppMode.Hi3CacheUpdater)
5660
{
@@ -109,6 +113,10 @@ void Impl()
109113
break;
110114
}
111115

116+
NavigationViewControl.FooterMenuItems.Add(new NavigationViewItem
117+
{ Icon = IconFilesCleanup, Tag = "filescleanup"}
118+
.BindNavigationViewItemText("_FileCleanupPage", "Title"));
119+
112120
if (NavigationViewControl.SettingsItem is NavigationViewItem SettingsItem)
113121
{
114122
SettingsItem.Icon = IconAppSettings;
@@ -246,7 +254,7 @@ private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvoke
246254
NavigateInnerSwitch(itemTag);
247255
}
248256

249-
private void NavigateInnerSwitch(string itemTag)
257+
private async void NavigateInnerSwitch(string itemTag)
250258
{
251259
if (itemTag == PreviousTag) return;
252260
switch (itemTag)
@@ -255,6 +263,30 @@ private void NavigateInnerSwitch(string itemTag)
255263
Navigate(typeof(HomePage), itemTag);
256264
break;
257265

266+
case "filescleanup":
267+
LoadingMessageHelper.ShowLoadingFrame();
268+
// Initialize and get game state, then get the latest package info
269+
LoadingMessageHelper.SetMessage(Lang._FileCleanupPage.LoadingTitle,
270+
Lang._FileCleanupPage.LoadingSubtitle2);
271+
272+
try
273+
{
274+
if (CurrentGameProperty?.GameInstall != null)
275+
await CurrentGameProperty.GameInstall.CleanUpGameFiles();
276+
}
277+
catch (Exception ex)
278+
{
279+
LoadingMessageHelper.HideLoadingFrame();
280+
LogWriteLine($"[NavigateInnerSwitch(filescleanup] Error while calling the CleanUpGameFiles method!\r\n{ex}", LogType.Error, true);
281+
282+
ErrorSender.SendException(ex);
283+
}
284+
285+
// Manually reselect last item in toolbar as CleanUp is an overlay
286+
NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems.OfType<NavigationViewItem>()
287+
.FirstOrDefault(x => x.Tag is string tag && tag == PreviousTag);
288+
break;
289+
258290
case "repair":
259291
if (!(GetCurrentGameProperty().GameVersion?.GamePreset.IsRepairEnabled ?? false))
260292
Navigate(typeof(UnavailablePage), itemTag);

0 commit comments

Comments
 (0)