Compare commits

...

4 Commits

Author SHA1 Message Date
Shawn Yuan
4e0ebfd6db Update src/settings-ui/QuickAccess.UI/QuickAccessXAML/MainWindow.xaml.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-13 14:38:10 +08:00
Shawn Yuan (from Dev Box)
3d510dc382 update 2026-01-13 14:14:24 +08:00
Shawn Yuan (from Dev Box)
8ffd88fdf3 memory optimization 2026-01-13 13:58:23 +08:00
Shawn Yuan (from Dev Box)
097cf7414b init 2026-01-13 12:27:21 +08:00
5 changed files with 71 additions and 3 deletions

View File

@@ -19,6 +19,8 @@ public sealed partial class AppsListPage : Page
public AppsListPage()
{
InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Disabled;
Unloaded += OnUnloaded;
}
public AllAppsViewModel ViewModel { get; private set; } = default!;
@@ -36,6 +38,30 @@ public sealed partial class AppsListPage : Page
}
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
CleanupPage();
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
CleanupPage();
}
private void CleanupPage()
{
// Clear the collection before cleaning up to release all item references
if (ViewModel != null)
{
ViewModel.FlyoutMenuItems.Clear();
}
DataContext = null;
ViewModel = null!;
_context = null;
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
if (_context == null || Frame == null)

View File

@@ -27,6 +27,7 @@ public sealed partial class LaunchPage : Page
public LaunchPage()
{
InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Disabled;
}
public LauncherViewModel ViewModel { get; private set; } = default!;
@@ -44,6 +45,12 @@ public sealed partial class LaunchPage : Page
}
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
DataContext = null;
}
private void SettingsBtn_Click(object sender, RoutedEventArgs e)
{
_coordinator?.OpenSettings();

View File

@@ -65,4 +65,16 @@ public sealed partial class ShellPage : Page
appsListPage.ViewModel?.RefreshSettings();
}
}
internal void NavigateToLaunchIfNeeded()
{
// Always clear FlyoutMenuItems to release memory
_allAppsViewModel?.FlyoutMenuItems.Clear();
// Navigate back to LaunchPage if on AppsListPage
if (ContentFrame.Content is AppsListPage)
{
NavigateToLaunch();
}
}
}

View File

@@ -143,8 +143,11 @@ public sealed partial class MainWindow : WindowEx, IDisposable
_trimCts = new CancellationTokenSource();
var token = _trimCts.Token;
// Delay the trim to avoid aggressive GC during quick toggles
Task.Delay(2000, token).ContinueWith(
// Delay memory trim for 5 seconds to avoid aggressive GC during quick toggles.
// A shorter delay (previously 2 seconds) caused heavy UI (e.g. AppsListPage) to be
// torn down and rebuilt when users quickly reopened the window, which hurt perceived
// responsiveness more than the extra few seconds of retained memory.
Task.Delay(5000, token).ContinueWith(
_ =>
{
if (token.IsCancellationRequested)
@@ -152,7 +155,24 @@ public sealed partial class MainWindow : WindowEx, IDisposable
return;
}
TrimMemory();
_dispatcherQueue.TryEnqueue(() =>
{
// Navigate back to LaunchPage before memory trim to release AppsListPage resources
ShellHost.NavigateToLaunchIfNeeded();
// Give UI time to complete cleanup before forcing GC
Task.Delay(500, token).ContinueWith(
__ =>
{
if (!token.IsCancellationRequested)
{
_dispatcherQueue.TryEnqueue(TrimMemory);
}
},
token,
TaskContinuationOptions.None,
TaskScheduler.Default);
});
},
token,
TaskContinuationOptions.None,

View File

@@ -154,6 +154,9 @@ public sealed class AllAppsViewModel : Observable
if (_coordinator.UpdateModuleEnabled(flyoutItem.Tag, flyoutItem.IsEnabled))
{
_coordinator.NotifyUserSettingsInteraction();
// Trigger re-sort immediately when status changes on UI
RefreshFlyoutMenuItems();
}
}