Compare commits

...

6 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
727837c34b Reset cleanup flag on navigation to handle page reuse
Co-authored-by: shuaiyuanxx <128874481+shuaiyuanxx@users.noreply.github.com>
2026-01-13 06:39:42 +00:00
copilot-swe-agent[bot]
9f26707d4f Add flag to prevent double-cleanup in AppsListPage
Co-authored-by: shuaiyuanxx <128874481+shuaiyuanxx@users.noreply.github.com>
2026-01-13 06:38:54 +00:00
copilot-swe-agent[bot]
021d4bf188 Initial plan 2026-01-13 06:35:34 +00: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 76 additions and 2 deletions

View File

@@ -15,10 +15,13 @@ namespace Microsoft.PowerToys.QuickAccess.Flyout;
public sealed partial class AppsListPage : Page
{
private FlyoutNavigationContext? _context;
private bool _isCleanedUp = false;
public AppsListPage()
{
InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Disabled;
Unloaded += OnUnloaded;
}
public AllAppsViewModel ViewModel { get; private set; } = default!;
@@ -26,6 +29,7 @@ public sealed partial class AppsListPage : Page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
_isCleanedUp = false;
if (e.Parameter is FlyoutNavigationContext context)
{
@@ -36,6 +40,37 @@ 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()
{
if (_isCleanedUp)
{
return;
}
_isCleanedUp = true;
// 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

@@ -144,7 +144,7 @@ public sealed partial class MainWindow : WindowEx, IDisposable
var token = _trimCts.Token;
// Delay the trim to avoid aggressive GC during quick toggles
Task.Delay(2000, token).ContinueWith(
Task.Delay(5000, token).ContinueWith(
_ =>
{
if (token.IsCancellationRequested)
@@ -152,7 +152,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();
}
}