[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

@@ -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>