[GPO] Add policies for configuring utilities enabled states (#21411)

* Add GPOWrapper headers and C++/WinRT library

* Check GPO before starting utilities

* Show message on GPO having disabled preview panes.

* Don't generate thumbnails if GPO disabled

* Fix FancyZonesEditor unable to recognize GPOWrapper

* Move settings view models to the settings project

* Use GPO to block enabling utilities in Settings

* Hide context menu entries when gpo disables utilities

* Apply gpo policies when enabling PowerToys on runner

* Add version and metadata to dll

* Add GPOWrapper to the installer

* Fix MSBuild errors on WPF apps by using Projection

* Signing

* Add gpo files and publish them

* Add GPO policies to the bug report tool

* Add some documentation for using GPO

* Mention support to actual lowest supported version of Windows

* Move PowerToys to the root of administrative templates tree

* Save policies on Software\Policies\PowerToys

* Support both machine and user scopes

* Fix documentation to reference computer and user scopes

* Mention incompatibility with outlook in gpo

* Set a better folder structure for gpo assets

* Move PDF Handler warning to the description

* Update doc/gpo/README.md

Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>

* Add actual minimum version of PowerToys to gpo files

* Fix identation

* Remove GPOWrapper Readme

* Add Active Directory instructions to doc

Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
Jaime Bernardo
2022-10-26 14:02:31 +01:00
committed by GitHub
parent 1ff5fa8794
commit a63288009a
182 changed files with 3257 additions and 449 deletions

View File

@@ -31,12 +31,25 @@
</Compile>
</ItemGroup>
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -43,6 +43,20 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
/// <param name="dataSource">Stream reference to access source file.</param>
public override void DoPreview<T>(T dataSource)
{
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredGcodePreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GpoDisabledErrorText);
Resize += FormResized;
base.DoPreview(dataSource);
});
return;
}
InvokeOnControlThread(() =>
{
try

View File

@@ -77,5 +77,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode.Properties {
return ResourceManager.GetString("GcodeWithoutEmbeddedThumbnails", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for an error when Gpo has the utility disabled.
/// </summary>
internal static string GpoDisabledErrorText {
get {
return ResourceManager.GetString("GpoDisabledErrorText", resourceCulture);
}
}
}
}

View File

@@ -124,4 +124,8 @@
<data name="GcodeWithoutEmbeddedThumbnails" xml:space="preserve">
<value>This G-code does not contain any embedded thumbnails.</value>
</data>
<data name="GpoDisabledErrorText" xml:space="preserve">
<value>Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.</value>
<comment>GPO stands for the Windows Group Policy Object feature.</comment>
</data>
</root>

View File

@@ -158,6 +158,12 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
return;
}
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredGcodeThumbnailsEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility.
return;
}
using (var stream = new ReadonlyStream(this.Stream as IStream))
{
using (var reader = new StreamReader(stream))

View File

@@ -6,7 +6,7 @@
<AssemblyName>PowerToys.GcodeThumbnailProvider</AssemblyName>
<AssemblyTitle>PowerToys.GcodeThumbnailProvider</AssemblyTitle>
<AssemblyDescription>PowerToys GcodePreviewHandler</AssemblyDescription>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<EnableComHosting>true</EnableComHosting>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Description>PowerToys GcodePreviewHandler</Description>
@@ -18,7 +18,23 @@
<Import Project="..\..\..\Version.props" />
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -37,7 +37,19 @@
</Compile>
</ItemGroup>
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Markdig.Signed" Version="0.27.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
@@ -45,6 +57,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />

View File

@@ -130,6 +130,21 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown
/// <param name="dataSource">Path to the file.</param>
public override void DoPreview<T>(T dataSource)
{
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMarkdownPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBarDisplayed = true;
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
Resize += FormResized;
Controls.Add(_infoBar);
base.DoPreview(dataSource);
});
return;
}
CleanupWebView2UserDataFolder();
_infoBarDisplayed = false;

View File

@@ -77,5 +77,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown.Properties {
return ResourceManager.GetString("MarkdownNotPreviewedError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for an error when Gpo has the utility disabled.
/// </summary>
internal static string GpoDisabledErrorText {
get {
return ResourceManager.GetString("GpoDisabledErrorText", resourceCulture);
}
}
}
}

View File

@@ -125,4 +125,8 @@
<value>The markdown could not be preview due to an internal error.</value>
<comment>This text is displayed if markdown fails to preview</comment>
</data>
<data name="GpoDisabledErrorText" xml:space="preserve">
<value>Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.</value>
<comment>GPO stands for the Windows Group Policy Object feature.</comment>
</data>
</root>

View File

@@ -26,7 +26,19 @@
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
@@ -41,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />

View File

@@ -37,6 +37,16 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
new XmlFormatter(),
}.AsReadOnly();
/// <summary>
/// Text box to display the information about blocked elements from Svg.
/// </summary>
private RichTextBox _textBox;
/// <summary>
/// Represent if an text box info bar is added for showing message.
/// </summary>
private bool _infoBarAdded;
/// <summary>
/// Saves if the user already navigated to the index page
/// </summary>
@@ -94,6 +104,20 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
Logger.LogTrace();
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMonacoPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resources.GpoDisabledErrorText);
Resize += FormResized;
base.DoPreview(dataSource);
});
return;
}
base.DoPreview(dataSource);
// Sets background color
@@ -421,5 +445,47 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
await Launcher.LaunchUriAsync(new Uri("https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section"));
Logger.LogTrace();
}
/// <summary>
/// Occurs when RichtextBox is resized.
/// </summary>
/// <param name="sender">Reference to resized control.</param>
/// <param name="e">Provides data for the ContentsResized event.</param>
private void RTBContentsResized(object sender, ContentsResizedEventArgs e)
{
var richTextBox = sender as RichTextBox;
richTextBox.Height = e.NewRectangle.Height + 5;
}
/// <summary>
/// Occurs when form is resized.
/// </summary>
/// <param name="sender">Reference to resized control.</param>
/// <param name="e">Provides data for the resize event.</param>
private void FormResized(object sender, EventArgs e)
{
if (_infoBarAdded)
{
_textBox.Width = Width;
}
}
/// <summary>
/// Adds a Text Box in Controls for showing information about blocked elements.
/// </summary>
/// <param name="message">Message to be displayed in textbox.</param>
private void AddTextBoxControl(string message)
{
_textBox = new RichTextBox();
_textBox.Text = message;
_textBox.BackColor = Color.LightYellow;
_textBox.Multiline = true;
_textBox.Dock = DockStyle.Top;
_textBox.ReadOnly = true;
_textBox.ContentsResized += RTBContentsResized;
_textBox.ScrollBars = RichTextBoxScrollBars.None;
_textBox.BorderStyle = BorderStyle.None;
Controls.Add(_textBox);
}
}
}

View File

@@ -106,5 +106,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco.Properties {
return ResourceManager.GetString("WebView2_Not_Installed_Message", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for an error when Gpo has the utility disabled.
/// </summary>
internal static string GpoDisabledErrorText {
get {
return ResourceManager.GetString("GpoDisabledErrorText", resourceCulture);
}
}
}
}

View File

@@ -136,4 +136,8 @@ Max file size: %1KB</value>
<data name="Download_WebView2" xml:space="preserve">
<value>Download WebView2 to display this file.</value>
</data>
<data name="GpoDisabledErrorText" xml:space="preserve">
<value>Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.</value>
<comment>GPO stands for the Windows Group Policy Object feature.</comment>
</data>
</root>

View File

@@ -31,11 +31,24 @@
</Compile>
</ItemGroup>
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -52,6 +52,19 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
/// <param name="dataSource">Stream reference to access source file.</param>
public override void DoPreview<T>(T dataSource)
{
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredPdfPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBar = GetTextBoxControl(Resources.GpoDisabledErrorText);
Controls.Add(_infoBar);
base.DoPreview(dataSource);
});
return;
}
this.SuspendLayout();
try

View File

@@ -100,5 +100,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf.Properties
return ResourceManager.GetString("PdfMorePagesMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for an error when Gpo has the utility disabled.
/// </summary>
internal static string GpoDisabledErrorText {
get {
return ResourceManager.GetString("GpoDisabledErrorText", resourceCulture);
}
}
}
}

View File

@@ -129,4 +129,8 @@
<value>Can't preview file. This PDF is password protected.</value>
<comment>This text is displayed if PDF is password protected.</comment>
</data>
<data name="GpoDisabledErrorText" xml:space="preserve">
<value>Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.</value>
<comment>GPO stands for the Windows Group Policy Object feature.</comment>
</data>
</root>

View File

@@ -49,6 +49,12 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Pdf
return;
}
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredPdfThumbnailsEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility.
return;
}
using var dataStream = new ReadonlyStream(this.Stream as IStream);
using var memStream = new MemoryStream();

View File

@@ -17,7 +17,23 @@
</PropertyGroup>
<Import Project="..\..\..\Version.props" />
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -123,6 +123,12 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
return;
}
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredStlThumbnailsEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility.
return;
}
using (var stream = new ReadonlyStream(this.Stream as IStream))
{
using (var memStream = new MemoryStream())

View File

@@ -6,7 +6,7 @@
<AssemblyName>PowerToys.StlThumbnailProvider</AssemblyName>
<AssemblyTitle>PowerToys.StlThumbnailProvider</AssemblyTitle>
<AssemblyDescription>PowerToys StlPreviewHandler</AssemblyDescription>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<EnableComHosting>true</EnableComHosting>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Description>PowerToys StlPreviewHandler</Description>
@@ -18,12 +18,25 @@
</PropertyGroup>
<Import Project="..\..\..\Version.props" />
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="HelixToolkit" Version="2.20.2" />
<PackageReference Include="HelixToolkit.Core.Wpf" Version="2.20.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />

View File

@@ -77,5 +77,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg.Properties {
return ResourceManager.GetString("SvgNotPreviewedError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string for an error when Gpo has the utility disabled.
/// </summary>
internal static string GpoDisabledErrorText {
get {
return ResourceManager.GetString("GpoDisabledErrorText", resourceCulture);
}
}
}
}

View File

@@ -123,4 +123,8 @@
<data name="SvgNotPreviewedError" xml:space="preserve">
<value>The Svg could not be preview due to an internal error in Svg Preview Handler.</value>
</data>
<data name="GpoDisabledErrorText" xml:space="preserve">
<value>Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.</value>
<comment>GPO stands for the Windows Group Policy Object feature.</comment>
</data>
</root>

View File

@@ -11,6 +11,7 @@ using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
using Common;
using Common.Utilities;
using Microsoft.PowerToys.PreviewHandler.Svg.Properties;
using Microsoft.PowerToys.PreviewHandler.Svg.Telemetry.Events;
using Microsoft.PowerToys.Telemetry;
using Microsoft.Web.WebView2.Core;
@@ -82,6 +83,20 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
/// <param name="dataSource">Stream reference to access source file.</param>
public override void DoPreview<T>(T dataSource)
{
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredSvgPreviewEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility. Show an error message instead.
InvokeOnControlThread(() =>
{
_infoBarAdded = true;
AddTextBoxControl(Properties.Resource.GpoDisabledErrorText);
Resize += FormResized;
base.DoPreview(dataSource);
});
return;
}
CleanupWebView2UserDataFolder();
string svgData = null;

View File

@@ -32,12 +32,25 @@
<Compile Update="SvgPreviewControl.cs" />
</ItemGroup>
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
</ItemGroup>

View File

@@ -272,6 +272,12 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Svg
return;
}
if (global::PowerToys.GPOWrapper.GPOWrapper.GetConfiguredSvgThumbnailsEnabledValue() == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
// GPO is disabling this utility.
return;
}
string svgData = null;
using (var stream = new ReadonlyStream(this.Stream as IStream))
{

View File

@@ -20,10 +20,24 @@
<Import Project="..\..\..\Version.props" />
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
<PropertyGroup>
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>
<PropertyGroup>
<!-- Disable missing comment warning. WinRT/C++ libraries added won't have comments on thier reflections. -->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
<ProjectReference Include="..\Common\PreviewHandlerCommon.csproj" />
</ItemGroup>

View File

@@ -23,6 +23,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

View File

@@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />

View File

@@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Markdig.Signed" Version="0.27.0" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

View File

@@ -29,6 +29,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />

View File

@@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />

View File

@@ -24,6 +24,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />

View File

@@ -28,6 +28,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<ProjectReference Include="..\common\PreviewHandlerCommon.csproj" />
<ProjectReference Include="..\SvgPreviewHandler\SvgPreviewHandler.csproj" />
</ItemGroup>

View File

@@ -20,6 +20,7 @@
<Import Project="..\..\..\Version.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />

View File

@@ -28,38 +28,47 @@ PowerPreviewModule::PowerPreviewModule() :
const bool installPerUser = true;
m_fileExplorerModules.push_back({ .settingName = L"svg-previewer-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PREVPANE_SVG_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredSvgPreviewEnabledValue,
.registryChanges = getSvgPreviewHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"md-previewer-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PREVPANE_MD_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredMarkdownPreviewEnabledValue,
.registryChanges = getMdPreviewHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"monaco-previewer-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PREVPANE_MONACO_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredMonacoPreviewEnabledValue,
.registryChanges = getMonacoPreviewHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"pdf-previewer-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PREVPANE_PDF_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredPdfPreviewEnabledValue,
.registryChanges = getPdfPreviewHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"gcode-previewer-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PREVPANE_GCODE_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredGcodePreviewEnabledValue,
.registryChanges = getGcodePreviewHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"svg-thumbnail-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_SVG_THUMBNAIL_PROVIDER_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredSvgThumbnailsEnabledValue,
.registryChanges = getSvgThumbnailHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"pdf-thumbnail-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_PDF_THUMBNAIL_PROVIDER_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredPdfThumbnailsEnabledValue,
.registryChanges = getPdfThumbnailHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"gcode-thumbnail-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_GCODE_THUMBNAIL_PROVIDER_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredGcodeThumbnailsEnabledValue,
.registryChanges = getGcodeThumbnailHandlerChangeSet(installationDir, installPerUser) });
m_fileExplorerModules.push_back({ .settingName = L"stl-thumbnail-toggle-setting",
.settingDescription = GET_RESOURCE_STRING(IDS_STL_THUMBNAIL_PROVIDER_SETTINGS_DESCRIPTION),
.checkModuleGPOEnabledRuleFunction = powertoys_gpo::getConfiguredStlThumbnailsEnabledValue,
.registryChanges = getStlThumbnailHandlerChangeSet(installationDir, installPerUser) });
try
@@ -202,15 +211,43 @@ void PowerPreviewModule::apply_settings(const PowerToysSettings::PowerToyValues&
for (auto& fileExplorerModule : m_fileExplorerModules)
{
const auto toggle = settings.get_bool_value(fileExplorerModule.settingName);
const auto gpo_rule = fileExplorerModule.checkModuleGPOEnabledRuleFunction();
const auto gpo_is_configured = gpo_rule == powertoys_gpo::gpo_rule_configured_enabled || gpo_rule == powertoys_gpo::gpo_rule_configured_disabled;
if (gpo_rule == powertoys_gpo::gpo_rule_configured_unavailable)
{
Logger::warn(L"Couldn't read the gpo rule for Power Preview module {}", fileExplorerModule.settingName);
}
if (gpo_rule == powertoys_gpo::gpo_rule_configured_wrong_value)
{
Logger::warn(L"gpo rule for Power Preview module {} is set to an unknown value", fileExplorerModule.settingName);
}
// Skip if no need to update
if (!toggle.has_value() || *toggle == fileExplorerModule.registryChanges.isApplied())
if (!toggle.has_value() && !gpo_is_configured)
{
continue;
}
bool module_new_state = false;
if (toggle.has_value())
{
module_new_state = *toggle;
}
if (gpo_is_configured)
{
// gpo rule overrides settings state
module_new_state = gpo_rule == powertoys_gpo::gpo_rule_configured_enabled;
}
// Skip if no need to update
if (module_new_state == fileExplorerModule.registryChanges.isApplied())
{
continue;
}
// (Un)Apply registry changes depending on the new setting value
const bool updated = *toggle ? fileExplorerModule.registryChanges.apply() : fileExplorerModule.registryChanges.unApply();
const bool updated = module_new_state ? fileExplorerModule.registryChanges.apply() : fileExplorerModule.registryChanges.unApply();
if (updated)
{

View File

@@ -7,11 +7,13 @@
#include <common/utils/modulesRegistry.h>
#include <common/SettingsAPI/settings_objects.h>
#include <common/utils/gpo.h>
struct FileExplorerModule
{
std::wstring settingName;
std::wstring settingDescription;
powertoys_gpo::gpo_rule_configured_t (*checkModuleGPOEnabledRuleFunction)();
registry::ChangeSet registryChanges;
};