Compare commits

...

1 Commits

Author SHA1 Message Date
Mike Griese
398b9e5444 CmdPal: make actions loading a bit more stable
Mostly stashing this so I remember to come back to it next week.

I was seeing some oddities with actions failing to load on my OS build.
Then I realized that if the actions fail to load, we'll reset the COM
object for the runtime and re-create it. Well if GetActionsForInputs
fails once, it'll probably fail the next time?

anyways, this tries to make that a wee bit more stable.
2025-06-21 06:26:34 -05:00

View File

@@ -2,10 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Indexer.Commands; using Microsoft.CmdPal.Ext.Indexer.Commands;
using Microsoft.CmdPal.Ext.Indexer.Data; using Microsoft.CmdPal.Ext.Indexer.Data;
using Microsoft.CmdPal.Ext.Indexer.Properties; using Microsoft.CmdPal.Ext.Indexer.Properties;
@@ -41,9 +43,17 @@ internal sealed partial class ActionsListContextItem : CommandContextItem
private void UpdateMoreCommands() private void UpdateMoreCommands()
{ {
try // TODO! probably should OS version check to make sure that
// we're on an OS version that supports actions
//
// wait no that's weird - we're already inside of a
// ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)
// check here.
//
// so I don't know why this is an invalid cast down in GetActionsForInputs
lock (UpdateMoreCommandsLock)
{ {
lock (UpdateMoreCommandsLock) try
{ {
if (actionRuntime == null) if (actionRuntime == null)
{ {
@@ -54,7 +64,19 @@ internal sealed partial class ActionsListContextItem : CommandContextItem
actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed; actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed;
actionRuntime.ActionCatalog.Changed += ActionCatalog_Changed; actionRuntime.ActionCatalog.Changed += ActionCatalog_Changed;
} }
catch
{
actionRuntime = null;
}
}
if (actionRuntime == null)
{
return;
}
try
{
var extension = System.IO.Path.GetExtension(fullPath).ToLower(CultureInfo.InvariantCulture); var extension = System.IO.Path.GetExtension(fullPath).ToLower(CultureInfo.InvariantCulture);
ActionEntity entity = null; ActionEntity entity = null;
if (extension != null) if (extension != null)
@@ -77,7 +99,9 @@ internal sealed partial class ActionsListContextItem : CommandContextItem
lock (actions) lock (actions)
{ {
actions.Clear(); actions.Clear();
foreach (var actionInstance in actionRuntime.ActionCatalog.GetActionsForInputs([entity])) ActionEntity[] inputs = [entity];
var actionsInstances = actionRuntime.ActionCatalog.GetActionsForInputs(inputs);
foreach (var actionInstance in actionsInstances)
{ {
actions.Add(new CommandContextItem(new ExecuteActionCommand(actionInstance))); actions.Add(new CommandContextItem(new ExecuteActionCommand(actionInstance)));
} }
@@ -85,9 +109,9 @@ internal sealed partial class ActionsListContextItem : CommandContextItem
MoreCommands = [.. actions]; MoreCommands = [.. actions];
} }
} }
catch catch (Exception e)
{ {
actionRuntime = null; Logger.LogError("Error getting actions", e);
} }
} }
} }