mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
important: keep this pagecontext alive for the duration
if you don't, then eventually, we'll GC this object, and all objects that took a weak ref on it will throw.
This commit is contained in:
@@ -51,12 +51,15 @@ public sealed class CommandProviderWrapper : ICommandProviderContext
|
||||
|
||||
public bool SupportsPinning { get; private set; }
|
||||
|
||||
public TopLevelItemPageContext TopLevelPageContext { get; }
|
||||
|
||||
public CommandProviderWrapper(ICommandProvider provider, TaskScheduler mainThread)
|
||||
{
|
||||
// This ctor is only used for in-proc builtin commands. So the Unsafe!
|
||||
// calls are pretty dang safe actually.
|
||||
_commandProvider = new(provider);
|
||||
_taskScheduler = mainThread;
|
||||
TopLevelPageContext = new TopLevelItemPageContext(this, _taskScheduler);
|
||||
|
||||
// Hook the extension back into us
|
||||
ExtensionHost = new CommandPaletteHost(provider);
|
||||
@@ -81,6 +84,7 @@ public sealed class CommandProviderWrapper : ICommandProviderContext
|
||||
{
|
||||
_taskScheduler = mainThread;
|
||||
_commandProviderCache = commandProviderCache;
|
||||
TopLevelPageContext = new TopLevelItemPageContext(this, _taskScheduler);
|
||||
|
||||
Extension = extension;
|
||||
ExtensionHost = new CommandPaletteHost(extension);
|
||||
|
||||
@@ -103,8 +103,7 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
// May be called from a background thread
|
||||
private async Task<IEnumerable<TopLevelViewModel>> LoadTopLevelCommandsFromProvider(CommandProviderWrapper commandProvider)
|
||||
{
|
||||
TopLevelItemPageContext pageContext = new(commandProvider, _taskScheduler);
|
||||
WeakReference<IPageContext> weak = new(pageContext);
|
||||
WeakReference<IPageContext> weak = new(commandProvider.TopLevelPageContext);
|
||||
|
||||
await commandProvider.LoadTopLevelCommands(_serviceProvider, weak);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Microsoft.CmdPal.UI.ViewModels;
|
||||
/// Used as the PageContext for top-level items. Top level items are displayed
|
||||
/// on the MainListPage, which _we_ own. We need to have a placeholder page
|
||||
/// context for each provider that still connects those top-level items to the
|
||||
/// CommandProvider they came from.
|
||||
/// CommandProvider they came from.
|
||||
/// </summary>
|
||||
public partial class TopLevelItemPageContext : IPageContext
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user