From cc586a03578808a416a555faef3860e293d01bae Mon Sep 17 00:00:00 2001 From: PesBandi <127593627+PesBandi@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:18:44 +0200 Subject: [PATCH 1/7] [QuickAccent]Add Middle Eastern Romanization (#31905) * [Quick Accent] Add support for Middle Eastern Romanization * Update ToUpper() (PowerAccent.cs) * Add right single quotation mark * rework ToUpper() * rework ToUpper() * Update ToUpper() * Internal strings more about Romanization --- .../poweraccent/PowerAccent.Core/Languages.cs | 34 +++++++++++++++++++ .../PowerAccent.Core/PowerAccent.cs | 10 +++++- .../SettingsXAML/Views/PowerAccentPage.xaml | 1 + .../Settings.UI/Strings/en-us/Resources.resw | 3 ++ .../ViewModels/PowerAccentViewModel.cs | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs index a689bf078d..d79800dbad 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs @@ -42,6 +42,7 @@ namespace PowerAccent.Core PL, PT, RO, + ROM, SK, SL, SP, @@ -88,6 +89,7 @@ namespace PowerAccent.Core Language.PL => GetDefaultLetterKeyPL(letter), // Polish Language.PT => GetDefaultLetterKeyPT(letter), // Portuguese Language.RO => GetDefaultLetterKeyRO(letter), // Romanian + Language.ROM => GetDefaultLetterKeyROM(letter), // Middle Eastern Romanization Language.SK => GetDefaultLetterKeySK(letter), // Slovak Language.SL => GetDefaultLetterKeySL(letter), // Slovenian Language.SP => GetDefaultLetterKeySP(letter), // Spain @@ -129,6 +131,7 @@ namespace PowerAccent.Core .Union(GetDefaultLetterKeyIT(letter)) .Union(GetDefaultLetterKeyKU(letter)) .Union(GetDefaultLetterKeyLT(letter)) + .Union(GetDefaultLetterKeyROM(letter)) .Union(GetDefaultLetterKeyMK(letter)) .Union(GetDefaultLetterKeyMI(letter)) .Union(GetDefaultLetterKeyNL(letter)) @@ -494,6 +497,37 @@ namespace PowerAccent.Core }; } + // Middle Eastern Romanization + private static string[] GetDefaultLetterKeyROM(LetterKey letter) + { + return letter switch + { + LetterKey.VK_A => new[] { "á", "â", "ă", "ā" }, + LetterKey.VK_B => new[] { "ḇ" }, + LetterKey.VK_C => new[] { "č", "ç" }, + LetterKey.VK_D => new[] { "ḑ", "ḍ", "ḏ", "ḏ\u0323" }, + LetterKey.VK_E => new[] { "ê", "ě", "ĕ", "ē", "é", "ə" }, + LetterKey.VK_G => new[] { "ġ", "ǧ", "ğ", "ḡ", "g\u0303", "g\u0331" }, + LetterKey.VK_H => new[] { "ḧ", "ḩ", "ḥ", "ḫ", "h\u0331" }, + LetterKey.VK_I => new[] { "í", "ı", "î", "ī", "ı\u0307\u0304" }, + LetterKey.VK_J => new[] { "ǰ", "j\u0331" }, + LetterKey.VK_K => new[] { "ḳ", "ḵ" }, + LetterKey.VK_L => new[] { "ł" }, + LetterKey.VK_N => new[] { "ⁿ", "ñ" }, + LetterKey.VK_O => new[] { "ó", "ô", "ö", "ŏ", "ō", "ȫ" }, + LetterKey.VK_P => new[] { "p\u0304" }, + LetterKey.VK_R => new[] { "ṙ", "ṛ" }, + LetterKey.VK_S => new[] { "ś", "š", "ş", "ṣ", "s\u0331", "ṣ\u0304" }, + LetterKey.VK_T => new[] { "ẗ", "ţ", "ṭ", "ṯ" }, + LetterKey.VK_U => new[] { "ú", "û", "ü", "ū", "ǖ" }, + LetterKey.VK_V => new[] { "v\u0307", "ṿ", "ᵛ" }, + LetterKey.VK_Y => new[] { "̀y" }, + LetterKey.VK_Z => new[] { "ż", "ž", "z\u0304", "z\u0327", "ẓ", "z\u0324", "ẕ" }, + LetterKey.VK_PERIOD => new[] { "’", "ʾ", "ʿ", "′", "…" }, + _ => Array.Empty(), + }; + } + // Slovak private static string[] GetDefaultLetterKeySK(LetterKey letter) { diff --git a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs index a9638fa0fc..a1802ba428 100644 --- a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs +++ b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs @@ -348,7 +348,15 @@ public class PowerAccent : IDisposable string[] result = new string[array.Length]; for (int i = 0; i < array.Length; i++) { - result[i] = array[i].Contains('ß') ? "ẞ" : array[i].ToUpper(System.Globalization.CultureInfo.InvariantCulture); + switch (array[i]) + { + case "ß": result[i] = "ẞ"; break; + case "ǰ": result[i] = "J\u030c"; break; + case "ı\u0307\u0304": result[i] = "İ\u0304"; break; + case "ı": result[i] = "İ"; break; + case "ᵛ": result[i] = "ⱽ"; break; + default: result[i] = array[i].ToUpper(System.Globalization.CultureInfo.InvariantCulture); break; + } } return result; diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml index 1a28b8c83e..0c75c60c92 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml @@ -83,6 +83,7 @@ + diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index 1a0817304d..a409727295 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -3584,6 +3584,9 @@ Activate by holding the key for the character you want to add an accent to, then Maori + + Middle Eastern Romanization + Dutch diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs index a69ba0b976..99ef36afb9 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs @@ -54,6 +54,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels "PL", "PT", "RO", + "ROM", "SK", "SL", "SP", From c890eb95cac1640bafb034f8c29cfd2859fdc2fa Mon Sep 17 00:00:00 2001 From: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:04:07 +0200 Subject: [PATCH 2/7] [FileLocksmith]Fix triggering FileLocksmith unexpectedly through verbs (#34905) --- .../FileLocksmithExt/ExplorerCommand.cpp | 81 ++++++++++--------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp index e0eee3d781..bc4ab945ca 100644 --- a/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp +++ b/src/modules/FileLocksmith/FileLocksmithExt/ExplorerCommand.cpp @@ -166,51 +166,58 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici) { - Trace::Invoked(); - ipc::Writer writer; + HRESULT hr = E_FAIL; - if (HRESULT result = writer.start(); FAILED(result)) + if (FileLocksmithSettingsInstance().GetEnabled() && + pici && (IS_INTRESOURCE(pici->lpVerb)) && + (LOWORD(pici->lpVerb) == 0)) { - Trace::InvokedRet(result); - return result; - } + Trace::Invoked(); + ipc::Writer writer; - if (HRESULT result = LaunchUI(pici, &writer); FAILED(result)) - { - Trace::InvokedRet(result); - return result; - } - - IShellItemArray* shell_item_array; - HRESULT result = SHCreateShellItemArrayFromDataObject(m_data_obj, __uuidof(IShellItemArray), reinterpret_cast(&shell_item_array)); - if (SUCCEEDED(result)) - { - DWORD num_items; - shell_item_array->GetCount(&num_items); - for (DWORD i = 0; i < num_items; i++) + if (HRESULT result = writer.start(); FAILED(result)) { - IShellItem* item; - result = shell_item_array->GetItemAt(i, &item); - if (SUCCEEDED(result)) - { - LPWSTR file_path; - result = item->GetDisplayName(SIGDN_FILESYSPATH, &file_path); - if (SUCCEEDED(result)) - { - // TODO Aggregate items and send to UI - writer.add_path(file_path); - CoTaskMemFree(file_path); - } - - item->Release(); - } + Trace::InvokedRet(result); + return result; } - shell_item_array->Release(); + if (HRESULT result = LaunchUI(pici, &writer); FAILED(result)) + { + Trace::InvokedRet(result); + return result; + } + + IShellItemArray* shell_item_array; + hr = SHCreateShellItemArrayFromDataObject(m_data_obj, __uuidof(IShellItemArray), reinterpret_cast(&shell_item_array)); + if (SUCCEEDED(hr)) + { + DWORD num_items; + shell_item_array->GetCount(&num_items); + for (DWORD i = 0; i < num_items; i++) + { + IShellItem* item; + hr = shell_item_array->GetItemAt(i, &item); + if (SUCCEEDED(hr)) + { + LPWSTR file_path; + hr = item->GetDisplayName(SIGDN_FILESYSPATH, &file_path); + if (SUCCEEDED(hr)) + { + // TODO Aggregate items and send to UI + writer.add_path(file_path); + CoTaskMemFree(file_path); + } + + item->Release(); + } + } + + shell_item_array->Release(); + } } - Trace::InvokedRet(S_OK); - return S_OK; + Trace::InvokedRet(hr); + return hr; } IFACEMETHODIMP ExplorerCommand::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved, CHAR* pszName, UINT cchMax) From b927b340ec83923769ae57d2a24e02980e5a815e Mon Sep 17 00:00:00 2001 From: "R. David Dunphy" Date: Tue, 24 Sep 2024 16:07:06 +0100 Subject: [PATCH 3/7] [QuickAccent]Add degree sign, integral, and vertical ellipsis to all languages (#34747) --- src/modules/poweraccent/PowerAccent.Core/Languages.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs index d79800dbad..d72a7bf486 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs @@ -161,7 +161,7 @@ namespace PowerAccent.Core { return letter switch { - LetterKey.VK_0 => new[] { "₀", "⁰", "↉" }, + LetterKey.VK_0 => new[] { "₀", "⁰", "°", "↉" }, LetterKey.VK_1 => new[] { "₁", "¹", "½", "⅓", "¼", "⅕", "⅙", "⅐", "⅛", "⅑", "⅒" }, LetterKey.VK_2 => new[] { "₂", "²", "⅔", "⅖" }, LetterKey.VK_3 => new[] { "₃", "³", "¾", "⅗", "⅜" }, @@ -188,7 +188,7 @@ namespace PowerAccent.Core LetterKey.VK_P => new[] { "ṗ", "℗", "∏", "¶" }, LetterKey.VK_Q => new[] { "ℚ" }, LetterKey.VK_R => new[] { "ṙ", "®", "ℝ" }, - LetterKey.VK_S => new[] { "ṡ", "§", "∑" }, + LetterKey.VK_S => new[] { "ṡ", "§", "∑", "∫" }, LetterKey.VK_T => new[] { "ţ", "ṫ", "ŧ", "™" }, LetterKey.VK_U => new[] { "ŭ" }, LetterKey.VK_V => new[] { "V̇" }, @@ -197,7 +197,7 @@ namespace PowerAccent.Core LetterKey.VK_Y => new[] { "ẏ", "ꝡ" }, LetterKey.VK_Z => new[] { "ʒ", "ǯ", "ℤ" }, LetterKey.VK_COMMA => new[] { "∙", "₋", "⁻", "–", "√" }, // – is in VK_MINUS for other languages, but not VK_COMMA, so we add it here. - LetterKey.VK_PERIOD => new[] { "…", "\u0300", "\u0301", "\u0302", "\u0303", "\u0304", "\u0308", "\u030B", "\u030C" }, + LetterKey.VK_PERIOD => new[] { "…", "⁝", "\u0300", "\u0301", "\u0302", "\u0303", "\u0304", "\u0308", "\u030B", "\u030C" }, LetterKey.VK_MINUS => new[] { "~", "‐", "‑", "‒", "—", "―", "⁓", "−", "⸺", "⸻", "∓" }, LetterKey.VK_SLASH_ => new[] { "÷", "√" }, LetterKey.VK_DIVIDE_ => new[] { "÷", "√" }, From 734b0f8a54a8714c1478c62046200e6920da6b01 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:33:01 +0200 Subject: [PATCH 4/7] [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 --- src/common/GPOWrapper/GPOWrapper.cpp | 4 +++ src/common/GPOWrapper/GPOWrapper.h | 1 + src/common/GPOWrapper/GPOWrapper.idl | 1 + src/common/utils/gpo.h | 6 ++++ src/gpo/assets/PowerToys.admx | 13 +++++++ src/gpo/assets/en-US/PowerToys.adml | 10 ++++++ .../NewShellExtensionContextMenu/settings.cpp | 10 ++++++ .../SettingsXAML/Views/NewPlusPage.xaml | 12 ++++++- .../ViewModels/NewPlusViewModel.cs | 34 ++++++++++++++++--- .../BugReportTool/ReportGPOValues.cpp | 1 + 10 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/common/GPOWrapper/GPOWrapper.cpp b/src/common/GPOWrapper/GPOWrapper.cpp index c3dd26cf8f..817db8c4de 100644 --- a/src/common/GPOWrapper/GPOWrapper.cpp +++ b/src/common/GPOWrapper/GPOWrapper.cpp @@ -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(powertoys_gpo::getConfiguredNewPlusHideTemplateFilenameExtensionValue()); + } } diff --git a/src/common/GPOWrapper/GPOWrapper.h b/src/common/GPOWrapper/GPOWrapper.h index e4b12853d8..e1fcb5426b 100644 --- a/src/common/GPOWrapper/GPOWrapper.h +++ b/src/common/GPOWrapper/GPOWrapper.h @@ -60,6 +60,7 @@ namespace winrt::PowerToys::GPOWrapper::implementation static GpoRuleConfigured GetConfiguredMwbValidateRemoteIpValue(); static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue(); static winrt::hstring GPOWrapper::GetConfiguredMwbPolicyDefinedIpMappingRules(); + static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue(); }; } diff --git a/src/common/GPOWrapper/GPOWrapper.idl b/src/common/GPOWrapper/GPOWrapper.idl index 7d00378389..1d375f1975 100644 --- a/src/common/GPOWrapper/GPOWrapper.idl +++ b/src/common/GPOWrapper/GPOWrapper.idl @@ -64,6 +64,7 @@ namespace PowerToys static GpoRuleConfigured GetConfiguredMwbValidateRemoteIpValue(); static GpoRuleConfigured GetConfiguredMwbDisableUserDefinedIpMappingRulesValue(); static String GetConfiguredMwbPolicyDefinedIpMappingRules(); + static GpoRuleConfigured GetConfiguredNewPlusHideTemplateFilenameExtensionValue(); } } } diff --git a/src/common/utils/gpo.h b/src/common/utils/gpo.h index 0b59690f8d..0f721d93d5 100644 --- a/src/common/utils/gpo.h +++ b/src/common/utils/gpo.h @@ -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 } diff --git a/src/gpo/assets/PowerToys.admx b/src/gpo/assets/PowerToys.admx index 9386fa6e31..0459a6f601 100644 --- a/src/gpo/assets/PowerToys.admx +++ b/src/gpo/assets/PowerToys.admx @@ -41,6 +41,9 @@ + + + @@ -611,5 +614,15 @@ + + + + + + + + + + diff --git a/src/gpo/assets/en-US/PowerToys.adml b/src/gpo/assets/en-US/PowerToys.adml index 4fcc123114..588ccf3d1d 100644 --- a/src/gpo/assets/en-US/PowerToys.adml +++ b/src/gpo/assets/en-US/PowerToys.adml @@ -12,6 +12,7 @@ Advanced Paste Mouse Without Borders General settings + New+ PowerToys version 0.64.0 or later PowerToys version 0.68.0 or later @@ -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. + + 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. Configure global utility enabled state @@ -248,6 +257,7 @@ If you disable or don't configure this policy, no predefined rules are applied. Validate remote machine IP Address Disable user defined IP Address mapping rules Predefined IP Address mapping rules + Hide template filename extension diff --git a/src/modules/NewPlus/NewShellExtensionContextMenu/settings.cpp b/src/modules/NewPlus/NewShellExtensionContextMenu/settings.cpp index a7ce32998d..f1322caf1f 100644 --- a/src/modules/NewPlus/NewShellExtensionContextMenu/settings.cpp +++ b/src/modules/NewPlus/NewShellExtensionContextMenu/settings.cpp @@ -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; } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/NewPlusPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/NewPlusPage.xaml index abde03627b..f232227b05 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/NewPlusPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/NewPlusPage.xaml @@ -68,9 +68,19 @@ - + + + + diff --git a/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs index b75af1dbde..70d2657e37 100644 --- a/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs @@ -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(); diff --git a/tools/BugReportTool/BugReportTool/ReportGPOValues.cpp b/tools/BugReportTool/BugReportTool/ReportGPOValues.cpp index 8e6e764c1a..cab28b4e35 100644 --- a/tools/BugReportTool/BugReportTool/ReportGPOValues.cpp +++ b/tools/BugReportTool/BugReportTool/ReportGPOValues.cpp @@ -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; } From 499dc9bb7a4727ef53a224530e4a096d1e5a7af3 Mon Sep 17 00:00:00 2001 From: Ani <115020168+drawbyperpetual@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:16:20 +0200 Subject: [PATCH 5/7] [AdvancedPaste]Check "Paste with AI" enabled state for enabling custom actions (#35026) * [AdvancedPaste] Check OpenAI enabled state for custom actions * Add some more explanations to the expected exception * Add description saying that it requires Paste with AI to be enabled * Check openAI enabled only if we have custom actions --------- Co-authored-by: Jaime Bernardo --- .../ViewModels/OptionsViewModel.cs | 3 +- .../AdvancedPasteModuleInterface/dllmain.cpp | 49 ++++++++++++++++--- .../SettingsXAML/Views/AdvancedPaste.xaml | 6 ++- .../Settings.UI/Strings/en-us/Resources.resw | 5 +- .../ViewModels/AdvancedPasteViewModel.cs | 2 + 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/modules/AdvancedPaste/AdvancedPaste/ViewModels/OptionsViewModel.cs b/src/modules/AdvancedPaste/AdvancedPaste/ViewModels/OptionsViewModel.cs index def4d89d11..141561543e 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/ViewModels/OptionsViewModel.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/ViewModels/OptionsViewModel.cs @@ -94,6 +94,7 @@ namespace AdvancedPaste.ViewModels ClipboardHistoryEnabled = IsClipboardHistoryEnabled(); ReadClipboard(); + UpdateAllowedByGPO(); _clipboardTimer = new() { Interval = TimeSpan.FromSeconds(1) }; _clipboardTimer.Tick += ClipboardTimer_Tick; _clipboardTimer.Start(); @@ -462,7 +463,7 @@ namespace AdvancedPaste.ViewModels { Logger.LogTrace(); - if (string.IsNullOrWhiteSpace(inputInstructions)) + if (string.IsNullOrWhiteSpace(inputInstructions) || !IsCustomAIEnabled) { return string.Empty; } diff --git a/src/modules/AdvancedPaste/AdvancedPasteModuleInterface/dllmain.cpp b/src/modules/AdvancedPaste/AdvancedPasteModuleInterface/dllmain.cpp index 261fa43932..eae8fc0b85 100644 --- a/src/modules/AdvancedPaste/AdvancedPasteModuleInterface/dllmain.cpp +++ b/src/modules/AdvancedPaste/AdvancedPasteModuleInterface/dllmain.cpp @@ -13,7 +13,9 @@ #include #include #include +#include +#include #include #include #include @@ -54,6 +56,9 @@ namespace const wchar_t JSON_KEY_PASTE_AS_JSON_HOTKEY[] = L"paste-as-json-hotkey"; const wchar_t JSON_KEY_SHOW_CUSTOM_PREVIEW[] = L"ShowCustomPreview"; const wchar_t JSON_KEY_VALUE[] = L"value"; + + const wchar_t OPENAI_VAULT_RESOURCE[] = L"https://platform.openai.com/api-keys"; + const wchar_t OPENAI_VAULT_USERNAME[] = L"PowerToys_AdvancedPaste_OpenAIKey"; } class AdvancedPaste : public PowertoyModuleIface @@ -133,6 +138,34 @@ private: return jsonObject; } + static bool open_ai_key_exists() + { + try + { + winrt::Windows::Security::Credentials::PasswordVault vault; + return vault.Retrieve(OPENAI_VAULT_RESOURCE, OPENAI_VAULT_USERNAME) != nullptr; + } + catch (const winrt::hresult_error& ex) + { + // Looks like the only way to access the PasswordVault is through the an API that throws an exception in case the resource doesn't exist. + // If the compiler breaks here when you're debugging, just continue. + // If you want to disable breaking here in a more permanent way, just add a condition in Visual Studio's Exception Settings to not break on win::hresult_error, but that might make you not hit other exceptions you might want to catch. + if (ex.code() == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) + { + return false; // Credential doesn't exist. + } + Logger::error("Unexpected error while retrieving OpenAI key from vault: {}", winrt::to_string(ex.message())); + return false; + } + } + + bool is_open_ai_enabled() + { + return gpo_policy_enabled_configuration() != powertoys_gpo::gpo_rule_configured_disabled && + powertoys_gpo::getAllowedAdvancedPasteOnlineAIModelsValue() != powertoys_gpo::gpo_rule_configured_disabled && + open_ai_key_exists(); + } + bool migrate_data_and_remove_data_file(Hotkey& old_paste_as_plain_hotkey) { const wchar_t OLD_JSON_KEY_ACTIVATION_SHORTCUT[] = L"ActivationShortcut"; @@ -216,15 +249,17 @@ private: if (propertiesObject.HasKey(JSON_KEY_CUSTOM_ACTIONS)) { const auto customActions = propertiesObject.GetNamedObject(JSON_KEY_CUSTOM_ACTIONS).GetNamedArray(JSON_KEY_VALUE); - - for (const auto& customAction : customActions) + if (customActions.Size() > 0 && is_open_ai_enabled()) { - const auto object = customAction.GetObjectW(); - - if (object.GetNamedBoolean(JSON_KEY_IS_SHOWN, false)) + for (const auto& customAction : customActions) { - m_custom_action_hotkeys.push_back(parse_single_hotkey(object.GetNamedObject(JSON_KEY_SHORTCUT))); - m_custom_action_ids.push_back(static_cast(object.GetNamedNumber(JSON_KEY_ID))); + const auto object = customAction.GetObjectW(); + + if (object.GetNamedBoolean(JSON_KEY_IS_SHOWN, false)) + { + m_custom_action_hotkeys.push_back(parse_single_hotkey(object.GetNamedObject(JSON_KEY_SHORTCUT))); + m_custom_action_ids.push_back(static_cast(object.GetNamedNumber(JSON_KEY_ID))); + } } } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPaste.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPaste.xaml index ed7a634388..1598beecc8 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPaste.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/AdvancedPaste.xaml @@ -102,7 +102,10 @@ - +