From d0263b86acb2b99fb92fb1a30eb32854526f736f Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Tue, 23 Jun 2026 18:00:46 -0500 Subject: [PATCH] tsm: use the much cheaper & non-async 26100 AppExtension APIs when possible (#20356) GetPublicPath doesn't require async _or_ Windows.Storage! FindAll is just the Sync version of FindAllAsync! --- .../CascadiaSettingsSerialization.cpp | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp index 2ac2e4c676..af32e4e955 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp @@ -395,7 +395,14 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings(bool generateExtensio try { const auto catalog = AppExtensionCatalog::Open(AppExtensionHostName); - extensions = extractValueFromTaskWithoutMainThreadAwait(catalog.FindAllAsync()); + if (auto catalog2{ catalog.try_as() }) + { + extensions = catalog2.FindAll(); + } + else + { + extensions = extractValueFromTaskWithoutMainThreadAwait(catalog.FindAllAsync()); + } } CATCH_LOG(); @@ -417,20 +424,37 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings(bool generateExtensio continue; } - // Likewise, getting the public folder from an extension is an async operation. - auto foundFolder = extractValueFromTaskWithoutMainThreadAwait(ext.GetPublicFolderAsync()); - if (!foundFolder) + winrt::hstring publicFolderPath; + if (auto ext3{ ext.try_as() }) { - continue; + // Windows 11 24H2 and above support a much faster, much less + // Windows.Storage-y API. + publicFolderPath = ext3.GetPublicPath(); + if (publicFolderPath.empty()) + { + // No point in falling through to GetPublicFolderAsync; + // it won't work. + continue; + } + } + else + { + // Likewise, getting the public folder from an extension is an async operation. + auto foundFolder = extractValueFromTaskWithoutMainThreadAwait(ext.GetPublicFolderAsync()); + if (!foundFolder) + { + continue; + } + + // the StorageFolder class has its own methods for obtaining the files within the folder + // however, all those methods are Async methods + // you may have noticed that we need to resort to clunky implementations for async operations + // (they are in extractValueFromTaskWithoutMainThreadAwait) + // so for now we will just take the folder path and access the files that way + publicFolderPath = foundFolder.Path(); } - // the StorageFolder class has its own methods for obtaining the files within the folder - // however, all those methods are Async methods - // you may have noticed that we need to resort to clunky implementations for async operations - // (they are in extractValueFromTaskWithoutMainThreadAwait) - // so for now we will just take the folder path and access the files that way - const auto path = buildPath(foundFolder.Path(), FragmentsSubDirectory); - + const auto path = buildPath(publicFolderPath, FragmentsSubDirectory); if (std::filesystem::is_directory(path)) { // MSIX does not support machine-wide scope