[New+, Enterprise]Policy for showing filename extension (#35000)

* add gpo: admx, gpo utils

* todo note

* BugReport tool

* implement policy in utility

* settings ui

* remove todo comment

* code fixes

* code fixes 2

* spell fix
This commit is contained in:
Heiko
2024-09-24 17:33:01 +02:00
committed by GitHub
parent b927b340ec
commit 734b0f8a54
10 changed files with 87 additions and 5 deletions

View File

@@ -220,4 +220,8 @@ namespace winrt::PowerToys::GPOWrapper::implementation
// Convert std::wstring to winrt::hstring
return to_hstring(rules.c_str());
}
GpoRuleConfigured GPOWrapper::GetConfiguredNewPlusHideTemplateFilenameExtensionValue()
{
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredNewPlusHideTemplateFilenameExtensionValue());
}
}

View File

@@ -60,6 +60,7 @@ namespace winrt::PowerToys::GPOWrapper::implementation
static GpoRuleConfigured GetConfiguredMwbValidateRemoteIpValue();
static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue();
static winrt::hstring GPOWrapper::GetConfiguredMwbPolicyDefinedIpMappingRules();
static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
};
}

View File

@@ -64,6 +64,7 @@ namespace PowerToys
static GpoRuleConfigured GetConfiguredMwbValidateRemoteIpValue();
static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue();
static String GetConfiguredMwbPolicyDefinedIpMappingRules();
static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
}
}
}

View File

@@ -82,6 +82,7 @@ namespace powertoys_gpo {
const std::wstring POLICY_MWB_VALIDATE_REMOTE_IP = L"MwbValidateRemoteIp";
const std::wstring POLICY_MWB_DISABLE_USER_DEFINED_IP_MAPPING_RULES = L"MwbDisableUserDefinedIpMappingRules";
const std::wstring POLICY_MWB_POLICY_DEFINED_IP_MAPPING_RULES = L"MwbPolicyDefinedIpMappingRules";
const std::wstring POLICY_NEW_PLUS_HIDE_TEMPLATE_FILENAME_EXTENSION = L"NewPlusHideTemplateFilenameExtension";
// Methods used for reading the registry
#pragma region ReadRegistryMethods
@@ -585,5 +586,10 @@ namespace powertoys_gpo {
return std::wstring ();
}
}
inline gpo_rule_configured_t getConfiguredNewPlusHideTemplateFilenameExtensionValue()
{
return getConfiguredValue(POLICY_NEW_PLUS_HIDE_TEMPLATE_FILENAME_EXTENSION);
}
#pragma endregion IndividualModuleSettingPolicies
}

View File

@@ -41,6 +41,9 @@
<category name="GeneralSettings" displayName="$(string.GeneralSettings)">
<parentCategory ref="PowerToys" />
</category>
<category name="NewPlus" displayName="$(string.NewPlus)">
<parentCategory ref="PowerToys" />
</category>
</categories>
<policies>
@@ -611,5 +614,15 @@
<multiText id="MwbPolicyDefinedIpMappingsList" valueName="MwbPolicyDefinedIpMappingRules" maxLength="65" required="true"/>
</elements>
</policy>
<policy name="NewPlusHideTemplateFilenameExtension" class="Both" displayName="$(string.NewPlusHideTemplateFilenameExtension)" explainText="$(string.NewPlusHideTemplateFilenameExtensionDescription)" key="Software\Policies\PowerToys" valueName="NewPlusHideTemplateFilenameExtension">
<parentCategory ref="NewPlus" />
<supportedOn ref="SUPPORTED_POWERTOYS_0_85_0" />
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
</policies>
</policyDefinitions>

View File

@@ -12,6 +12,7 @@
<string id="AdvancedPaste">Advanced Paste</string>
<string id="MouseWithoutBorders">Mouse Without Borders</string>
<string id="GeneralSettings">General settings</string>
<string id="NewPlus">New+</string>
<string id="SUPPORTED_POWERTOYS_0_64_0">PowerToys version 0.64.0 or later</string>
<string id="SUPPORTED_POWERTOYS_0_68_0">PowerToys version 0.68.0 or later</string>
@@ -189,6 +190,14 @@ If you enable this policy, you can define IP Address mapping rules that the user
Please enter one mapping per line in the format: "hostname IP"
If you disable or don't configure this policy, no predefined rules are applied.
</string>
<string id="NewPlusHideTemplateFilenameExtensionDescription">This policy configures if the template filenames are shown with extension or not.
If you enable this policy, the setting is enabled and the extension is hidden.
If you disable this policy, the setting is disabled and the extension is shown.
If you don't configure this policy, the user takes control over the setting and can enable or disable it.
</string>
<string id="ConfigureAllUtilityGlobalEnabledState">Configure global utility enabled state</string>
@@ -248,6 +257,7 @@ If you disable or don't configure this policy, no predefined rules are applied.
<string id="MwbValidateRemoteIp">Validate remote machine IP Address</string>
<string id="MwbDisableUserDefinedIpMappingRules">Disable user defined IP Address mapping rules</string>
<string id="MwbPolicyDefinedIpMappingRules">Predefined IP Address mapping rules</string>
<string id="NewPlusHideTemplateFilenameExtension">Hide template filename extension</string>
</stringTable>
<presentationTable>

View File

@@ -175,6 +175,16 @@ bool NewSettings::GetEnabled()
bool NewSettings::GetHideFileExtension() const
{
auto gpoSetting = powertoys_gpo::getConfiguredNewPlusHideTemplateFilenameExtensionValue();
if (gpoSetting == powertoys_gpo::gpo_rule_configured_enabled)
{
return true;
}
if (gpoSetting == powertoys_gpo::gpo_rule_configured_disabled)
{
return false;
}
return new_settings.hide_file_extension;
}

View File

@@ -68,9 +68,19 @@
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="NewPlus_Display_Options" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsCard x:Uid="NewPlus_Hide_File_Extension_Toggle">
<tkcontrols:SettingsCard x:Uid="NewPlus_Hide_File_Extension_Toggle" IsEnabled="{x:Bind ViewModel.IsHideFileExtSettingsCardEnabled, Mode=OneWay}">
<ToggleSwitch x:Uid="HideFileExtensionToggle" IsOn="{x:Bind ViewModel.HideFileExtension, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<InfoBar
x:Uid="GPO_SettingIsManaged"
IsClosable="False"
IsOpen="{x:Bind ViewModel.IsHideFileExtSettingGPOConfigured, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.IsHideFileExtSettingGPOConfigured, Mode=OneWay}"
Severity="Informational">
<!-- InfoBar.IconSource>
<FontIconSource FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE72E;" />
</InfoBar.IconSource-->
</InfoBar>
<tkcontrols:SettingsCard x:Uid="NewPlus_Hide_Starting_Digits_Toggle">
<ToggleSwitch x:Uid="HideStartingDigitsToggle" IsOn="{x:Bind ViewModel.HideStartingDigits, Mode=TwoWay}" />
<tkcontrols:SettingsCard.Description>

View File

@@ -51,6 +51,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_hideStartingDigits = Settings.HideStartingDigits;
_templateLocation = Settings.TemplateLocation;
InitializeEnabledValue();
InitializeGpoValues();
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
@@ -71,6 +72,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
private void InitializeGpoValues()
{
// Policy for hide file extension setting
_hideFileExtensionGpoRuleConfiguration = GPOWrapper.GetConfiguredNewPlusHideTemplateFilenameExtensionValue();
_hideFileExtensionIsGPOConfigured = _hideFileExtensionGpoRuleConfiguration == GpoRuleConfigured.Disabled || _hideFileExtensionGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
public bool IsEnabled
{
get => _isNewPlusEnabled;
@@ -82,6 +90,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
GeneralSettingsConfig.Enabled.NewPlus = value;
OnPropertyChanged(nameof(IsEnabled));
OnPropertyChanged(nameof(IsHideFileExtSettingsCardEnabled));
OnPropertyChanged(nameof(IsHideFileExtSettingGPOConfigured));
OutGoingGeneralSettings outgoingMessage = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoingMessage.ToString());
@@ -121,10 +131,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public bool HideFileExtension
{
get => _hideFileExtension;
get
{
if (_hideFileExtensionIsGPOConfigured)
{
return _hideFileExtensionGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
return _hideFileExtension;
}
set
{
if (_hideFileExtension != value)
if (_hideFileExtension != value && !_hideFileExtensionIsGPOConfigured)
{
_hideFileExtension = value;
Settings.HideFileExtension = value;
@@ -137,6 +156,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool IsHideFileExtSettingsCardEnabled => _isNewPlusEnabled && !_hideFileExtensionIsGPOConfigured;
public bool IsHideFileExtSettingGPOConfigured => _isNewPlusEnabled && _hideFileExtensionIsGPOConfigured;
public bool HideStartingDigits
{
get => _hideStartingDigits;
@@ -209,13 +232,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private bool _isNewPlusEnabled;
private string _templateLocation;
private bool _hideFileExtension;
private bool _hideStartingDigits;
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private GpoRuleConfigured _hideFileExtensionGpoRuleConfiguration;
private bool _hideFileExtensionIsGPOConfigured;
public void RefreshEnabledState()
{
InitializeEnabledValue();

View File

@@ -91,4 +91,5 @@ void ReportGPOValues(const std::filesystem::path& tmpDir)
report << "getConfiguredMwbDisableUserDefinedIpMappingRulesValue: " << gpo_rule_configured_to_string(powertoys_gpo::getConfiguredMwbDisableUserDefinedIpMappingRulesValue()) << std::endl;
report << "getConfiguredMwbPolicyDefinedIpMappingRules: " << gpo_string_to_string(powertoys_gpo::getConfiguredMwbPolicyDefinedIpMappingRules()) << std::endl;
report << "getConfiguredNewPlusEnabledValue: " << gpo_rule_configured_to_string(powertoys_gpo::getConfiguredNewPlusEnabledValue()) << std::endl;
report << "getConfiguredNewPlusHideTemplateFilenameExtensionValue: " << gpo_rule_configured_to_string(powertoys_gpo::getConfiguredNewPlusHideTemplateFilenameExtensionValue()) << std::endl;
}