From 41cfa201637187995d0bb8bd678e7fb877f791ea Mon Sep 17 00:00:00 2001 From: "Gordon Lam (SH)" Date: Mon, 30 Jun 2025 11:00:55 +0800 Subject: [PATCH] Make the feature default to be off --- .../Data/IndexerListItem.cs | 14 +++++++++++--- .../IndexerCommandsProvider.cs | 4 +--- .../Pages/ActionsListContextItem.cs | 6 +----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs index 59084c5120..cd56f1c624 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Data/IndexerListItem.cs @@ -14,6 +14,15 @@ namespace Microsoft.CmdPal.Ext.Indexer.Data; internal sealed partial class IndexerListItem : ListItem { + internal static readonly bool IsActionsFeatureEnabled = GetFeatureFlag(); + + private static bool GetFeatureFlag() + { + var env = System.Environment.GetEnvironmentVariable("CMDPAL_ENABLE_ACTIONS_LIST"); + return !string.IsNullOrEmpty(env) && + (env == "1" || env.Equals("true", System.StringComparison.OrdinalIgnoreCase)); + } + internal string FilePath { get; private set; } public IndexerListItem( @@ -44,8 +53,8 @@ internal sealed partial class IndexerListItem : ListItem IContextItem[] moreCommands = [ ..context, new CommandContextItem(new OpenWithCommand(indexerItem))]; - /* - if (ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)) + + if (IsActionsFeatureEnabled && ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)) { var actionsListContextItem = new ActionsListContextItem(indexerItem.FullPath); if (actionsListContextItem.AnyActions()) @@ -56,7 +65,6 @@ internal sealed partial class IndexerListItem : ListItem ]; } } - */ MoreCommands = [ .. moreCommands, diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs index 90dfaaf7fe..605e3c70ff 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/IndexerCommandsProvider.cs @@ -20,12 +20,10 @@ public partial class IndexerCommandsProvider : CommandProvider DisplayName = Resources.IndexerCommandsProvider_DisplayName; Icon = Icons.FileExplorer; - /* - if (ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)) + if (IndexerListItem.IsActionsFeatureEnabled && ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4)) { _ = ActionRuntimeManager.InstanceAsync; } - */ } public override ICommandItem[] TopLevelCommands() diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs index 12b0fdb24b..d8a9d15316 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Pages/ActionsListContextItem.cs @@ -19,10 +19,10 @@ namespace Microsoft.CmdPal.Ext.Indexer.Pages; internal sealed partial class ActionsListContextItem : CommandContextItem, IDisposable { - // private static ActionRuntime actionRuntime; private readonly string fullPath; private readonly List actions = []; private static readonly Lock UpdateMoreCommandsLock = new(); + private static ActionRuntime actionRuntime; public ActionsListContextItem(string fullPath) : base(new NoOpCommand()) @@ -43,7 +43,6 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp private void UpdateMoreCommands() { - /* lock (UpdateMoreCommandsLock) { if (actionRuntime == null) @@ -96,12 +95,10 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp { Logger.LogError($"Error updating commands: {ex.Message}"); } - */ } public void Dispose() { - /* lock (UpdateMoreCommandsLock) { if (actionRuntime != null) @@ -109,6 +106,5 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed; } } - */ } }