mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[MonacoPreviewHandler][Settings] Resolve preview handler race (#16180)
* Register .markdown with the correct handler * Fix spelling * Move file name extensions from "expect.txt" to "excludes.txt" * Revert "Move file name extensions from "expect.txt" to "excludes.txt"" This reverts commit710d5a4968. I must have misunderstood the instructions. * Revert "Register .markdown with the correct handler" This reverts commit5c37b009f3. * Work in progress * Code ready for testing * Update excludes.txt * Update excludes.txt * Update modulesRegistry.h * Update modulesRegistry.h For the want of an exclamation mark, a kingdom is lost! * Update modulesRegistry.h * Work on modulesRegistry.h per code review in 16180 Removed all previous exclusions from Monaco preview handler. Added a new exclusion: SVGZ. It's a binary file that Monaco cannot, in any meaningful way, read. * Update expect.txt * Update accessory files * Disable machine-wide checks for performance reasons
This commit is contained in:
@@ -13,8 +13,14 @@ namespace NonLocalizable
|
||||
const static wchar_t* MONACO_LANGUAGES_FILE_NAME = L"modules\\FileExplorerPreview\\monaco_languages.json";
|
||||
const static wchar_t* ListID = L"list";
|
||||
const static wchar_t* ExtensionsID = L"extensions";
|
||||
const static wchar_t* MDExtension = L".md";
|
||||
const static wchar_t* SVGExtension = L".svg";
|
||||
const static std::vector<std::wstring> ExtSVG = { L".svg" };
|
||||
const static std::vector<std::wstring> ExtMarkdown = { L".md", L".markdown", L".mdown", L".mkdn", L".mkd", L".mdwn", L".mdtxt", L".mdtext" };
|
||||
const static std::vector<std::wstring> ExtPDF = { L".pdf" };
|
||||
const static std::vector<std::wstring> ExtGCode = { L".gcode" };
|
||||
const static std::vector<std::wstring> ExtSTL = { L".stl" };
|
||||
const static std::vector<std::wstring> ExtNoNoNo = {
|
||||
L".svgz" //Monaco cannot handle this file type at all; it's a binary file.
|
||||
};
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getSvgPreviewHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -30,7 +36,7 @@ inline registry::ChangeSet getSvgPreviewHandlerChangeSet(const std::wstring inst
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.PreviewHandler.Svg.SvgPreviewHandler",
|
||||
L"Svg Preview Handler",
|
||||
{ L".svg" });
|
||||
NonLocalizable::ExtSVG);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getMdPreviewHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -44,14 +50,23 @@ inline registry::ChangeSet getMdPreviewHandlerChangeSet(const std::wstring insta
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.PreviewHandler.Markdown.MarkdownPreviewHandler",
|
||||
L"Markdown Preview Handler",
|
||||
{ L".md" });
|
||||
NonLocalizable::ExtMarkdown);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getMonacoPreviewHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
{
|
||||
using namespace registry::shellex;
|
||||
|
||||
// Set up a list of extensions for the preview handler to take over
|
||||
std::vector<std::wstring> extensions;
|
||||
|
||||
// Set up a list of extensions that Monaco support but the preview handler shouldn't take over
|
||||
std::vector<std::wstring> ExtExclusions;
|
||||
ExtExclusions.insert(ExtExclusions.end(), NonLocalizable::ExtMarkdown.begin(), NonLocalizable::ExtMarkdown.end());
|
||||
ExtExclusions.insert(ExtExclusions.end(), NonLocalizable::ExtSVG.begin(), NonLocalizable::ExtSVG.end());
|
||||
ExtExclusions.insert(ExtExclusions.end(), NonLocalizable::ExtNoNoNo.begin(), NonLocalizable::ExtNoNoNo.end());
|
||||
bool IsExcluded = false;
|
||||
|
||||
std::wstring languagesFilePath = fs::path{ installationDir } / NonLocalizable::MONACO_LANGUAGES_FILE_NAME;
|
||||
auto json = json::from_file(languagesFilePath);
|
||||
|
||||
@@ -68,13 +83,19 @@ inline registry::ChangeSet getMonacoPreviewHandlerChangeSet(const std::wstring i
|
||||
for (uint32_t j = 0; j < extensionsList.Size(); ++j)
|
||||
{
|
||||
auto extension = extensionsList.GetStringAt(j);
|
||||
|
||||
// Ignore extensions we already have dedicated handlers for
|
||||
if (std::wstring{ extension } == std::wstring{ NonLocalizable::MDExtension } ||
|
||||
std::wstring{ extension } == std::wstring{ NonLocalizable::SVGExtension })
|
||||
|
||||
// Ignore extensions in the exclusion list
|
||||
IsExcluded = false;
|
||||
|
||||
for (std::wstring k : ExtExclusions)
|
||||
{
|
||||
continue;
|
||||
if (std::wstring{ extension } == k)
|
||||
{
|
||||
IsExcluded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (IsExcluded) { continue; }
|
||||
extensions.push_back(std::wstring{ extension });
|
||||
}
|
||||
}
|
||||
@@ -106,7 +127,7 @@ inline registry::ChangeSet getPdfPreviewHandlerChangeSet(const std::wstring inst
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.PreviewHandler.Pdf.PdfPreviewHandler",
|
||||
L"Pdf Preview Handler",
|
||||
{ L".pdf" });
|
||||
NonLocalizable::ExtPDF);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getGcodePreviewHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -120,7 +141,7 @@ inline registry::ChangeSet getGcodePreviewHandlerChangeSet(const std::wstring in
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.PreviewHandler.Gcode.GcodePreviewHandler",
|
||||
L"G-code Preview Handler",
|
||||
{ L".gcode" });
|
||||
NonLocalizable::ExtGCode);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getSvgThumbnailHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -134,7 +155,7 @@ inline registry::ChangeSet getSvgThumbnailHandlerChangeSet(const std::wstring in
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.ThumbnailHandler.Svg.SvgThumbnailProvider",
|
||||
L"Svg Thumbnail Provider",
|
||||
{ L".svg" });
|
||||
NonLocalizable::ExtSVG);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getPdfThumbnailHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -148,7 +169,7 @@ inline registry::ChangeSet getPdfThumbnailHandlerChangeSet(const std::wstring in
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.ThumbnailHandler.Pdf.PdfThumbnailProvider",
|
||||
L"Pdf Thumbnail Provider",
|
||||
{ L".pdf" });
|
||||
NonLocalizable::ExtPDF);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getGcodeThumbnailHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -162,7 +183,7 @@ inline registry::ChangeSet getGcodeThumbnailHandlerChangeSet(const std::wstring
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.ThumbnailHandler.Gcode.GcodeThumbnailProvider",
|
||||
L"G-code Thumbnail Provider",
|
||||
{ L".gcode" });
|
||||
NonLocalizable::ExtGCode);
|
||||
}
|
||||
|
||||
inline registry::ChangeSet getStlThumbnailHandlerChangeSet(const std::wstring installationDir, const bool perUser)
|
||||
@@ -176,7 +197,7 @@ inline registry::ChangeSet getStlThumbnailHandlerChangeSet(const std::wstring in
|
||||
registry::DOTNET_COMPONENT_CATEGORY_CLSID,
|
||||
L"Microsoft.PowerToys.ThumbnailHandler.Stl.StlThumbnailProvider",
|
||||
L"Stl Thumbnail Provider",
|
||||
{ L".stl" });
|
||||
NonLocalizable::ExtSTL);
|
||||
}
|
||||
|
||||
inline std::vector<registry::ChangeSet> getAllModulesChangeSets(const std::wstring installationDir)
|
||||
@@ -191,4 +212,4 @@ inline std::vector<registry::ChangeSet> getAllModulesChangeSets(const std::wstri
|
||||
getPdfThumbnailHandlerChangeSet(installationDir, PER_USER),
|
||||
getGcodeThumbnailHandlerChangeSet(installationDir, PER_USER),
|
||||
getStlThumbnailHandlerChangeSet(installationDir, PER_USER) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@
|
||||
<value>Show recently used strings</value>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_MD.Header" xml:space="preserve">
|
||||
<value>Enable Markdown (.md) preview</value>
|
||||
<value>Enable Markdown preview (.md, .markdown, .mdown, .mkdn, .mkd, .mdwn, .mdtxt, .mdtext)</value>
|
||||
<comment>Do not loc "Markdown". Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_Monaco.Header" xml:space="preserve">
|
||||
|
||||
Reference in New Issue
Block a user