From fb5ed133867eb681ce8e34d69466e5215a9b9ff1 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 8 Aug 2024 15:26:43 +0100 Subject: [PATCH] [Refactor]Port C++/CX to C++/WinRT (#34198) ## Summary of the Pull Request Removes all C++/CX code, replacing it with C++/WinRT. ## Detailed Description of the Pull Request / Additional comments Removes all C++/CX code. Renames interop namespaces to be better consumed by CsWinRT. Standardizes all projects on net8.0-windows10.0.20348.0, which is a requirement for C++/WinRT usage. FileLocksmithLibInterop brought to stdcpplatest and static analysis errors were corrected. Removed now unneeded string conversion code from FileLocksmithLibInterop. Changed interop KeyboardHook to use a single hook across all instances. Required because on C++/WinRT we don't have the .NET runtime to bind a object instance to a delegate and be able to pass it to a C function pointer argument (still no idea why this worked correctly on C++/CX to be honest). This change actually makes us create less low level keyboard hooks. Changed some code that depended on arrays since WinRT/C++ returns null instead of an empty array through the interface. ## Validation Steps Performed Built and tested runtime. --- PowerToys.sln | 31 +- installer/PowerToysSetup/KeyboardManager.wxs | 8 +- .../AllExperiments/AllExperiments.csproj | 3 + src/common/Common.UI/Common.UI.csproj | 3 +- .../FilePreviewCommon.csproj | 2 +- src/common/ManagedCommon/Logger.cs | 2 +- src/common/ManagedCommon/ManagedCommon.csproj | 10 +- .../Telemetry/ManagedTelemetry.csproj | 2 +- src/common/interop/CommonManaged.cpp | 39 +++ src/common/interop/CommonManaged.h | 20 ++ src/common/interop/CommonManaged.idl | 11 + src/common/interop/Constants.cpp | 146 +++++++++ src/common/interop/Constants.h | 50 +++ src/common/interop/Constants.idl | 41 +++ src/common/interop/HotkeyManager.cpp | 145 ++++----- src/common/interop/HotkeyManager.h | 65 ++-- src/common/interop/HotkeyManager.idl | 23 ++ src/common/interop/KeyboardHook.cpp | 136 ++++---- src/common/interop/KeyboardHook.h | 63 ++-- src/common/interop/KeyboardHook.idl | 23 ++ src/common/interop/LayoutMapManaged.cpp | 19 ++ src/common/interop/LayoutMapManaged.h | 24 ++ src/common/interop/LayoutMapManaged.idl | 12 + src/common/interop/PowerToys.Interop.def | 3 + src/common/interop/PowerToys.Interop.vcxproj | 136 +++++--- .../interop/PowerToys.Interop.vcxproj.filters | 87 ++++- src/common/interop/PropertySheet.props | 16 + .../interop/TwoWayPipeMessageIPCManaged.cpp | 37 +++ .../interop/TwoWayPipeMessageIPCManaged.h | 28 ++ .../interop/TwoWayPipeMessageIPCManaged.idl | 14 + .../interop/interop-tests/InteropTests.cs | 2 +- .../Microsoft.Interop.Tests.csproj | 10 +- src/common/interop/interop.cpp | 299 ------------------ src/common/interop/pch.cpp | 1 + src/common/interop/pch.h | 11 +- src/common/interop/two_way_pipe_message_ipc.h | 3 +- .../DSCGeneration.cs | 4 +- ...rToys.Settings.DSC.Schema.Generator.csproj | 5 +- .../AdvancedPasteXAML/App.xaml.cs | 6 +- .../FileLocksmithLibInterop/FileLocksmith.cpp | 4 +- .../FileLocksmithLibInterop.vcxproj | 191 ++++------- .../FileLocksmithLibInterop.vcxproj.filters | 26 +- .../FileLocksmithLibInterop/NativeMethods.cpp | 208 ++++++++++++ .../FileLocksmithLibInterop/NativeMethods.h | 23 ++ .../FileLocksmithLibInterop/NativeMethods.idl | 19 ++ .../FileLocksmithLibInterop/NtdllBase.cpp | 6 +- .../NtdllExtensions.cpp | 26 +- .../PowerToys.FileLocksmithLibInterop.def | 3 + .../FileLocksmithLibInterop/ProcessResult.cpp | 29 ++ .../FileLocksmithLibInterop/ProcessResult.h | 28 ++ .../FileLocksmithLibInterop/ProcessResult.idl | 16 + .../FileLocksmithLibInterop/interop.cpp | 248 --------------- .../FileLocksmithLibInterop/packages.config | 4 + .../FileLocksmithLibInterop/pch.h | 2 + .../Converters/FileCountConverter.cs | 2 +- .../FileListToDescriptionConverter.cs | 2 +- .../Converters/PidToIconConverter.cs | 2 +- .../UserToSystemWarningVisibilityConverter.cs | 2 +- .../FileLocksmithUI/FileLocksmithUI.csproj | 2 +- .../FileLocksmithXAML/App.xaml.cs | 4 +- .../FileLocksmithXAML/Views/MainPage.xaml | 2 +- .../FileLocksmithXAML/Views/MainPage.xaml.cs | 2 +- .../ViewModels/MainViewModel.cs | 14 +- src/modules/MouseUtils/MouseJumpUI/Program.cs | 2 +- .../PowerOCR/Keyboard/EventMonitor.cs | 2 +- src/modules/awake/Awake/Program.cs | 2 +- .../ColorPickerUI/ViewModels/MainViewModel.cs | 2 +- .../editor/FancyZonesEditor/App.xaml.cs | 2 +- .../KeyboardManagerEditor.vcxproj | 3 + ...s.Run.Plugin.UnitConverter.UnitTest.csproj | 3 +- ....PowerToys.Run.Plugin.UnitConverter.csproj | 3 +- ...werToys.Run.Plugin.VSCodeWorkspaces.csproj | 3 +- ...Run.Plugin.ValueGenerator.UnitTests.csproj | 3 +- ...PowerToys.Run.Plugin.ValueGenerator.csproj | 3 +- ...nity.PowerToys.Run.Plugin.WebSearch.csproj | 3 +- .../Microsoft.Plugin.Folder.UnitTests.csproj | 3 +- .../Microsoft.Plugin.Folder.csproj | 3 +- .../Microsoft.Plugin.Indexer.csproj | 3 +- .../Microsoft.Plugin.Program.UnitTests.csproj | 1 + .../Microsoft.Plugin.Program.csproj | 1 + .../Microsoft.Plugin.Shell.csproj | 3 +- .../Microsoft.Plugin.Uri.UnitTests.csproj | 3 +- .../Microsoft.Plugin.Uri.csproj | 3 +- ...osoft.Plugin.WindowWalker.UnitTests.csproj | 3 +- .../Microsoft.Plugin.WindowWalker.csproj | 3 +- ...Toys.Run.Plugin.Calculator.UnitTest.csproj | 3 +- ...oft.PowerToys.Run.Plugin.Calculator.csproj | 3 +- ...rosoft.PowerToys.Run.Plugin.OneNote.csproj | 3 +- .../Components/Utility.cs | 2 +- .../Components/UtilityProvider.cs | 2 +- ...rToys.Run.Plugin.Registry.UnitTests.csproj | 3 +- ...osoft.PowerToys.Run.Plugin.Registry.csproj | 3 +- ...rosoft.PowerToys.Run.Plugin.Service.csproj | 3 +- ...werToys.Run.Plugin.System.UnitTests.csproj | 3 +- ...crosoft.PowerToys.Run.Plugin.System.csproj | 3 +- ...rToys.Run.Plugin.TimeDate.UnitTests.csproj | 3 +- ...osoft.PowerToys.Run.Plugin.TimeDate.csproj | 3 +- ...owerToys.Run.Plugin.WindowsSettings.csproj | 3 +- ...ft.Plugin.WindowsTerminal.UnitTests.csproj | 1 + ...owerToys.Run.Plugin.WindowsTerminal.csproj | 1 + .../PowerLauncher.Telemetry.csproj | 2 +- .../launcher/PowerLauncher/App.xaml.cs | 2 +- .../launcher/PowerLauncher/MainWindow.xaml.cs | 2 +- .../PowerLauncher/ViewModel/MainViewModel.cs | 2 +- .../Wox.Infrastructure.csproj | 3 +- .../launcher/Wox.Plugin/Wox.Plugin.csproj | 3 +- .../peek/Peek.Common/Peek.Common.csproj | 1 + .../Peek.FilePreviewer.csproj | 1 + src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs | 2 +- .../poweraccent/PowerAccent.UI/Program.cs | 2 +- .../GcodePreviewHandler/Program.cs | 2 +- .../MarkdownPreviewHandler/Program.cs | 2 +- .../MonacoPreviewHandler/Program.cs | 2 +- .../previewpane/PdfPreviewHandler/Program.cs | 2 +- .../previewpane/QoiPreviewHandler/Program.cs | 2 +- .../previewpane/SvgPreviewHandler/Program.cs | 2 +- .../UnitTests-PreviewHandlerCommon.csproj | 2 +- .../common/PreviewHandlerCommon.csproj | 2 +- .../RegistryPreview/RegistryPreview.csproj | 1 + .../MicrophoneDevice.cpp | 1 + .../VideoCaptureDeviceList.cpp | 1 + .../VideoConferenceShared.vcxproj | 3 +- .../VideoConferenceShared/pch.h | 2 + .../Settings.UI.Library/GeneralSettings.cs | 2 +- .../HotkeySettingsControlHook.cs | 2 +- .../Settings.UI.Library.csproj | 4 +- .../Settings.UI.Library/Utilities/Helper.cs | 6 +- .../Settings.UI/SettingsXAML/App.xaml.cs | 2 +- .../SettingsXAML/Flyout/AppsListPage.xaml.cs | 2 +- .../SettingsXAML/Flyout/LaunchPage.xaml.cs | 2 +- .../Views/OobeEnvironmentVariables.xaml.cs | 2 +- .../SettingsXAML/OOBE/Views/OobeHosts.xaml.cs | 2 +- .../SettingsXAML/OobeWindow.xaml.cs | 2 +- .../EnvironmentVariablesViewModel.cs | 2 +- .../Settings.UI/ViewModels/HostsViewModel.cs | 2 +- .../ViewModels/VideoConferenceViewModel.cs | 5 +- 136 files changed, 1486 insertions(+), 1094 deletions(-) create mode 100644 src/common/interop/CommonManaged.cpp create mode 100644 src/common/interop/CommonManaged.h create mode 100644 src/common/interop/CommonManaged.idl create mode 100644 src/common/interop/Constants.cpp create mode 100644 src/common/interop/Constants.h create mode 100644 src/common/interop/Constants.idl create mode 100644 src/common/interop/HotkeyManager.idl create mode 100644 src/common/interop/KeyboardHook.idl create mode 100644 src/common/interop/LayoutMapManaged.cpp create mode 100644 src/common/interop/LayoutMapManaged.h create mode 100644 src/common/interop/LayoutMapManaged.idl create mode 100644 src/common/interop/PowerToys.Interop.def create mode 100644 src/common/interop/PropertySheet.props create mode 100644 src/common/interop/TwoWayPipeMessageIPCManaged.cpp create mode 100644 src/common/interop/TwoWayPipeMessageIPCManaged.h create mode 100644 src/common/interop/TwoWayPipeMessageIPCManaged.idl delete mode 100644 src/common/interop/interop.cpp create mode 100644 src/common/interop/pch.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.h create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.idl create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/PowerToys.FileLocksmithLibInterop.def create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.h create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.idl delete mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/interop.cpp create mode 100644 src/modules/FileLocksmith/FileLocksmithLibInterop/packages.config create mode 100644 src/modules/videoconference/VideoConferenceShared/pch.h diff --git a/PowerToys.sln b/PowerToys.sln index e2fc9edb66c9..3e2cad691a98 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -182,11 +182,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Settings.UI.Library", "src\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj", "{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerToys.Interop", "src\common\interop\PowerToys.Interop.vcxproj", "{F055103B-F80B-4D0C-BF48-057C55620033}" - ProjectSection(ProjectDependencies) = postProject - {CC6E41AC-8174-4E8A-8D22-85DD7F4851DF} = {CC6E41AC-8174-4E8A-8D22-85DD7F4851DF} - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Plugin.Folder", "src\modules\launcher\Plugins\Microsoft.Plugin.Folder\Microsoft.Plugin.Folder.csproj", "{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerLauncher.Telemetry", "src\modules\launcher\PowerLauncher.Telemetry\PowerLauncher.Telemetry.csproj", "{08C8C05F-0362-41BC-818C-724572DF8B06}" @@ -585,6 +580,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerToys.Settings.DSC.Sche {020A7474-3601-4160-A159-D7B70B77B15F} = {020A7474-3601-4160-A159-D7B70B77B15F} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerToys.Interop", "src\common\interop\PowerToys.Interop.vcxproj", "{F055103B-F80B-4D0C-BF48-057C55620033}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -955,16 +952,6 @@ Global {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|x64 {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|x64 {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.ActiveCfg = Release|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.Build.0 = Debug|ARM64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.ActiveCfg = Debug|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.Build.0 = Debug|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x86.ActiveCfg = Debug|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.ActiveCfg = Release|ARM64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.Build.0 = Release|ARM64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.ActiveCfg = Release|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.Build.0 = Release|x64 - {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x86.ActiveCfg = Release|x64 {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|ARM64.ActiveCfg = Debug|ARM64 {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|ARM64.Build.0 = Debug|ARM64 {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|x64.ActiveCfg = Debug|x64 @@ -2601,6 +2588,18 @@ Global {1D6893CB-BC0C-46A8-A76C-9728706CA51A}.Release|x64.Build.0 = Release|x64 {1D6893CB-BC0C-46A8-A76C-9728706CA51A}.Release|x86.ActiveCfg = Release|x64 {1D6893CB-BC0C-46A8-A76C-9728706CA51A}.Release|x86.Build.0 = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.Build.0 = Debug|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.ActiveCfg = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.Build.0 = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x86.ActiveCfg = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x86.Build.0 = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.ActiveCfg = Release|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.Build.0 = Release|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.ActiveCfg = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.Build.0 = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x86.ActiveCfg = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2647,7 +2646,6 @@ Global {748417CA-F17E-487F-9411-CAFB6D3F4877} = {2F305555-C296-497E-AC20-5FA1B237996A} {217DF501-135C-4E38-BFC8-99D4821032EA} = {2F305555-C296-497E-AC20-5FA1B237996A} {B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A} = {C3081D9A-1586-441A-B5F4-ED815B3719C1} - {F055103B-F80B-4D0C-BF48-057C55620033} = {5A7818A8-109C-4E1C-850D-1A654E234B0E} {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {4AFC9975-2456-4C70-94A4-84073C1CED93} {08C8C05F-0362-41BC-818C-724572DF8B06} = {C140A3EF-6DBF-4084-9D4C-4EB5A99FEE68} {5D00D290-4016-4CFE-9E41-1E7C724509BA} = {1AFB6476-670D-4E80-A464-657E01DFF482} @@ -2817,6 +2815,7 @@ Global {3A9A791E-94A9-49F8-8401-C11CE288D5FB} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} {C0974915-8A1D-4BF0-977B-9587D3807AB7} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} {1D6893CB-BC0C-46A8-A76C-9728706CA51A} = {557C4636-D7E1-4838-A504-7D19B725EE95} + {F055103B-F80B-4D0C-BF48-057C55620033} = {5A7818A8-109C-4E1C-850D-1A654E234B0E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/installer/PowerToysSetup/KeyboardManager.wxs b/installer/PowerToysSetup/KeyboardManager.wxs index 0c7376a33f46..dc216ccde301 100644 --- a/installer/PowerToysSetup/KeyboardManager.wxs +++ b/installer/PowerToysSetup/KeyboardManager.wxs @@ -25,11 +25,9 @@ - - - - - + + + diff --git a/src/common/AllExperiments/AllExperiments.csproj b/src/common/AllExperiments/AllExperiments.csproj index 7c42c36e947e..a7b46b9bdae6 100644 --- a/src/common/AllExperiments/AllExperiments.csproj +++ b/src/common/AllExperiments/AllExperiments.csproj @@ -15,6 +15,9 @@ + + + diff --git a/src/common/Common.UI/Common.UI.csproj b/src/common/Common.UI/Common.UI.csproj index 1a3edaaa9ce5..7aa067ef05b1 100644 --- a/src/common/Common.UI/Common.UI.csproj +++ b/src/common/Common.UI/Common.UI.csproj @@ -2,13 +2,14 @@ - net8.0-windows + net8.0-windows10.0.20348.0 win-x64;win-arm64 true PowerToys.Common.UI + diff --git a/src/common/FilePreviewCommon/FilePreviewCommon.csproj b/src/common/FilePreviewCommon/FilePreviewCommon.csproj index c62d4334cc1c..5165e15a6630 100644 --- a/src/common/FilePreviewCommon/FilePreviewCommon.csproj +++ b/src/common/FilePreviewCommon/FilePreviewCommon.csproj @@ -1,7 +1,7 @@  - net8.0-windows + net8.0-windows10.0.20348.0 win-x64;win-arm64 PowerToys FilePreviewCommon PowerToys.FilePreviewCommon diff --git a/src/common/ManagedCommon/Logger.cs b/src/common/ManagedCommon/Logger.cs index ad0819b6c6b7..acd1a381f181 100644 --- a/src/common/ManagedCommon/Logger.cs +++ b/src/common/ManagedCommon/Logger.cs @@ -7,7 +7,7 @@ using System.Globalization; using System.IO.Abstractions; using System.Reflection; -using interop; +using PowerToys.Interop; namespace ManagedCommon { diff --git a/src/common/ManagedCommon/ManagedCommon.csproj b/src/common/ManagedCommon/ManagedCommon.csproj index dfc45169e1ac..12e26113308c 100644 --- a/src/common/ManagedCommon/ManagedCommon.csproj +++ b/src/common/ManagedCommon/ManagedCommon.csproj @@ -1,13 +1,21 @@  - net8.0-windows + net8.0-windows10.0.20348.0 win-x64;win-arm64 PowerToys ManagedCommon PowerToys.ManagedCommon + + + PowerToys.Interop + $(OutDir) + false + + + diff --git a/src/common/ManagedTelemetry/Telemetry/ManagedTelemetry.csproj b/src/common/ManagedTelemetry/Telemetry/ManagedTelemetry.csproj index 46d7ae693713..1a14bc979fd3 100644 --- a/src/common/ManagedTelemetry/Telemetry/ManagedTelemetry.csproj +++ b/src/common/ManagedTelemetry/Telemetry/ManagedTelemetry.csproj @@ -1,6 +1,6 @@  - net8.0-windows + net8.0-windows10.0.20348.0 win-x64;win-arm64 PowerToys Telemetry PowerToys.ManagedTelemetry diff --git a/src/common/interop/CommonManaged.cpp b/src/common/interop/CommonManaged.cpp new file mode 100644 index 000000000000..39ae2967b42c --- /dev/null +++ b/src/common/interop/CommonManaged.cpp @@ -0,0 +1,39 @@ +#include "pch.h" +#include "CommonManaged.h" +#include "CommonManaged.g.cpp" +#include +#include "../../modules/videoconference/VideoConferenceShared/MicrophoneDevice.h" +#include "../../modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.h" + +namespace winrt::PowerToys::Interop::implementation +{ + hstring CommonManaged::GetProductVersion() + { + return hstring{ get_product_version() }; + } + winrt::Windows::Foundation::Collections::IVector CommonManaged::GetAllActiveMicrophoneDeviceNames() + { + auto names = std::vector(); + for (const auto& device : MicrophoneDevice::getAllActive()) + { + names.push_back(device->name().data()); + } + return winrt::multi_threaded_vector(std::move(names)); + } + winrt::Windows::Foundation::Collections::IVector CommonManaged::GetAllVideoCaptureDeviceNames() + { + auto names = std::vector(); + VideoCaptureDeviceList vcdl; + vcdl.EnumerateDevices(); + + for (UINT32 i = 0; i < vcdl.Count(); ++i) + { + auto name = vcdl.GetDeviceName(i).data(); + if (name != L"PowerToys VideoConference Mute") + { + names.push_back(name); + } + } + return winrt::multi_threaded_vector(std::move(names)); + } +} diff --git a/src/common/interop/CommonManaged.h b/src/common/interop/CommonManaged.h new file mode 100644 index 000000000000..96d6f5d8a549 --- /dev/null +++ b/src/common/interop/CommonManaged.h @@ -0,0 +1,20 @@ +#pragma once +#include "CommonManaged.g.h" + +namespace winrt::PowerToys::Interop::implementation +{ + struct CommonManaged : CommonManagedT + { + CommonManaged() = default; + + static hstring GetProductVersion(); + static winrt::Windows::Foundation::Collections::IVector GetAllActiveMicrophoneDeviceNames(); + static winrt::Windows::Foundation::Collections::IVector GetAllVideoCaptureDeviceNames(); + }; +} +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct CommonManaged : CommonManagedT + { + }; +} diff --git a/src/common/interop/CommonManaged.idl b/src/common/interop/CommonManaged.idl new file mode 100644 index 000000000000..0a523e790a52 --- /dev/null +++ b/src/common/interop/CommonManaged.idl @@ -0,0 +1,11 @@ +namespace PowerToys +{ + namespace Interop + { + [default_interface] static runtimeclass CommonManaged { + static String GetProductVersion(); + static Windows.Foundation.Collections.IVector GetAllActiveMicrophoneDeviceNames(); + static Windows.Foundation.Collections.IVector GetAllVideoCaptureDeviceNames(); + } + } +} \ No newline at end of file diff --git a/src/common/interop/Constants.cpp b/src/common/interop/Constants.cpp new file mode 100644 index 000000000000..57ebaa5661a0 --- /dev/null +++ b/src/common/interop/Constants.cpp @@ -0,0 +1,146 @@ +#include "pch.h" +#include "Constants.h" +#include "Constants.g.cpp" +#include "shared_constants.h" +#include + +namespace winrt::PowerToys::Interop::implementation +{ + uint32_t Constants::VK_WIN_BOTH() + { + return CommonSharedConstants::VK_WIN_BOTH; + } + hstring Constants::AppDataPath() + { + PWSTR local_app_path; + winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &local_app_path)); + winrt::hstring result{ local_app_path }; + CoTaskMemFree(local_app_path); + result = result + L"\\" + CommonSharedConstants::APPDATA_PATH; + return result; + } + hstring Constants::PowerLauncherSharedEvent() + { + return CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT; + } + hstring Constants::PowerLauncherCentralizedHookSharedEvent() + { + return CommonSharedConstants::POWER_LAUNCHER_CENTRALIZED_HOOK_SHARED_EVENT; + } + hstring Constants::RunSendSettingsTelemetryEvent() + { + return CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT; + } + hstring Constants::RunExitEvent() + { + return CommonSharedConstants::RUN_EXIT_EVENT; + } + hstring Constants::FZEExitEvent() + { + return CommonSharedConstants::FZE_EXIT_EVENT; + } + hstring Constants::FZEToggleEvent() + { + return CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT; + } + hstring Constants::ColorPickerSendSettingsTelemetryEvent() + { + return CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT; + } + hstring Constants::ShowColorPickerSharedEvent() + { + return CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT; + } + hstring Constants::ShowAdvancedPasteSharedEvent() + { + return CommonSharedConstants::SHOW_ADVANCED_PASTE_SHARED_EVENT; + } + hstring Constants::AdvancedPasteMarkdownEvent() + { + return CommonSharedConstants::ADVANCED_PASTE_MARKDOWN_EVENT; + } + hstring Constants::AdvancedPasteJsonEvent() + { + return CommonSharedConstants::ADVANCED_PASTE_JSON_EVENT; + } + hstring Constants::ShowPowerOCRSharedEvent() + { + return CommonSharedConstants::SHOW_POWEROCR_SHARED_EVENT; + } + hstring Constants::MouseJumpShowPreviewEvent() + { + return CommonSharedConstants::MOUSE_JUMP_SHOW_PREVIEW_EVENT; + } + hstring Constants::AwakeExitEvent() + { + return CommonSharedConstants::AWAKE_EXIT_EVENT; + } + hstring Constants::ShowPeekEvent() + { + return CommonSharedConstants::SHOW_PEEK_SHARED_EVENT; + } + hstring Constants::PowerAccentExitEvent() + { + return CommonSharedConstants::POWERACCENT_EXIT_EVENT; + } + hstring Constants::ShortcutGuideTriggerEvent() + { + return CommonSharedConstants::SHORTCUT_GUIDE_TRIGGER_EVENT; + } + hstring Constants::RegistryPreviewTriggerEvent() + { + return CommonSharedConstants::REGISTRY_PREVIEW_TRIGGER_EVENT; + } + hstring Constants::MeasureToolTriggerEvent() + { + return CommonSharedConstants::MEASURE_TOOL_TRIGGER_EVENT; + } + hstring Constants::GcodePreviewResizeEvent() + { + return CommonSharedConstants::GCODE_PREVIEW_RESIZE_EVENT; + } + hstring Constants::QoiPreviewResizeEvent() + { + return CommonSharedConstants::QOI_PREVIEW_RESIZE_EVENT; + } + hstring Constants::DevFilesPreviewResizeEvent() + { + return CommonSharedConstants::DEV_FILES_PREVIEW_RESIZE_EVENT; + } + hstring Constants::MarkdownPreviewResizeEvent() + { + return CommonSharedConstants::MARKDOWN_PREVIEW_RESIZE_EVENT; + } + hstring Constants::PdfPreviewResizeEvent() + { + return CommonSharedConstants::PDF_PREVIEW_RESIZE_EVENT; + } + hstring Constants::SvgPreviewResizeEvent() + { + return CommonSharedConstants::SVG_PREVIEW_RESIZE_EVENT; + } + hstring Constants::ShowHostsSharedEvent() + { + return CommonSharedConstants::SHOW_HOSTS_EVENT; + } + hstring Constants::ShowHostsAdminSharedEvent() + { + return CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT; + } + hstring Constants::CropAndLockThumbnailEvent() + { + return CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT; + } + hstring Constants::CropAndLockReparentEvent() + { + return CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT; + } + hstring Constants::ShowEnvironmentVariablesSharedEvent() + { + return CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT; + } + hstring Constants::ShowEnvironmentVariablesAdminSharedEvent() + { + return CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT; + } +} diff --git a/src/common/interop/Constants.h b/src/common/interop/Constants.h new file mode 100644 index 000000000000..319c6b76b3bd --- /dev/null +++ b/src/common/interop/Constants.h @@ -0,0 +1,50 @@ +#pragma once +#include "Constants.g.h" +namespace winrt::PowerToys::Interop::implementation +{ + struct Constants : ConstantsT + { + Constants() = default; + + static uint32_t VK_WIN_BOTH(); + static hstring AppDataPath(); + static hstring PowerLauncherSharedEvent(); + static hstring PowerLauncherCentralizedHookSharedEvent(); + static hstring RunSendSettingsTelemetryEvent(); + static hstring RunExitEvent(); + static hstring FZEExitEvent(); + static hstring FZEToggleEvent(); + static hstring ColorPickerSendSettingsTelemetryEvent(); + static hstring ShowColorPickerSharedEvent(); + static hstring ShowAdvancedPasteSharedEvent(); + static hstring AdvancedPasteMarkdownEvent(); + static hstring AdvancedPasteJsonEvent(); + static hstring ShowPowerOCRSharedEvent(); + static hstring MouseJumpShowPreviewEvent(); + static hstring AwakeExitEvent(); + static hstring ShowPeekEvent(); + static hstring PowerAccentExitEvent(); + static hstring ShortcutGuideTriggerEvent(); + static hstring RegistryPreviewTriggerEvent(); + static hstring MeasureToolTriggerEvent(); + static hstring GcodePreviewResizeEvent(); + static hstring QoiPreviewResizeEvent(); + static hstring DevFilesPreviewResizeEvent(); + static hstring MarkdownPreviewResizeEvent(); + static hstring PdfPreviewResizeEvent(); + static hstring SvgPreviewResizeEvent(); + static hstring ShowHostsSharedEvent(); + static hstring ShowHostsAdminSharedEvent(); + static hstring CropAndLockThumbnailEvent(); + static hstring CropAndLockReparentEvent(); + static hstring ShowEnvironmentVariablesSharedEvent(); + static hstring ShowEnvironmentVariablesAdminSharedEvent(); + }; +} + +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct Constants : ConstantsT + { + }; +} diff --git a/src/common/interop/Constants.idl b/src/common/interop/Constants.idl new file mode 100644 index 000000000000..0f33274a9335 --- /dev/null +++ b/src/common/interop/Constants.idl @@ -0,0 +1,41 @@ +namespace PowerToys +{ + namespace Interop + { + [default_interface] static runtimeclass Constants { + static UInt32 VK_WIN_BOTH {get; }; + static String AppDataPath(); + static String PowerLauncherSharedEvent(); + static String PowerLauncherCentralizedHookSharedEvent(); + static String RunSendSettingsTelemetryEvent(); + static String RunExitEvent(); + static String FZEExitEvent(); + static String FZEToggleEvent(); + static String ColorPickerSendSettingsTelemetryEvent(); + static String ShowColorPickerSharedEvent(); + static String ShowAdvancedPasteSharedEvent(); + static String AdvancedPasteMarkdownEvent(); + static String AdvancedPasteJsonEvent(); + static String ShowPowerOCRSharedEvent(); + static String MouseJumpShowPreviewEvent(); + static String AwakeExitEvent(); + static String ShowPeekEvent(); + static String PowerAccentExitEvent(); + static String ShortcutGuideTriggerEvent(); + static String RegistryPreviewTriggerEvent(); + static String MeasureToolTriggerEvent(); + static String GcodePreviewResizeEvent(); + static String QoiPreviewResizeEvent(); + static String DevFilesPreviewResizeEvent(); + static String MarkdownPreviewResizeEvent(); + static String PdfPreviewResizeEvent(); + static String SvgPreviewResizeEvent(); + static String ShowHostsSharedEvent(); + static String ShowHostsAdminSharedEvent(); + static String CropAndLockThumbnailEvent(); + static String CropAndLockReparentEvent(); + static String ShowEnvironmentVariablesSharedEvent(); + static String ShowEnvironmentVariablesAdminSharedEvent(); + } + } +} \ No newline at end of file diff --git a/src/common/interop/HotkeyManager.cpp b/src/common/interop/HotkeyManager.cpp index f38ad4d1ef6b..adcbb9ada0d8 100644 --- a/src/common/interop/HotkeyManager.cpp +++ b/src/common/interop/HotkeyManager.cpp @@ -1,94 +1,89 @@ #include "pch.h" #include "HotkeyManager.h" +#include "HotkeyManager.g.cpp" -using namespace interop; - -HotkeyManager::HotkeyManager() +namespace winrt::PowerToys::Interop::implementation { - keyboardEventCallback = gcnew KeyboardEventCallback(this, &HotkeyManager::KeyboardEventProc); - isActiveCallback = gcnew IsActiveCallback(this, &HotkeyManager::IsActiveProc); - filterKeyboardCallback = gcnew FilterKeyboardEvent(this, &HotkeyManager::FilterKeyboardProc); + HotkeyManager::HotkeyManager() + { + keyboardEventCallback = KeyboardEventCallback{ this, &HotkeyManager::KeyboardEventProc }; + isActiveCallback = IsActiveCallback{ this, &HotkeyManager::IsActiveProc }; + filterKeyboardCallback = FilterKeyboardEvent{ this, &HotkeyManager::FilterKeyboardProc }; + keyboardHook = KeyboardHook{ keyboardEventCallback, isActiveCallback, filterKeyboardCallback }; + keyboardHook.Start(); + } - keyboardHook = gcnew KeyboardHook( - keyboardEventCallback, - isActiveCallback, - filterKeyboardCallback); - hotkeys = gcnew Dictionary(); - pressedKeys = gcnew Hotkey(); - keyboardHook->Start(); -} + // When all Shortcut keys are pressed, fire the HotkeyCallback event. + void HotkeyManager::KeyboardEventProc(KeyboardEvent ev) + { + // pressedKeys always stores the latest keyboard state + auto pressedKeysHandle = GetHotkeyHandle(pressedKeys); + if (hotkeys.find(pressedKeysHandle) != hotkeys.end()) + { + hotkeys[pressedKeysHandle](); -HotkeyManager::~HotkeyManager() -{ - delete keyboardHook; -} + // After invoking the hotkey send a dummy key to prevent Start Menu from activating + INPUT dummyEvent[1] = {}; + dummyEvent[0].type = INPUT_KEYBOARD; + dummyEvent[0].ki.wVk = 0xFF; + dummyEvent[0].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(1, dummyEvent, sizeof(INPUT)); + } + } -// When all Shortcut keys are pressed, fire the HotkeyCallback event. -void HotkeyManager::KeyboardEventProc(KeyboardEvent ^ /*ev*/) -{ - // pressedKeys always stores the latest keyboard state - auto pressedKeysHandle = GetHotkeyHandle(pressedKeys); - if (hotkeys->ContainsKey(pressedKeysHandle)) + // Hotkeys are intended to be global, therefore they are always active no matter the + // context in which the keypress occurs. + bool HotkeyManager::IsActiveProc() { - hotkeys[pressedKeysHandle]->Invoke(); - - // After invoking the hotkey send a dummy key to prevent Start Menu from activating - INPUT dummyEvent[1] = {}; - dummyEvent[0].type = INPUT_KEYBOARD; - dummyEvent[0].ki.wVk = 0xFF; - dummyEvent[0].ki.dwFlags = KEYEVENTF_KEYUP; - SendInput(1, dummyEvent, sizeof(INPUT)); + return true; } -} + bool HotkeyManager::FilterKeyboardProc(KeyboardEvent ev) + { + // Updating the pressed keys here so we know if the keypress event should be propagated or not. + pressedKeys.Win = (GetAsyncKeyState(VK_LWIN) & 0x8000) || (GetAsyncKeyState(VK_RWIN) & 0x8000); + pressedKeys.Ctrl = GetAsyncKeyState(VK_CONTROL) & 0x8000; + pressedKeys.Alt = GetAsyncKeyState(VK_MENU) & 0x8000; + pressedKeys.Shift = GetAsyncKeyState(VK_SHIFT) & 0x8000; + pressedKeys.Key = static_cast(ev.key); -// Hotkeys are intended to be global, therefore they are always active no matter the -// context in which the keypress occurs. -bool HotkeyManager::IsActiveProc() -{ - return true; -} + // Convert to hotkey handle + auto pressedKeysHandle = GetHotkeyHandle(pressedKeys); -// KeyboardEvent callback is only fired for relevant key events. -bool HotkeyManager::FilterKeyboardProc(KeyboardEvent ^ ev) -{ - // Updating the pressed keys here so we know if the keypress event should be propagated or not. - pressedKeys->Win = (GetAsyncKeyState(VK_LWIN) & 0x8000) || (GetAsyncKeyState(VK_RWIN) & 0x8000); - pressedKeys->Ctrl = GetAsyncKeyState(VK_CONTROL) & 0x8000; - pressedKeys->Alt = GetAsyncKeyState(VK_MENU) & 0x8000; - pressedKeys->Shift = GetAsyncKeyState(VK_SHIFT) & 0x8000; - pressedKeys->Key = static_cast(ev->key); + // Check if any hotkey matches the pressed keys if the current key event is a key down event + if ((ev.message == WM_KEYDOWN || ev.message == WM_SYSKEYDOWN) && hotkeys.find(pressedKeysHandle)!=hotkeys.end()) + { + return true; + } - // Convert to hotkey handle - auto pressedKeysHandle = GetHotkeyHandle(pressedKeys); + return false; + } - // Check if any hotkey matches the pressed keys if the current key event is a key down event - if ((ev->message == WM_KEYDOWN || ev->message == WM_SYSKEYDOWN) && hotkeys->ContainsKey(pressedKeysHandle)) + uint16_t HotkeyManager::RegisterHotkey(winrt::PowerToys::Interop::Hotkey const& _hotkey, winrt::PowerToys::Interop::HotkeyCallback const& _callback) { - return true; + auto handle = GetHotkeyHandle(_hotkey); + hotkeys[handle] = _callback; + return handle; } - return false; -} - -// NOTE: Replaces old hotkey if one already present. -HOTKEY_HANDLE HotkeyManager::RegisterHotkey(Hotkey ^ hotkey, HotkeyCallback ^ callback) -{ - auto handle = GetHotkeyHandle(hotkey); - hotkeys[handle] = callback; - return handle; -} + void HotkeyManager::UnregisterHotkey(uint16_t _handle) + { + auto iter = hotkeys.find(_handle); + if (iter != hotkeys.end()) { + hotkeys.erase(iter); + } + } -void HotkeyManager::UnregisterHotkey(HOTKEY_HANDLE handle) -{ - hotkeys->Remove(handle); -} + void HotkeyManager::Close() + { + } -HOTKEY_HANDLE HotkeyManager::GetHotkeyHandle(Hotkey ^ hotkey) -{ - HOTKEY_HANDLE handle = hotkey->Key; - handle |= hotkey->Win << 8; - handle |= hotkey->Ctrl << 9; - handle |= hotkey->Shift << 10; - handle |= hotkey->Alt << 11; - return handle; + uint16_t HotkeyManager::GetHotkeyHandle(Hotkey hotkey) + { + uint16_t handle = hotkey.Key; + handle |= hotkey.Win << 8; + handle |= hotkey.Ctrl << 9; + handle |= hotkey.Shift << 10; + handle |= hotkey.Alt << 11; + return handle; + } } diff --git a/src/common/interop/HotkeyManager.h b/src/common/interop/HotkeyManager.h index 0f5c94bf3894..bc8898e5aea4 100644 --- a/src/common/interop/HotkeyManager.h +++ b/src/common/interop/HotkeyManager.h @@ -1,54 +1,33 @@ #pragma once -#include -#include "KeyboardHook.h" +#include "HotkeyManager.g.h" -namespace interop +namespace winrt::PowerToys::Interop::implementation { -public - ref struct Hotkey + struct HotkeyManager : HotkeyManagerT { - bool Win; - bool Ctrl; - bool Shift; - bool Alt; - unsigned char Key; - - Hotkey() - { - Win = false; - Ctrl = false; - Shift = false; - Alt = false; - Key = 0; - } - }; - -public - delegate void HotkeyCallback(); - - typedef unsigned short HOTKEY_HANDLE; - -public - ref class HotkeyManager - { - public: HotkeyManager(); - ~HotkeyManager(); - HOTKEY_HANDLE RegisterHotkey(Hotkey ^ hotkey, HotkeyCallback ^ callback); - void UnregisterHotkey(HOTKEY_HANDLE handle); + uint16_t RegisterHotkey(winrt::PowerToys::Interop::Hotkey const& _hotkey, winrt::PowerToys::Interop::HotkeyCallback const& _callback); + void UnregisterHotkey(uint16_t _handle); + void Close(); private: - KeyboardHook ^ keyboardHook; - Dictionary ^ hotkeys; - Hotkey ^ pressedKeys; - KeyboardEventCallback ^ keyboardEventCallback; - IsActiveCallback ^ isActiveCallback; - FilterKeyboardEvent ^ filterKeyboardCallback; - - void KeyboardEventProc(KeyboardEvent ^ ev); + KeyboardHook keyboardHook{ nullptr }; + std::map hotkeys; + Hotkey pressedKeys{ }; + KeyboardEventCallback keyboardEventCallback; + IsActiveCallback isActiveCallback; + FilterKeyboardEvent filterKeyboardCallback; + + void KeyboardEventProc(KeyboardEvent ev); bool IsActiveProc(); - bool FilterKeyboardProc(KeyboardEvent ^ ev); - HOTKEY_HANDLE GetHotkeyHandle(Hotkey ^ hotkey); + bool FilterKeyboardProc(KeyboardEvent ev); + uint16_t GetHotkeyHandle(Hotkey hotkey); + }; +} +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct HotkeyManager : HotkeyManagerT + { }; } diff --git a/src/common/interop/HotkeyManager.idl b/src/common/interop/HotkeyManager.idl new file mode 100644 index 000000000000..27cd7fbc7819 --- /dev/null +++ b/src/common/interop/HotkeyManager.idl @@ -0,0 +1,23 @@ +namespace PowerToys +{ + namespace Interop + { + struct Hotkey + { + Boolean Win; + Boolean Ctrl; + Boolean Shift; + Boolean Alt; + UInt8 Key; + }; + delegate void HotkeyCallback(); + + [default_interface] runtimeclass HotkeyManager : Windows.Foundation.IClosable + { + HotkeyManager(); + UInt16 RegisterHotkey(Hotkey _hotkey, HotkeyCallback _callback); + void UnregisterHotkey(UInt16 _handle); + } + + } +} diff --git a/src/common/interop/KeyboardHook.cpp b/src/common/interop/KeyboardHook.cpp index f1c09c78a2bb..065859468908 100644 --- a/src/common/interop/KeyboardHook.cpp +++ b/src/common/interop/KeyboardHook.cpp @@ -1,73 +1,99 @@ #include "pch.h" #include "KeyboardHook.h" -#include -#include -#include +#include "KeyboardHook.g.cpp" #include #include -using namespace interop; -using namespace System::Runtime::InteropServices; -using namespace System; -using namespace System::Diagnostics; - -KeyboardHook::KeyboardHook( - KeyboardEventCallback ^ keyboardEventCallback, - IsActiveCallback ^ isActiveCallback, - FilterKeyboardEvent ^ filterKeyboardEvent) +namespace winrt::PowerToys::Interop::implementation { - this->keyboardEventCallback = keyboardEventCallback; - this->isActiveCallback = isActiveCallback; - this->filterKeyboardEvent = filterKeyboardEvent; -} + std::mutex KeyboardHook::instancesMutex; + std::unordered_set KeyboardHook::instances; -KeyboardHook::~KeyboardHook() -{ - // Unregister low level hook procedure - UnhookWindowsHookEx(hookHandle); -} + KeyboardHook::KeyboardHook(winrt::PowerToys::Interop::KeyboardEventCallback const& keyboardEventCallback, winrt::PowerToys::Interop::IsActiveCallback const& isActiveCallback, winrt::PowerToys::Interop::FilterKeyboardEvent const& filterKeyboardEvent) + { + this->keyboardEventCallback = keyboardEventCallback; + this->isActiveCallback = isActiveCallback; + this->filterKeyboardEvent = filterKeyboardEvent; + } -void KeyboardHook::Start() -{ - hookProc = gcnew HookProcDelegate(this, &KeyboardHook::HookProc); -#if defined(DISABLE_LOWLEVEL_HOOKS_WHEN_DEBUGGED) - const bool hookDisabled = IsDebuggerPresent(); -#else - const bool hookDisabled = false; -#endif - if (!hookDisabled) + void KeyboardHook::Close() { - // register low level hook procedure - hookHandle = SetWindowsHookEx( - WH_KEYBOARD_LL, - (HOOKPROC)(void*)Marshal::GetFunctionPointerForDelegate(hookProc), - 0, - 0); - if (hookHandle == nullptr) + std::unique_lock lock { instancesMutex }; + auto iter = instances.find(this); + if (iter != instances.end()) { - DWORD errorCode = GetLastError(); - show_last_error_message(L"SetWindowsHookEx", errorCode, L"PowerToys - Interop"); + instances.erase(iter); + } + if (instances.size() < 1 && hookHandle != nullptr) + { + if (UnhookWindowsHookEx(hookHandle)) + { + hookHandle = nullptr; + } } } -} -LRESULT __clrcall KeyboardHook::HookProc(int nCode, WPARAM wParam, LPARAM lParam) -{ - if (nCode == HC_ACTION && isActiveCallback->Invoke()) - { - KeyboardEvent ^ ev = gcnew KeyboardEvent(); - ev->message = wParam; - ev->key = reinterpret_cast(lParam)->vkCode; - ev->dwExtraInfo = reinterpret_cast(lParam)->dwExtraInfo; - // Ignore the keyboard hook if the FilterkeyboardEvent returns false. - if ((filterKeyboardEvent != nullptr && !filterKeyboardEvent->Invoke(ev))) + void KeyboardHook::Start() + { +#if defined(DISABLE_LOWLEVEL_HOOKS_WHEN_DEBUGGED) + const bool hookDisabled = IsDebuggerPresent(); +#else + const bool hookDisabled = false; +#endif + if (!hookDisabled) { - return CallNextHookEx(hookHandle, nCode, wParam, lParam); + std::unique_lock lock { instancesMutex }; + assert(instances.find(this) == instances.end()); + // register low level hook procedure + instances.insert(this); + if (hookHandle == nullptr) + { + hookHandle = SetWindowsHookEx( + WH_KEYBOARD_LL, + HookProc, + 0, + 0); + if (hookHandle == nullptr) + { + DWORD errorCode = GetLastError(); + show_last_error_message(L"SetWindowsHookEx", errorCode, L"PowerToys - Interop"); + } + } } + } + LRESULT KeyboardHook::HookProc(int nCode, WPARAM wParam, LPARAM lParam) + { + if (nCode == HC_ACTION) + { + std::vector instances_copy; + { + /* Use a copy of instances, to iterate through the copy without needing to maintain the lock */ + std::unique_lock lock{ instancesMutex }; + instances_copy.reserve(instances.size()); + std::copy(instances.begin(), instances.end(), std::back_inserter(instances_copy)); + } + + for (auto const& s_instance : instances_copy) + { + if (s_instance->isActiveCallback()) + { + KeyboardEvent ev; + ev.message = wParam; + ev.key = reinterpret_cast(lParam)->vkCode; + ev.dwExtraInfo = reinterpret_cast(lParam)->dwExtraInfo; - keyboardEventCallback->Invoke(ev); - return 1; + // Ignore the keyboard hook if the FilterkeyboardEvent returns false. + if ((s_instance->filterKeyboardEvent != nullptr && !s_instance->filterKeyboardEvent(ev))) + { + continue; + } + + s_instance->keyboardEventCallback(ev); + return 1; + } + } + } + return CallNextHookEx(NULL, nCode, wParam, lParam); } - return CallNextHookEx(hookHandle, nCode, wParam, lParam); -} \ No newline at end of file +} diff --git a/src/common/interop/KeyboardHook.h b/src/common/interop/KeyboardHook.h index 1b14748e759f..1a8d834fed61 100644 --- a/src/common/interop/KeyboardHook.h +++ b/src/common/interop/KeyboardHook.h @@ -1,48 +1,35 @@ #pragma once +#include "KeyboardHook.g.h" +#include +#include -#include - -using namespace System::Threading; -using namespace System::Collections::Generic; - -namespace interop +namespace winrt::PowerToys::Interop::implementation { -public - ref struct KeyboardEvent - { - WPARAM message; - int key; - uint64_t dwExtraInfo; - }; - -public - delegate void KeyboardEventCallback(KeyboardEvent ^ ev); -public - delegate bool IsActiveCallback(); -public - delegate bool FilterKeyboardEvent(KeyboardEvent ^ ev); - -public - ref class KeyboardHook + struct KeyboardHook : KeyboardHookT { - public: - KeyboardHook( - KeyboardEventCallback ^ keyboardEventCallback, - IsActiveCallback ^ isActiveCallback, - FilterKeyboardEvent ^ filterKeyboardEvent); - ~KeyboardHook(); + // KeyboardHook() = default; + KeyboardHook(winrt::PowerToys::Interop::KeyboardEventCallback const& keyboardEventCallback, winrt::PowerToys::Interop::IsActiveCallback const& isActiveCallback, winrt::PowerToys::Interop::FilterKeyboardEvent const& filterKeyboardEvent); void Start(); + void Close(); private: - delegate LRESULT HookProcDelegate(int nCode, WPARAM wParam, LPARAM lParam); - KeyboardEventCallback ^ keyboardEventCallback; - IsActiveCallback ^ isActiveCallback; - FilterKeyboardEvent ^ filterKeyboardEvent; - HHOOK hookHandle; - HookProcDelegate ^ hookProc; - - LRESULT __clrcall HookProc(int nCode, WPARAM wParam, LPARAM lParam); + winrt::PowerToys::Interop::KeyboardEventCallback keyboardEventCallback; + winrt::PowerToys::Interop::IsActiveCallback isActiveCallback; + winrt::PowerToys::Interop::FilterKeyboardEvent filterKeyboardEvent; + + // This class used to be C++/CX, which meant it ran on .NET runtime and was able to send function pointer for delegates as hook procedures for SetWindowsHookEx which kept an object reference. + // There doesn't seem to be a way to do this outside of the .NET runtime that allows us to get a proper C-style function. + // The alternative when porting to C++/winrt is to keep track of every instance and use a single proc instead of one per object. This should also make it lighter. + static std::mutex instancesMutex; + static std::unordered_set instances; + static inline HHOOK hookHandle = nullptr; + static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam); + }; +} +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct KeyboardHook : KeyboardHookT + { }; - } diff --git a/src/common/interop/KeyboardHook.idl b/src/common/interop/KeyboardHook.idl new file mode 100644 index 000000000000..eae09269730a --- /dev/null +++ b/src/common/interop/KeyboardHook.idl @@ -0,0 +1,23 @@ +typedef UInt64 WPARAM; + +namespace PowerToys +{ + namespace Interop + { + struct KeyboardEvent + { + WPARAM message; + Int32 key; + UInt64 dwExtraInfo; + }; + + [version(1.0), uuid(7b820173-a54a-4a38-b810-810e05c14344)] delegate void KeyboardEventCallback(KeyboardEvent ev); + [version(1.0), uuid(e3a8bb91-0dfd-4d77-8472-75a47b7af8f8)] delegate Boolean IsActiveCallback(); + [version(1.0), uuid(94b900ee-d9e8-4630-9064-737eeb9c18ad)] delegate Boolean FilterKeyboardEvent(KeyboardEvent ev); + + [default_interface] runtimeclass KeyboardHook: Windows.Foundation.IClosable { + KeyboardHook(KeyboardEventCallback keyboardEventCallback, IsActiveCallback isActiveCallback, FilterKeyboardEvent filterKeyboardEvent); + void Start(); + } + } +} \ No newline at end of file diff --git a/src/common/interop/LayoutMapManaged.cpp b/src/common/interop/LayoutMapManaged.cpp new file mode 100644 index 000000000000..8ef49fd345d3 --- /dev/null +++ b/src/common/interop/LayoutMapManaged.cpp @@ -0,0 +1,19 @@ +#include "pch.h" +#include "LayoutMapManaged.h" +#include "LayoutMapManaged.g.cpp" + +namespace winrt::PowerToys::Interop::implementation +{ + hstring LayoutMapManaged::GetKeyName(uint32_t key) + { + return hstring{ _map->GetKeyName(key) }; + } + uint32_t LayoutMapManaged::GetKeyValue(hstring const& name) + { + return _map->GetKeyFromName(std::wstring(name)); + } + void LayoutMapManaged::Updatelayout() + { + _map->UpdateLayout(); + } +} diff --git a/src/common/interop/LayoutMapManaged.h b/src/common/interop/LayoutMapManaged.h new file mode 100644 index 000000000000..d192a6e92e7c --- /dev/null +++ b/src/common/interop/LayoutMapManaged.h @@ -0,0 +1,24 @@ +#pragma once +#include "LayoutMapManaged.g.h" +#include "keyboard_layout.h" + +namespace winrt::PowerToys::Interop::implementation +{ + struct LayoutMapManaged : LayoutMapManagedT + { + LayoutMapManaged() = default; + + hstring GetKeyName(uint32_t key); + uint32_t GetKeyValue(hstring const& name); + void Updatelayout(); + + private: + std::unique_ptr _map = std::make_unique(); + }; +} +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct LayoutMapManaged : LayoutMapManagedT + { + }; +} diff --git a/src/common/interop/LayoutMapManaged.idl b/src/common/interop/LayoutMapManaged.idl new file mode 100644 index 000000000000..62812700947c --- /dev/null +++ b/src/common/interop/LayoutMapManaged.idl @@ -0,0 +1,12 @@ +namespace PowerToys +{ + namespace Interop + { + [default_interface] runtimeclass LayoutMapManaged { + LayoutMapManaged(); + String GetKeyName(UInt32 key); + UInt32 GetKeyValue(String name); + void Updatelayout(); + } + } +} \ No newline at end of file diff --git a/src/common/interop/PowerToys.Interop.def b/src/common/interop/PowerToys.Interop.def new file mode 100644 index 000000000000..24e7c1235c39 --- /dev/null +++ b/src/common/interop/PowerToys.Interop.def @@ -0,0 +1,3 @@ +EXPORTS +DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE +DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/src/common/interop/PowerToys.Interop.vcxproj b/src/common/interop/PowerToys.Interop.vcxproj index 56292df1fd7d..8180339f37a6 100644 --- a/src/common/interop/PowerToys.Interop.vcxproj +++ b/src/common/interop/PowerToys.Interop.vcxproj @@ -1,6 +1,6 @@  - + PowerToys.Interop @@ -25,16 +25,25 @@ 16.0 {F055103B-F80B-4D0C-BF48-057C55620033} - net8.0-windows - ManagedCProj - PowerToysInterop + PowerToys.Interop PowerToys.Interop + true + true + true + true + en-US + 14.0 + false + false + Windows Store + 10.0 DynamicLibrary - NetCore v143 + Unicode + false @@ -55,93 +64,122 @@ MultiThreadedDebugDLL + true + true MultiThreadedDLL + false + true + false - PowerToysInterop;%(PreprocessorDefinitions) - NotUsing + $(IntDir)pch.pch + _WINRT_DLL;WINRT_LEAN_AND_MEAN;PowerToysInterop;%(PreprocessorDefinitions) $(SolutionDir)src\common\interop;../../;../;%(AdditionalIncludeDirectories) + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - /Zc:twoPhase- - stdcpp17 + %(AdditionalOptions) /bigobj /Zc:twoPhase- - WindowsApp.lib;%(AdditionalDependencies) + WindowsApp.lib;shell32.lib;advapi32.lib;%(AdditionalDependencies) + Console + false + PowerToys.Interop.def - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + CommonManaged.idl + + + KeyboardListener.idl + + + HotkeyManager.idl + + + KeyboardHook.idl + + + + + LayoutMapManaged.idl + + + TwoWayPipeMessageIPCManaged.idl + + + - - false + + + + CommonManaged.idl + + + KeyboardListener.idl + + + HotkeyManager.idl - - false + + KeyboardHook.idl - - - - - - false + + + LayoutMapManaged.idl - - false + + Create + + TwoWayPipeMessageIPCManaged.idl + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + \ No newline at end of file diff --git a/src/common/interop/PowerToys.Interop.vcxproj.filters b/src/common/interop/PowerToys.Interop.vcxproj.filters index cf0425666e52..5df4afc36889 100644 --- a/src/common/interop/PowerToys.Interop.vcxproj.filters +++ b/src/common/interop/PowerToys.Interop.vcxproj.filters @@ -18,12 +18,6 @@ Header Files - - Header Files - - - Header Files - Header Files @@ -36,30 +30,69 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + - + Source Files - + Source Files - + Source Files - + + Source Files + + + Header Files + + + Source Files + + Source Files Source Files - + Source Files - + Source Files - + Source Files @@ -69,9 +102,33 @@ - + + + Source Files + + - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + \ No newline at end of file diff --git a/src/common/interop/PropertySheet.props b/src/common/interop/PropertySheet.props new file mode 100644 index 000000000000..4f1a414a6e36 --- /dev/null +++ b/src/common/interop/PropertySheet.props @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/src/common/interop/TwoWayPipeMessageIPCManaged.cpp b/src/common/interop/TwoWayPipeMessageIPCManaged.cpp new file mode 100644 index 000000000000..544b9924f340 --- /dev/null +++ b/src/common/interop/TwoWayPipeMessageIPCManaged.cpp @@ -0,0 +1,37 @@ +#include "pch.h" +#include "TwoWayPipeMessageIPCManaged.h" +#include "TwoWayPipeMessageIPCManaged.g.cpp" +#include "two_way_pipe_message_ipc_impl.h" +#include + +namespace winrt::PowerToys::Interop::implementation +{ + TwoWayPipeMessageIPCManaged::TwoWayPipeMessageIPCManaged(hstring const& inputPipeName, hstring const& outputPipeName, winrt::PowerToys::Interop::TwoWayPipeIPCReadCallback const& _callback) + { + this->_callback = _callback; + if (_callback != nullptr) + { + _internalReadCallback = [this](const std::wstring& msg) { + this->_callback(msg); + }; + } + _pipe = new TwoWayPipeMessageIPC(std::wstring{ inputPipeName }, std::wstring{ outputPipeName }, _internalReadCallback); + } + + void TwoWayPipeMessageIPCManaged::Send(hstring const& msg) + { + _pipe->send(std::wstring{ msg }); + } + void TwoWayPipeMessageIPCManaged::Start() + { + _pipe->start(nullptr); + } + void TwoWayPipeMessageIPCManaged::End() + { + _pipe->end(); + } + void TwoWayPipeMessageIPCManaged::Close() + { + delete _pipe; + } +} diff --git a/src/common/interop/TwoWayPipeMessageIPCManaged.h b/src/common/interop/TwoWayPipeMessageIPCManaged.h new file mode 100644 index 000000000000..d68492be513e --- /dev/null +++ b/src/common/interop/TwoWayPipeMessageIPCManaged.h @@ -0,0 +1,28 @@ +#pragma once +#include "TwoWayPipeMessageIPCManaged.g.h" +#include "two_way_pipe_message_ipc.h" + +namespace winrt::PowerToys::Interop::implementation +{ + struct TwoWayPipeMessageIPCManaged : TwoWayPipeMessageIPCManagedT + { + TwoWayPipeMessageIPCManaged() = default; + + TwoWayPipeMessageIPCManaged(hstring const& inputPipeName, hstring const& outputPipeName, winrt::PowerToys::Interop::TwoWayPipeIPCReadCallback const& _callback); + void Send(hstring const& msg); + void Start(); + void End(); + void Close(); + + private: + TwoWayPipeMessageIPC* _pipe; + TwoWayPipeIPCReadCallback _callback; + std::function _internalReadCallback; + }; +} +namespace winrt::PowerToys::Interop::factory_implementation +{ + struct TwoWayPipeMessageIPCManaged : TwoWayPipeMessageIPCManagedT + { + }; +} diff --git a/src/common/interop/TwoWayPipeMessageIPCManaged.idl b/src/common/interop/TwoWayPipeMessageIPCManaged.idl new file mode 100644 index 000000000000..5e470639e950 --- /dev/null +++ b/src/common/interop/TwoWayPipeMessageIPCManaged.idl @@ -0,0 +1,14 @@ +namespace PowerToys +{ + namespace Interop + { + delegate void TwoWayPipeIPCReadCallback(String message); + [default_interface] runtimeclass TwoWayPipeMessageIPCManaged : Windows.Foundation.IClosable + { + TwoWayPipeMessageIPCManaged(String inputPipeName, String outputPipeName, TwoWayPipeIPCReadCallback _callback); + void Send(String msg); + void Start(); + void End(); + } + } +} \ No newline at end of file diff --git a/src/common/interop/interop-tests/InteropTests.cs b/src/common/interop/interop-tests/InteropTests.cs index 0ac159bb2c95..76362a549f51 100644 --- a/src/common/interop/interop-tests/InteropTests.cs +++ b/src/common/interop/interop-tests/InteropTests.cs @@ -4,8 +4,8 @@ using System; using System.Threading; -using interop; using Microsoft.VisualStudio.TestTools.UnitTesting; +using PowerToys.Interop; namespace Microsoft.Interop.Tests { diff --git a/src/common/interop/interop-tests/Microsoft.Interop.Tests.csproj b/src/common/interop/interop-tests/Microsoft.Interop.Tests.csproj index 849b072c3369..db7ef1695960 100644 --- a/src/common/interop/interop-tests/Microsoft.Interop.Tests.csproj +++ b/src/common/interop/interop-tests/Microsoft.Interop.Tests.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 false win-x64;win-arm64 @@ -46,7 +46,15 @@ prompt + + + PowerToys.Interop + $(OutDir) + false + + + diff --git a/src/common/interop/interop.cpp b/src/common/interop/interop.cpp deleted file mode 100644 index 6b5a86ec9baa..000000000000 --- a/src/common/interop/interop.cpp +++ /dev/null @@ -1,299 +0,0 @@ -#include "pch.h" - -#include -#include -#include -#include "keyboard_layout.h" -#include "two_way_pipe_message_ipc.h" -#include "shared_constants.h" - -// We cannot use C++/WinRT APIs when compiled with /clr (we'll get a runtime crash). os-detect API is used -// in both native C++ and C++/CX. -// We also cannot compile it as a library, since we use different cppruntime linkage in C++/CX and native C++. -// Therefore the simplest way is to compile these functions as native using the pragmas below. -#pragma managed(push, off) -#include "../utils/os-detect.h" -// TODO: move to a separate library in common -#include "../../modules/videoconference/VideoConferenceShared/MicrophoneDevice.h" -#include "../../modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.h" -#pragma managed(pop) - -#include - -using namespace System; -using namespace System::Runtime::InteropServices; -using System::Collections::Generic::List; - -// https://learn.microsoft.com/cpp/dotnet/how-to-wrap-native-class-for-use-by-csharp?view=vs-2019 -namespace interop -{ -public - ref class LayoutMapManaged - { - public: - LayoutMapManaged() : - _map(new LayoutMap) {} - - ~LayoutMapManaged() - { - delete _map; - } - - String ^ GetKeyName(DWORD key) - { - return gcnew String(_map->GetKeyName(key).c_str()); - } - - DWORD GetKeyValue(String ^ name) - { - return _map->GetKeyFromName(msclr::interop::marshal_as(name)); - } - - void Updatelayout() - { - _map->UpdateLayout(); - } - - protected: - !LayoutMapManaged() - { - delete _map; - } - - private: - LayoutMap* _map; - }; - -public - ref class TwoWayPipeMessageIPCManaged - { - public: - delegate void ReadCallback(String ^ message); - - TwoWayPipeMessageIPCManaged(String ^ inputPipeName, String ^ outputPipeName, ReadCallback ^ callback) - { - _wrapperCallback = gcnew InternalReadCallback(this, &TwoWayPipeMessageIPCManaged::ReadCallbackHelper); - _callback = callback; - - TwoWayPipeMessageIPC::callback_function cb = nullptr; - if (callback != nullptr) - { - cb = (TwoWayPipeMessageIPC::callback_function)(void*)Marshal::GetFunctionPointerForDelegate(_wrapperCallback); - } - _pipe = new TwoWayPipeMessageIPC( - msclr::interop::marshal_as(inputPipeName), - msclr::interop::marshal_as(outputPipeName), - cb); - } - - ~TwoWayPipeMessageIPCManaged() - { - delete _pipe; - } - - void Send(String ^ msg) - { - _pipe->send(msclr::interop::marshal_as(msg)); - } - - void Start() - { - _pipe->start(nullptr); - } - - void End() - { - _pipe->end(); - } - - protected: - !TwoWayPipeMessageIPCManaged() - { - delete _pipe; - } - - private: - delegate void InternalReadCallback(const std::wstring& msg); - - TwoWayPipeMessageIPC* _pipe; - ReadCallback ^ _callback; - InternalReadCallback ^ _wrapperCallback; - - void ReadCallbackHelper(const std::wstring& msg) - { - _callback(gcnew String(msg.c_str())); - } - }; - -public - ref class CommonManaged - { - public: - static String ^ GetProductVersion() { - return gcnew String(get_product_version().c_str()); - } - - static List ^ GetAllActiveMicrophoneDeviceNames() { - auto names = gcnew List(); - for (const auto& device : MicrophoneDevice::getAllActive()) - { - names->Add(gcnew String(device->name().data())); - } - return names; - } - - static List ^ - GetAllVideoCaptureDeviceNames() { - auto names = gcnew List(); - VideoCaptureDeviceList vcdl; - vcdl.EnumerateDevices(); - - for (UINT32 i = 0; i < vcdl.Count(); ++i) - { - auto name = gcnew String(vcdl.GetDeviceName(i).data()); - if (name != L"PowerToys VideoConference Mute") - { - names->Add(name); - } - } - return names; - } - }; - -public - ref class Constants - { - public: - literal int VK_WIN_BOTH = CommonSharedConstants::VK_WIN_BOTH; - - static String ^ AppDataPath() { - auto localPath = Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData); - auto powerToysPath = gcnew String(CommonSharedConstants::APPDATA_PATH); - return System::IO::Path::Combine(localPath, powerToysPath); - } - - static String ^ PowerLauncherSharedEvent() { - return gcnew String(CommonSharedConstants::POWER_LAUNCHER_SHARED_EVENT); - } - - static String ^ PowerLauncherCentralizedHookSharedEvent() { - return gcnew String(CommonSharedConstants::POWER_LAUNCHER_CENTRALIZED_HOOK_SHARED_EVENT); - } - - static String ^ RunSendSettingsTelemetryEvent() { - return gcnew String(CommonSharedConstants::RUN_SEND_SETTINGS_TELEMETRY_EVENT); - } - - static String ^ RunExitEvent() { - return gcnew String(CommonSharedConstants::RUN_EXIT_EVENT); - } - - static String ^ FZEExitEvent() { - return gcnew String(CommonSharedConstants::FZE_EXIT_EVENT); - } - - static String ^ FZEToggleEvent() { - return gcnew String(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT); - } - - static String ^ ColorPickerSendSettingsTelemetryEvent() { - return gcnew String(CommonSharedConstants::COLOR_PICKER_SEND_SETTINGS_TELEMETRY_EVENT); - } - - static String ^ ShowColorPickerSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_COLOR_PICKER_SHARED_EVENT); - } - - static String ^ ShowAdvancedPasteSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_ADVANCED_PASTE_SHARED_EVENT); - } - - static String ^ AdvancedPasteMarkdownEvent() { - return gcnew String(CommonSharedConstants::ADVANCED_PASTE_MARKDOWN_EVENT); - } - - static String ^ AdvancedPasteJsonEvent() { - return gcnew String(CommonSharedConstants::ADVANCED_PASTE_JSON_EVENT); - } - - static String ^ ShowPowerOCRSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_POWEROCR_SHARED_EVENT); - } - - static String ^ MouseJumpShowPreviewEvent() { - return gcnew String(CommonSharedConstants::MOUSE_JUMP_SHOW_PREVIEW_EVENT); - } - - static String ^ AwakeExitEvent() { - return gcnew String(CommonSharedConstants::AWAKE_EXIT_EVENT); - } - - static String^ ShowPeekEvent() { - return gcnew String(CommonSharedConstants::SHOW_PEEK_SHARED_EVENT); - } - - static String ^ PowerAccentExitEvent() { - return gcnew String(CommonSharedConstants::POWERACCENT_EXIT_EVENT); - } - - static String ^ ShortcutGuideTriggerEvent() { - return gcnew String(CommonSharedConstants::SHORTCUT_GUIDE_TRIGGER_EVENT); - } - - static String ^ RegistryPreviewTriggerEvent() { - return gcnew String(CommonSharedConstants::REGISTRY_PREVIEW_TRIGGER_EVENT); - } - - static String ^ MeasureToolTriggerEvent() { - return gcnew String(CommonSharedConstants::MEASURE_TOOL_TRIGGER_EVENT); - } - - static String ^ GcodePreviewResizeEvent() { - return gcnew String(CommonSharedConstants::GCODE_PREVIEW_RESIZE_EVENT); - } - - static String ^ QoiPreviewResizeEvent() { - return gcnew String(CommonSharedConstants::QOI_PREVIEW_RESIZE_EVENT); - } - - static String ^ DevFilesPreviewResizeEvent() { - return gcnew String(CommonSharedConstants::DEV_FILES_PREVIEW_RESIZE_EVENT); - } - - static String ^ MarkdownPreviewResizeEvent() { - return gcnew String(CommonSharedConstants::MARKDOWN_PREVIEW_RESIZE_EVENT); - } - - static String ^ PdfPreviewResizeEvent() { - return gcnew String(CommonSharedConstants::PDF_PREVIEW_RESIZE_EVENT); - } - - static String ^ SvgPreviewResizeEvent() { - return gcnew String(CommonSharedConstants::SVG_PREVIEW_RESIZE_EVENT); - } - - static String ^ ShowHostsSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_HOSTS_EVENT); - } - - static String ^ ShowHostsAdminSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT); - } - - static String ^ CropAndLockThumbnailEvent() { - return gcnew String(CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT); - } - - static String ^ CropAndLockReparentEvent() { - return gcnew String(CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT); - } - - static String ^ ShowEnvironmentVariablesSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_EVENT); - } - - static String ^ ShowEnvironmentVariablesAdminSharedEvent() { - return gcnew String(CommonSharedConstants::SHOW_ENVIRONMENT_VARIABLES_ADMIN_EVENT); - } - }; -} diff --git a/src/common/interop/pch.cpp b/src/common/interop/pch.cpp new file mode 100644 index 000000000000..bcb5590be1b3 --- /dev/null +++ b/src/common/interop/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/src/common/interop/pch.h b/src/common/interop/pch.h index 2f415a620ed8..0934324c057c 100644 --- a/src/common/interop/pch.h +++ b/src/common/interop/pch.h @@ -3,13 +3,12 @@ // This also affects IntelliSense performance, including code completion and many code browsing features. // However, files listed here are ALL re-compiled if any one of them is updated between builds. // Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - +#pragma once #define WIN32_LEAN_AND_MEAN // add headers that you want to pre-compile here +#include +#include +#include +#include #include #include - -#endif //PCH_H diff --git a/src/common/interop/two_way_pipe_message_ipc.h b/src/common/interop/two_way_pipe_message_ipc.h index 18c4b236b996..3844c835c43b 100644 --- a/src/common/interop/two_way_pipe_message_ipc.h +++ b/src/common/interop/two_way_pipe_message_ipc.h @@ -1,8 +1,9 @@ #pragma once +#include class TwoWayPipeMessageIPC { public: - typedef void (*callback_function)(const std::wstring&); + typedef std::functioncallback_function; TwoWayPipeMessageIPC( std::wstring _input_pipe_name, std::wstring _output_pipe_name, diff --git a/src/dsc/PowerToys.Settings.DSC.Schema.Generator/DSCGeneration.cs b/src/dsc/PowerToys.Settings.DSC.Schema.Generator/DSCGeneration.cs index 64ddf9e00c73..f0fef8bd29f5 100644 --- a/src/dsc/PowerToys.Settings.DSC.Schema.Generator/DSCGeneration.cs +++ b/src/dsc/PowerToys.Settings.DSC.Schema.Generator/DSCGeneration.cs @@ -220,7 +220,7 @@ public static string EmitModuleFileContents(SettingsStructure[] moduleSettings, } var enumsBlock = string.Join(DoubleNewLine, enumsToEmit.Select(EmitEnumDefinition)); - var version = interop.CommonManaged.GetProductVersion().Replace("v", string.Empty); + var version = PowerToys.Interop.CommonManaged.GetProductVersion().Replace("v", string.Empty); var outputResult = string.Empty; outputResult += $$""" @@ -393,7 +393,7 @@ [void] Set() { public static string EmitManifestFileContents() { - var version = interop.CommonManaged.GetProductVersion().Replace("v", string.Empty) + ".0"; + var version = PowerToys.Interop.CommonManaged.GetProductVersion().Replace("v", string.Empty) + ".0"; var generatedDate = DateTime.Now.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture); return $$""" diff --git a/src/dsc/PowerToys.Settings.DSC.Schema.Generator/PowerToys.Settings.DSC.Schema.Generator.csproj b/src/dsc/PowerToys.Settings.DSC.Schema.Generator/PowerToys.Settings.DSC.Schema.Generator.csproj index 0b6ad0cf8588..f208559a2f5f 100644 --- a/src/dsc/PowerToys.Settings.DSC.Schema.Generator/PowerToys.Settings.DSC.Schema.Generator.csproj +++ b/src/dsc/PowerToys.Settings.DSC.Schema.Generator/PowerToys.Settings.DSC.Schema.Generator.csproj @@ -5,7 +5,7 @@ Project="$(SolutionDir)src\Common.SelfContained.props" /> Exe - net8.0-windows + net8.0-windows10.0.20348.0 PowerToys.Settings.DSC.Schema app.manifest win-x64;win-arm64 @@ -36,6 +36,9 @@ $(OutDir) false + + + diff --git a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs index dee81f7ffe05..c0224a0c55aa 100644 --- a/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs +++ b/src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs @@ -88,9 +88,9 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar } } - NativeEventWaiter.WaitForEventLoop(interop.Constants.ShowAdvancedPasteSharedEvent(), OnAdvancedPasteHotkey); - NativeEventWaiter.WaitForEventLoop(interop.Constants.AdvancedPasteMarkdownEvent(), OnAdvancedPasteMarkdownHotkey); - NativeEventWaiter.WaitForEventLoop(interop.Constants.AdvancedPasteJsonEvent(), OnAdvancedPasteJsonHotkey); + NativeEventWaiter.WaitForEventLoop(PowerToys.Interop.Constants.ShowAdvancedPasteSharedEvent(), OnAdvancedPasteHotkey); + NativeEventWaiter.WaitForEventLoop(PowerToys.Interop.Constants.AdvancedPasteMarkdownEvent(), OnAdvancedPasteMarkdownHotkey); + NativeEventWaiter.WaitForEventLoop(PowerToys.Interop.Constants.AdvancedPasteJsonEvent(), OnAdvancedPasteJsonHotkey); } private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmith.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmith.cpp index 69f1ae7bed32..069a95bd3797 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmith.cpp +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmith.cpp @@ -10,7 +10,7 @@ static bool is_directory(const std::wstring path) } // C++20 method -static bool starts_with(std::wstring_view whole, std::wstring_view part) +static constexpr bool starts_with(std::wstring_view whole, std::wstring_view part) { return whole.size() >= part.size() && whole.substr(0, part.size()) == part; } @@ -121,7 +121,7 @@ std::wstring pid_to_full_path(DWORD pid) std::wstring result(LongMaxPathSize, L'\0'); // Returns zero on failure, so it's okay to resize to zero. - auto length = GetModuleFileNameExW(process, NULL, result.data(), (DWORD)result.size()); + auto length = GetModuleFileNameExW(process, NULL, result.data(), static_cast(result.size())); result.resize(length); CloseHandle(process); diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj index f645de558ff3..8d33e3f543fe 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj @@ -1,22 +1,15 @@ + Debug ARM64 - - Debug - Win32 - Release ARM64 - - Release - Win32 - Debug x64 @@ -30,174 +23,96 @@ 16.0 Win32Proj {c604b37e-9d0e-4484-8778-e8b31b0e1b3a} - FileLocksmithLibInterop - net8.0-windows + PowerToys.FileLocksmithLib.Interop + PowerToys.FileLocksmithLib.Interop + net8.0-windows10.0.20348.0 ..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\ PowerToys.FileLocksmithLib.Interop - - DynamicLibrary - true - v143 - Unicode - NetCore - - - DynamicLibrary - false - v143 - true - Unicode - NetCore - - - DynamicLibrary - true - v143 - Unicode - NetCore - - - DynamicLibrary - true - v143 - Unicode - NetCore - - - DynamicLibrary - false - v143 - true - Unicode - NetCore - - + DynamicLibrary - false v143 - true Unicode - NetCore + false - - true - - - - - - - - - - - - - - - - - - - - - - - - - - + - Level3 - true - _DEBUG;FILELOCKSMITHLIBINTEROP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NetCore - stdcpp17 + _DEBUG;%(PreprocessorDefinitions) MultiThreadedDebugDLL - /Zc:twoPhase- + true + true - - Windows - true - false - - + - Level3 - true - _DEBUG;FILELOCKSMITHLIBINTEROP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NetCore - stdcpp17 - MultiThreadedDebugDLL - /Zc:twoPhase- - - - Windows - true - false - - - - - Level3 + NDEBUG;%(PreprocessorDefinitions) true true - true - NDEBUG;FILELOCKSMITHLIBINTEROP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NetCore - stdcpp17 - /Zc:twoPhase- MultiThreadedDLL + false + true + false - Windows true true - true - false - + Level3 - true - true true - NDEBUG;FILELOCKSMITHLIBINTEROP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + FILELOCKSMITHLIBINTEROP_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - NetCore - stdcpp17 - /Zc:twoPhase- - MultiThreadedDLL + %(AdditionalOptions) /bigobj /Zc:twoPhase- + .;%(AdditionalIncludeDirectories) Windows - true - true true false + PowerToys.FileLocksmithLibInterop.def + + true + + + + + + + + + + - + + NativeMethods.idl + Create + + ProcessResult.idl + + + + NativeMethods.idl + + + ProcessResult.idl + @@ -208,7 +123,23 @@ + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj.filters b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj.filters index 14ec0e55f073..b23ee3e58c5a 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj.filters +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/FileLocksmithLibInterop.vcxproj.filters @@ -15,9 +15,6 @@ - - Source Files - Source Files @@ -30,6 +27,12 @@ Source Files + + Source Files + + + Source Files + @@ -47,10 +50,27 @@ Header Files + + Header Files + + + Header Files + Resource Files + + + + + + Source Files + + + Source Files + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.cpp new file mode 100644 index 000000000000..55875626e88c --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.cpp @@ -0,0 +1,208 @@ +#include "pch.h" +#include "NativeMethods.h" +#include "FileLocksmith.h" +#include "../FileLocksmithLib/Constants.h" + +namespace winrt::PowerToys::FileLocksmithLib::Interop::implementation +{ + +#pragma region HelperMethods + std::wstring executable_path() + { + return pid_to_full_path(GetCurrentProcessId()); + } + std::wstring paths_file() + { + std::wstring path{ PowerToys::Interop::Constants::AppDataPath() }; + path += L"\\"; + path += constants::nonlocalizable::PowerToyName; + path += L"\\"; + path += constants::nonlocalizable::LastRunPath; + return path; + } + +#pragma endregion + + com_array NativeMethods::FindProcessesRecursive(array_view paths) + { + std::vector paths_cpp{ paths.begin(), paths.end() }; + + auto result_cpp = find_processes_recursive(paths_cpp); + const auto result_size = static_cast(result_cpp.size()); + + std::vector result; + + if (result_size == 0) + { + return com_array(); + } + + for (int i = 0; i < result_size; i++) + { + result.push_back(ProcessResult + { + hstring { result_cpp[i].name }, + result_cpp[i].pid, + hstring{ result_cpp[i].user }, + winrt::com_array + { + result_cpp[i].files.begin(), result_cpp[i].files.end() + } + }); + } + + return com_array{ result.begin(), result.end() }; + } + + hstring NativeMethods::PidToFullPath(uint32_t pid) + { + return hstring{ pid_to_full_path(pid) }; + } + + com_array NativeMethods::ReadPathsFromFile() + { + std::ifstream stream(paths_file()); + + std::vector result_cpp; + std::wstring line; + + bool finished = false; + + while (!finished) + { + WCHAR ch{}; + // We have to read data like this + if (!stream.read(reinterpret_cast(&ch), 2)) + { + finished = true; + } + else if (ch == L'\n') + { + if (line.empty()) + { + finished = true; + } + else + { + result_cpp.push_back(line); + line = {}; + } + } + else + { + line += ch; + } + } + return com_array{ result_cpp.begin(), result_cpp.end() }; + } + + bool NativeMethods::StartAsElevated(array_view paths) + { + std::ofstream stream(paths_file()); + const WCHAR newline = L'\n'; + + for (uint32_t i = 0; i < paths.size(); i++) + { + std::wstring path_cpp{ paths[i] }; + stream.write(reinterpret_cast(path_cpp.c_str()), path_cpp.size() * sizeof(WCHAR)); + stream.write(reinterpret_cast(&newline), sizeof(WCHAR)); + } + + stream.write(reinterpret_cast(&newline), sizeof(WCHAR)); + + if (!stream) + { + return false; + } + + stream.close(); + + auto exec_path = executable_path(); + + SHELLEXECUTEINFOW exec_info{}; + exec_info.cbSize = sizeof(exec_info); + exec_info.fMask = SEE_MASK_NOCLOSEPROCESS; + exec_info.hwnd = NULL; + exec_info.lpVerb = L"runas"; + exec_info.lpFile = exec_path.c_str(); + exec_info.lpParameters = L"--elevated"; + exec_info.lpDirectory = NULL; + exec_info.nShow = SW_SHOW; + exec_info.hInstApp = NULL; + + if (ShellExecuteExW(&exec_info)) + { + CloseHandle(exec_info.hProcess); + return true; + } + + return false; + } + + /* Adapted from "https://learn.microsoft.com/windows/win32/secauthz/enabling-and-disabling-privileges-in-c--" */ + bool NativeMethods::SetDebugPrivilege() + { + HANDLE hToken; + TOKEN_PRIVILEGES tp{}; + LUID luid; + + if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) != 0) + { + if (!LookupPrivilegeValue( + NULL, // lookup privilege on local system + SE_DEBUG_NAME, // privilege to lookup + &luid)) // receives LUID of privilege + { + CloseHandle(hToken); + return false; + } + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + if (!AdjustTokenPrivileges( + hToken, + FALSE, + &tp, + sizeof(TOKEN_PRIVILEGES), + NULL, + NULL)) + { + CloseHandle(hToken); + return false; + } + + if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) + { + CloseHandle(hToken); + return false; + } + + CloseHandle(hToken); + return true; + } + return false; + } + + // adapted from common/utils/elevation.h. No need to bring all dependencies to this project, though. + // TODO: Make elevation.h lighter so that this function can be used without bringing dependencies like spdlog in. + bool NativeMethods::IsProcessElevated() + { + HANDLE token = nullptr; + bool elevated = false; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) + { + TOKEN_ELEVATION elevation{}; + DWORD size; + if (GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &size)) + { + elevated = (elevation.TokenIsElevated != 0); + } + } + if (token) + { + CloseHandle(token); + } + return elevated; + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.h b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.h new file mode 100644 index 000000000000..9446b2160059 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.h @@ -0,0 +1,23 @@ +#pragma once +#include "NativeMethods.g.h" + +namespace winrt::PowerToys::FileLocksmithLib::Interop::implementation +{ + struct NativeMethods : NativeMethodsT + { + NativeMethods() = default; + + static com_array FindProcessesRecursive(array_view paths); + static hstring PidToFullPath(uint32_t pid); + static com_array ReadPathsFromFile(); + static bool StartAsElevated(array_view paths); + static bool SetDebugPrivilege(); + static bool IsProcessElevated(); + }; +} +namespace winrt::PowerToys::FileLocksmithLib::Interop::factory_implementation +{ + struct NativeMethods : NativeMethodsT + { + }; +} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.idl b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.idl new file mode 100644 index 000000000000..e9efc9020e7c --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NativeMethods.idl @@ -0,0 +1,19 @@ +import "ProcessResult.idl"; + +namespace PowerToys +{ + namespace FileLocksmithLib + { + namespace Interop + { + [default_interface] static runtimeclass NativeMethods { + static PowerToys.FileLocksmithLib.Interop.ProcessResult[] FindProcessesRecursive(String[] paths); + static String PidToFullPath(UInt32 pid); + static String[] ReadPathsFromFile(); + static Boolean StartAsElevated(String[] paths); + static Boolean SetDebugPrivilege(); + static Boolean IsProcessElevated(); + } + } + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllBase.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllBase.cpp index 571ea153bcc5..11eca201878c 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllBase.cpp +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllBase.cpp @@ -10,19 +10,19 @@ Ntdll::Ntdll() throw std::runtime_error{ "GetModuleHandleW returned null" }; } - m_NtQuerySystemInformation = (NtQuerySystemInformation_t)GetProcAddress(m_module, "NtQuerySystemInformation"); + m_NtQuerySystemInformation = reinterpret_cast(GetProcAddress(m_module, "NtQuerySystemInformation")); if (m_NtQuerySystemInformation == 0) { throw std::runtime_error{ "GetProcAddress returned null for NtQuerySystemInformation" }; } - m_NtDuplicateObject = (NtDuplicateObject_t)GetProcAddress(m_module, "NtDuplicateObject"); + m_NtDuplicateObject = reinterpret_cast(GetProcAddress(m_module, "NtDuplicateObject")); if (m_NtDuplicateObject == 0) { throw std::runtime_error{ "GetProcAddress returned null for NtDuplicateObject" }; } - m_NtQueryObject = (NtQueryObject_t)GetProcAddress(m_module, "NtQueryObject"); + m_NtQueryObject = reinterpret_cast(GetProcAddress(m_module, "NtQueryObject")); if (m_NtQueryObject == 0) { throw std::runtime_error{ "GetProcAddress returned null for NtQueryObject" }; diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp index f731cfbee136..e95cd161247f 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp @@ -35,7 +35,7 @@ namespace return long_filename; } - return { buffer, (UINT)lstrlenW(buffer) }; + return { buffer, static_cast(lstrlenW(buffer)) }; } constexpr size_t DefaultModulesResultSize = 512; @@ -94,7 +94,7 @@ NtdllExtensions::MemoryLoopResult NtdllExtensions::NtQuerySystemInformationMemor while (result.memory.size() <= MaxResultBufferSize) { ULONG result_len; - result.status = NtQuerySystemInformation(SystemInformationClass, result.memory.data(), (ULONG)result.memory.size(), &result_len); + result.status = NtQuerySystemInformation(SystemInformationClass, result.memory.data(), static_cast(result.memory.size()), &result_len); if (result.status == STATUS_INFO_LENGTH_MISMATCH) { @@ -123,10 +123,10 @@ std::wstring NtdllExtensions::file_handle_to_kernel_name(HANDLE file_handle, std } ULONG return_length; - auto status = NtQueryObject(file_handle, ObjectNameInformation, buffer.data(), (ULONG)buffer.size(), &return_length); + auto status = NtQueryObject(file_handle, ObjectNameInformation, buffer.data(), static_cast(buffer.size()), &return_length); if (NT_SUCCESS(status)) { - auto object_name_info = (UNICODE_STRING*)buffer.data(); + auto object_name_info = reinterpret_cast(buffer.data()); return unicode_to_str(*object_name_info); } @@ -160,7 +160,7 @@ std::vector NtdllExtensions::handles() noexcept return {}; } - auto info_ptr = (SYSTEM_HANDLE_INFORMATION_EX*)get_info_result.memory.data(); + auto info_ptr = reinterpret_cast(get_info_result.memory.data()); std::map pid_to_handle; std::vector result; @@ -197,7 +197,7 @@ std::vector NtdllExtensions::handles() noexcept } else { - process_handle = OpenProcess(PROCESS_DUP_HANDLE, FALSE, (DWORD)pid); + process_handle = OpenProcess(PROCESS_DUP_HANDLE, FALSE, static_cast(pid)); if (!process_handle) { continue; @@ -215,7 +215,7 @@ std::vector NtdllExtensions::handles() noexcept // } HANDLE local_handle_copy; - auto dh_result = DuplicateHandle(process_handle, (HANDLE)handle_info->HandleValue, GetCurrentProcess(), &local_handle_copy, 0, 0, DUPLICATE_SAME_ACCESS); + auto dh_result = DuplicateHandle(process_handle, reinterpret_cast(handle_info->HandleValue), GetCurrentProcess(), &local_handle_copy, 0, 0, DUPLICATE_SAME_ACCESS); if (dh_result == 0) { // Ignore this handle. @@ -224,7 +224,7 @@ std::vector NtdllExtensions::handles() noexcept handle_copy = local_handle_copy; ULONG return_length; - auto status = NtQueryObject(handle_copy, ObjectTypeInformation, object_info_buffer.data(), (ULONG)object_info_buffer.size(), &return_length); + auto status = NtQueryObject(handle_copy, ObjectTypeInformation, object_info_buffer.data(), static_cast(object_info_buffer.size()), &return_length); if (NT_ERROR(status)) { // Ignore this handle. @@ -233,7 +233,7 @@ std::vector NtdllExtensions::handles() noexcept continue; } - auto object_type_info = (OBJECT_TYPE_INFORMATION*)object_info_buffer.data(); + auto object_type_info = reinterpret_cast(object_info_buffer.data()); auto type_name = unicode_to_str(object_type_info->Name); std::wstring file_name; @@ -317,7 +317,7 @@ std::wstring NtdllExtensions::pid_to_user(DWORD pid) std::vector token_buffer(token_size); GetTokenInformation(token, TokenUser, token_buffer.data(), token_size, &token_size); - TOKEN_USER* user_ptr = (TOKEN_USER*)token_buffer.data(); + TOKEN_USER* user_ptr = reinterpret_cast(token_buffer.data()); PSID psid = user_ptr->User.Sid; DWORD user_buf_size = 0; DWORD domain_buf_size = 0; @@ -350,15 +350,15 @@ std::vector NtdllExtensions::processes() noexcept } std::vector result; - auto info_ptr = (PSYSTEM_PROCESS_INFORMATION)get_info_result.memory.data(); + auto info_ptr = reinterpret_cast(get_info_result.memory.data()); while (info_ptr->NextEntryOffset) { - info_ptr = decltype(info_ptr)((LPBYTE)info_ptr + info_ptr->NextEntryOffset); + info_ptr = reinterpret_cast(reinterpret_cast(info_ptr) + info_ptr->NextEntryOffset); ProcessInfo item; item.name = unicode_to_str(info_ptr->ImageName); - item.pid = (DWORD)(uintptr_t)info_ptr->UniqueProcessId; + item.pid = static_cast(reinterpret_cast(info_ptr->UniqueProcessId)); item.modules = process_modules(item.pid); item.user = pid_to_user(item.pid); diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/PowerToys.FileLocksmithLibInterop.def b/src/modules/FileLocksmith/FileLocksmithLibInterop/PowerToys.FileLocksmithLibInterop.def new file mode 100644 index 000000000000..24e7c1235c39 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/PowerToys.FileLocksmithLibInterop.def @@ -0,0 +1,3 @@ +EXPORTS +DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE +DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.cpp new file mode 100644 index 000000000000..a5cfbe95d8b3 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.cpp @@ -0,0 +1,29 @@ +#include "pch.h" +#include "ProcessResult.h" + +namespace winrt::PowerToys::FileLocksmithLib::Interop::implementation +{ + ProcessResult::ProcessResult(hstring const& name, uint32_t pid, hstring const& user, array_view files) + { + _name = name; + _pid = pid; + _user = user; + _files = { files.begin(), files.end() }; + } + hstring ProcessResult::name() + { + return _name; + } + uint32_t ProcessResult::pid() + { + return _pid; + } + hstring ProcessResult::user() + { + return _user; + } + com_array ProcessResult::files() + { + return winrt::com_array{ _files.begin(), _files.end() }; + } +} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.h b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.h new file mode 100644 index 000000000000..28096f9f7d26 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.h @@ -0,0 +1,28 @@ +#pragma once +#include "ProcessResult.g.h" + +namespace winrt::PowerToys::FileLocksmithLib::Interop::implementation +{ + struct ProcessResult : ProcessResultT + { + ProcessResult() = default; + + ProcessResult(hstring const& name, uint32_t pid, hstring const& user, array_view files); + hstring name(); + uint32_t pid(); + hstring user(); + com_array files(); + + private: + hstring _name; + uint32_t _pid; + hstring _user; + com_array _files; + }; +} +namespace winrt::PowerToys::FileLocksmithLib::Interop::factory_implementation +{ + struct ProcessResult : ProcessResultT + { + }; +} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.idl b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.idl new file mode 100644 index 000000000000..ff229d4f0060 --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/ProcessResult.idl @@ -0,0 +1,16 @@ +namespace PowerToys +{ + namespace FileLocksmithLib + { + namespace Interop + { + [default_interface] runtimeclass ProcessResult { + ProcessResult(String name, UInt32 pid, String user, String[] files); + String name{ get; }; + UInt32 pid{ get; }; + String user{ get; }; + String[] files{ get; }; + }; + } + } +} \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/interop.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/interop.cpp deleted file mode 100644 index e208adafcf6f..000000000000 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/interop.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include "pch.h" - -#include "FileLocksmith.h" - -#include "../FileLocksmithLib/Constants.h" - -namespace FileLocksmith::Interop -{ - public ref struct ProcessResult - { - System::String^ name; - System::UInt32 pid; - System::String^ user; - array^ files; - }; - - System::String^ from_wstring_view(std::wstring_view str) - { - return gcnew System::String(str.data(), 0, static_cast(str.size())); - } - - std::wstring from_system_string(System::String^ str) - { - // TODO use some built-in method - auto chars = str->ToCharArray(); - - std::wstring result(chars->Length, 0); - for (int i = 0; i < chars->Length; i++) - { - result[i] = chars[i]; - } - - return result; - } - - std::wstring paths_file() - { -#pragma warning(suppress : 4691) // Weird warning about System::String from referenced library not being the one expected (?!) - std::wstring path = from_system_string(interop::Constants::AppDataPath()); - path += L"\\"; - path += constants::nonlocalizable::PowerToyName; - path += L"\\"; - path += constants::nonlocalizable::LastRunPath; - return path; - } - - std::wstring executable_path() - { - return pid_to_full_path(GetCurrentProcessId()); - } - - public ref struct NativeMethods - { - static array ^ FindProcessesRecursive(array^ paths) - { - const int n = paths->Length; - - std::vector paths_cpp(n); - for (int i = 0; i < n; i++) - { - paths_cpp[i] = from_system_string(paths[i]); - } - - auto result_cpp = find_processes_recursive(paths_cpp); - const auto result_size = static_cast(result_cpp.size()); - - auto result = gcnew array(result_size); - for (int i = 0; i < result_size; i++) - { - auto item = gcnew ProcessResult; - - item->name = from_wstring_view(result_cpp[i].name); - item->pid = result_cpp[i].pid; - item->user = from_wstring_view(result_cpp[i].user); - - const int n_files = static_cast(result_cpp[i].files.size()); - item->files = gcnew array(n_files); - for (int j = 0; j < n_files; j++) - { - item->files[j] = from_wstring_view(result_cpp[i].files[j]); - } - - result[i] = item; - } - - return result; - } - - static System::String^ PidToFullPath(System::UInt32 pid) - { - auto path_cpp = pid_to_full_path(pid); - return from_wstring_view(path_cpp); - } - - static array^ ReadPathsFromFile() - { - std::ifstream stream(paths_file()); - - std::vector result_cpp; - std::wstring line; - - bool finished = false; - - while (!finished) - { - WCHAR ch{}; - // We have to read data like this - if (!stream.read(reinterpret_cast(&ch), 2)) - { - finished = true; - } - else if (ch == L'\n') - { - if (line.empty()) - { - finished = true; - } - else - { - result_cpp.push_back(line); - line = {}; - } - } - else - { - line += ch; - } - } - - auto result = gcnew array(static_cast(result_cpp.size())); - for (int i = 0; i < result->Length; i++) - { - result[i] = from_wstring_view(result_cpp[i]); - } - - return result; - } - - static System::Boolean StartAsElevated(array ^ paths) - { - std::ofstream stream(paths_file()); - const WCHAR newline = L'\n'; - for (int i = 0; i < paths->Length; i++) - { - auto path_cpp = from_system_string(paths[i]); - stream.write(reinterpret_cast(path_cpp.c_str()), path_cpp.size() * sizeof(WCHAR)); - stream.write(reinterpret_cast(&newline), sizeof(WCHAR)); - } - - stream.write(reinterpret_cast(&newline), sizeof(WCHAR)); - - if (!stream) - { - return false; - } - - stream.close(); - - auto exec_path = executable_path(); - - SHELLEXECUTEINFOW exec_info{}; - exec_info.cbSize = sizeof(exec_info); - exec_info.fMask = SEE_MASK_NOCLOSEPROCESS; - exec_info.hwnd = NULL; - exec_info.lpVerb = L"runas"; - exec_info.lpFile = exec_path.c_str(); - exec_info.lpParameters = L"--elevated"; - exec_info.lpDirectory = NULL; - exec_info.nShow = SW_SHOW; - exec_info.hInstApp = NULL; - - if (ShellExecuteExW(&exec_info)) - { - CloseHandle(exec_info.hProcess); - return true; - } - - return false; - } - - /* Adapted from "https://learn.microsoft.com/windows/win32/secauthz/enabling-and-disabling-privileges-in-c--" */ - static System::Boolean SetDebugPrivilege() - { - HANDLE hToken; - TOKEN_PRIVILEGES tp{}; - LUID luid; - - if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) != 0) - { - if (!LookupPrivilegeValue( - NULL, // lookup privilege on local system - SE_DEBUG_NAME, // privilege to lookup - &luid)) // receives LUID of privilege - { - CloseHandle(hToken); - return false; - } - tp.PrivilegeCount = 1; - tp.Privileges[0].Luid = luid; - tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - - if (!AdjustTokenPrivileges( - hToken, - FALSE, - &tp, - sizeof(TOKEN_PRIVILEGES), - (PTOKEN_PRIVILEGES)NULL, - (PDWORD)NULL)) - { - CloseHandle(hToken); - return false; - } - - if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) - { - CloseHandle(hToken); - return false; - } - - CloseHandle(hToken); - return true; - } - return false; - } - - // adapted from common/utils/elevation.h. No need to bring all dependencies to this project, though. - // TODO: Make elevation.h lighter so that this function can be used without bringing dependencies like spdlog in. - static System::Boolean IsProcessElevated() - { - HANDLE token = nullptr; - bool elevated = false; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) - { - TOKEN_ELEVATION elevation{}; - DWORD size; - if (GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &size)) - { - elevated = (elevation.TokenIsElevated != 0); - } - } - if (token) - { - CloseHandle(token); - } - return elevated; - } - }; -} diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/packages.config b/src/modules/FileLocksmith/FileLocksmithLibInterop/packages.config new file mode 100644 index 000000000000..09bfc449e21c --- /dev/null +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/pch.h b/src/modules/FileLocksmith/FileLocksmithLibInterop/pch.h index 5bfe0c9082cd..f2449b1578db 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/pch.h +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/pch.h @@ -17,3 +17,5 @@ #include #include #include + +#include diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs index 47e4e97ebf1a..43bf8c9a5901 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileCountConverter.cs @@ -3,8 +3,8 @@ // See the LICENSE file in the project root for more information. using System; -using FileLocksmith.Interop; using Microsoft.UI.Xaml.Data; +using PowerToys.FileLocksmithLib.Interop; namespace PowerToys.FileLocksmithUI.Converters { diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs index 58abd64fb78b..fcde399f4ae9 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/FileListToDescriptionConverter.cs @@ -4,8 +4,8 @@ using System; using System.IO; -using FileLocksmith.Interop; using Microsoft.UI.Xaml.Data; +using PowerToys.FileLocksmithLib.Interop; namespace PowerToys.FileLocksmithUI.Converters { diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs index 20f724e26187..c5b03a7d2b85 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/PidToIconConverter.cs @@ -15,7 +15,7 @@ public sealed class PidToIconConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { - var y = FileLocksmith.Interop.NativeMethods.PidToFullPath((uint)value); + var y = PowerToys.FileLocksmithLib.Interop.NativeMethods.PidToFullPath((uint)value); Icon icon = null; if (!string.IsNullOrEmpty(y)) diff --git a/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs b/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs index d14f4441178a..85b988dbe349 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/Converters/UserToSystemWarningVisibilityConverter.cs @@ -4,9 +4,9 @@ using System; using System.Globalization; -using FileLocksmith.Interop; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Data; +using PowerToys.FileLocksmithLib.Interop; namespace PowerToys.FileLocksmithUI.Converters { diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithUI.csproj b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithUI.csproj index 2f244cc72d46..9b8e0d6e9928 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithUI.csproj +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithUI.csproj @@ -53,7 +53,7 @@ - PowerToys.GPOWrapper + PowerToys.GPOWrapper;PowerToys.FileLocksmithLib.Interop $(OutDir) false diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs index 63d2c27c20f8..6aefd101deba 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/App.xaml.cs @@ -43,11 +43,11 @@ protected override void OnLaunched(LaunchActivatedEventArgs args) return; } - bool isElevated = FileLocksmith.Interop.NativeMethods.IsProcessElevated(); + bool isElevated = PowerToys.FileLocksmithLib.Interop.NativeMethods.IsProcessElevated(); if (isElevated) { - if (!FileLocksmith.Interop.NativeMethods.SetDebugPrivilege()) + if (!PowerToys.FileLocksmithLib.Interop.NativeMethods.SetDebugPrivilege()) { Logger.LogWarning("Couldn't set debug privileges to see system processes."); } diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml index 472318a93a65..21561991c5c2 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml @@ -6,7 +6,7 @@ xmlns:core="using:Microsoft.Xaml.Interactions.Core" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:interactivity="using:Microsoft.Xaml.Interactivity" - xmlns:interop="using:FileLocksmith.Interop" + xmlns:interop="using:PowerToys.FileLocksmithLib.Interop" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls" xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters" diff --git a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs index a1bab74f4269..227654d5897f 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/FileLocksmithXAML/Views/MainPage.xaml.cs @@ -3,9 +3,9 @@ // See the LICENSE file in the project root for more information. using System; -using FileLocksmith.Interop; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using PowerToys.FileLocksmithLib.Interop; using PowerToys.FileLocksmithUI.ViewModels; namespace PowerToys.FileLocksmithUI.Views diff --git a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs index d473a05c5803..856af731fff6 100644 --- a/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs +++ b/src/modules/FileLocksmith/FileLocksmithUI/ViewModels/MainViewModel.cs @@ -11,8 +11,8 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using FileLocksmith.Interop; using ManagedCommon; +using PowerToys.FileLocksmithLib.Interop; namespace PowerToys.FileLocksmithUI.ViewModels { @@ -95,10 +95,14 @@ private async Task LoadProcessesAsync() _cancelProcessWatching = new CancellationTokenSource(); - foreach (ProcessResult p in await FindProcesses(paths)) + var processes_found = await FindProcesses(paths); + if (processes_found is not null) { - Processes.Add(p); - WatchProcess(p, _cancelProcessWatching.Token); + foreach (ProcessResult p in processes_found) + { + Processes.Add(p); + WatchProcess(p, _cancelProcessWatching.Token); + } } IsLoading = false; @@ -109,7 +113,7 @@ private async Task> FindProcesses(string[] paths) var results = new List(); await Task.Run(() => { - results = NativeMethods.FindProcessesRecursive(paths).ToList(); + results = NativeMethods.FindProcessesRecursive(paths)?.ToList(); }); return results; } diff --git a/src/modules/MouseUtils/MouseJumpUI/Program.cs b/src/modules/MouseUtils/MouseJumpUI/Program.cs index d70ebfa45435..eed055d2f5df 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Program.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Program.cs @@ -10,10 +10,10 @@ using System.Windows.Forms; using System.Windows.Threading; using Common.UI; -using interop; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Library; using MouseJumpUI.Helpers; +using PowerToys.Interop; namespace MouseJumpUI; diff --git a/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs b/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs index e0cf0a7ac546..41686c4faf76 100644 --- a/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs +++ b/src/modules/PowerOCR/PowerOCR/Keyboard/EventMonitor.cs @@ -3,8 +3,8 @@ // See the LICENSE file in the project root for more information. using Common.UI; -using interop; using PowerOCR.Utilities; +using PowerToys.Interop; namespace PowerOCR.Keyboard { diff --git a/src/modules/awake/Awake/Program.cs b/src/modules/awake/Awake/Program.cs index 8f36e7a14b36..229ad84efc60 100644 --- a/src/modules/awake/Awake/Program.cs +++ b/src/modules/awake/Awake/Program.cs @@ -181,7 +181,7 @@ private static void HandleCommandLineArguments(bool usePtConfig, bool displayOn, TrayHelper.InitializeTray(Core.Constants.FullAppName, _defaultAwakeIcon); - var eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset, interop.Constants.AwakeExitEvent()); + var eventHandle = new EventWaitHandle(false, EventResetMode.ManualReset, PowerToys.Interop.Constants.AwakeExitEvent()); new Thread(() => { WaitHandle.WaitAny([eventHandle]); diff --git a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs index 957f813aaea7..0a814e7da97f 100644 --- a/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs +++ b/src/modules/colorPicker/ColorPickerUI/ViewModels/MainViewModel.cs @@ -14,8 +14,8 @@ using ColorPicker.Settings; using ColorPicker.ViewModelContracts; using Common.UI; -using interop; using ManagedCommon; +using PowerToys.Interop; namespace ColorPicker.ViewModels { diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs index d0fa03ea09d4..57dda038d5ca 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/App.xaml.cs @@ -145,7 +145,7 @@ private void OnExit(object sender, ExitEventArgs e) private void App_WaitExit() { NativeEventWaiter.WaitForEventLoop( - interop.Constants.FZEExitEvent(), + PowerToys.Interop.Constants.FZEExitEvent(), () => { Logger.LogInfo("Exit event triggered"); diff --git a/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj b/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj index bc400224279b..28a265401ad4 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj +++ b/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj @@ -150,6 +150,9 @@ Designer + + true + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest.csproj index 25a0594c6def..581ddc66f4dc 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest/Community.PowerToys.Run.Plugin.UnitConverter.UnitTest.csproj @@ -1,11 +1,12 @@ - net8.0-windows + net8.0-windows10.0.20348.0 false + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Community.PowerToys.Run.Plugin.UnitConverter.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Community.PowerToys.Run.Plugin.UnitConverter.csproj index 6cc95e6f4745..65398dd7657c 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Community.PowerToys.Run.Plugin.UnitConverter.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Community.PowerToys.Run.Plugin.UnitConverter.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {BB23A474-5058-4F75-8FA3-5FE3DE53CDF4} Properties Community.PowerToys.Run.Plugin.UnitConverter @@ -44,6 +44,7 @@ + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj index e39a91b07211..aec7b6b06292 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {4D971245-7A70-41D5-BAA0-DDB5684CAF51} Properties Community.PowerToys.Run.Plugin.VSCodeWorkspaces @@ -40,6 +40,7 @@ + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests.csproj index 29efb82e385e..55b01115e6fc 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests/Community.PowerToys.Run.Plugin.ValueGenerator.UnitTests.csproj @@ -1,12 +1,13 @@  - net8.0-windows + net8.0-windows10.0.20348.0 enable false + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Community.PowerToys.Run.Plugin.ValueGenerator.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Community.PowerToys.Run.Plugin.ValueGenerator.csproj index fda1abda75ec..5de2c70953fc 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Community.PowerToys.Run.Plugin.ValueGenerator.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Community.PowerToys.Run.Plugin.ValueGenerator.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {D095BE44-1F2E-463E-A494-121892A75EA2} true @@ -37,6 +37,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.WebSearch/Community.PowerToys.Run.Plugin.WebSearch.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.WebSearch/Community.PowerToys.Run.Plugin.WebSearch.csproj index 701cabbe3560..5c3cf165a8fd 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.WebSearch/Community.PowerToys.Run.Plugin.WebSearch.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.WebSearch/Community.PowerToys.Run.Plugin.WebSearch.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {9F94B303-5E21-4364-9362-64426F8DB932} Properties Community.PowerToys.Run.Plugin.WebSearch @@ -38,6 +38,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/Microsoft.Plugin.Folder.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/Microsoft.Plugin.Folder.UnitTests.csproj index 2c5d5d67365a..1b033c0f5204 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/Microsoft.Plugin.Folder.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder.UnitTests/Microsoft.Plugin.Folder.UnitTests.csproj @@ -1,13 +1,14 @@ - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.Plugin.Folder.UnitTests true + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj index 1b905bd088a2..d23af055206a 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Microsoft.Plugin.Folder.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {787B8AA6-CA93-4C84-96FE-DF31110AD1C4} Properties Microsoft.Plugin.Folder @@ -53,6 +53,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Microsoft.Plugin.Indexer.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Microsoft.Plugin.Indexer.csproj index 23fbf5239c19..29bc8925df35 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Microsoft.Plugin.Indexer.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/Microsoft.Plugin.Indexer.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {F8B870EB-D5F5-45BA-9CF7-A5C459818820} Properties Microsoft.Plugin.Indexer @@ -29,6 +29,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Microsoft.Plugin.Program.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Microsoft.Plugin.Program.UnitTests.csproj index c5cc34c944fb..859541a127bd 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Microsoft.Plugin.Program.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program.UnitTests/Microsoft.Plugin.Program.UnitTests.csproj @@ -14,6 +14,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Microsoft.Plugin.Program.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Microsoft.Plugin.Program.csproj index 6de692895a5f..1d4ec99ff1b0 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Microsoft.Plugin.Program.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Microsoft.Plugin.Program.csproj @@ -47,6 +47,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Microsoft.Plugin.Shell.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Microsoft.Plugin.Shell.csproj index 030aaf9fea1c..2a49e7a7b780 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Microsoft.Plugin.Shell.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Microsoft.Plugin.Shell.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} Properties Microsoft.Plugin.Shell @@ -41,6 +41,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri.UnitTests/Microsoft.Plugin.Uri.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri.UnitTests/Microsoft.Plugin.Uri.UnitTests.csproj index 584fdf33c210..8a24f715dfbb 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri.UnitTests/Microsoft.Plugin.Uri.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri.UnitTests/Microsoft.Plugin.Uri.UnitTests.csproj @@ -1,13 +1,14 @@  - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.Plugin.Uri.UnitTests true + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Microsoft.Plugin.Uri.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Microsoft.Plugin.Uri.csproj index 56161d9eea0b..74e04907a493 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Microsoft.Plugin.Uri.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Uri/Microsoft.Plugin.Uri.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {03276a39-d4e9-417c-8ffd-200b0ee5e871} Properties Microsoft.Plugin.Uri @@ -38,6 +38,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker.UnitTests/Microsoft.Plugin.WindowWalker.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker.UnitTests/Microsoft.Plugin.WindowWalker.UnitTests.csproj index 7df803696644..2e712bd3167e 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker.UnitTests/Microsoft.Plugin.WindowWalker.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker.UnitTests/Microsoft.Plugin.WindowWalker.UnitTests.csproj @@ -1,12 +1,13 @@  - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.Plugin.WindowWalker.UnitTests + diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Microsoft.Plugin.WindowWalker.csproj b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Microsoft.Plugin.WindowWalker.csproj index 585c8991710e..3f28cc678a29 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Microsoft.Plugin.WindowWalker.csproj +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Microsoft.Plugin.WindowWalker.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {74F1B9ED-F59C-4FE7-B473-7B453E30837E} Properties Microsoft.Plugin.WindowWalker @@ -44,6 +44,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest.csproj index 39e08c5a2eef..b23141086cc3 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest.csproj @@ -1,13 +1,14 @@ - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests true + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Microsoft.PowerToys.Run.Plugin.Calculator.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Microsoft.PowerToys.Run.Plugin.Calculator.csproj index d513ee0d7baf..e7e1cfb07315 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Microsoft.PowerToys.Run.Plugin.Calculator.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Microsoft.PowerToys.Run.Plugin.Calculator.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {59BD9891-3837-438A-958D-ADC7F91F6F7E} Properties Microsoft.PowerToys.Run.Plugin.Calculator @@ -44,6 +44,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote/Microsoft.PowerToys.Run.Plugin.OneNote.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote/Microsoft.PowerToys.Run.Plugin.OneNote.csproj index 053734f08c23..cc14944ab581 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote/Microsoft.PowerToys.Run.Plugin.OneNote.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.OneNote/Microsoft.PowerToys.Run.Plugin.OneNote.csproj @@ -1,7 +1,7 @@  - net8.0-windows + net8.0-windows10.0.20348.0 Microsoft.PowerToys.Run.Plugin.OneNote Microsoft.PowerToys.Run.Plugin.OneNote enable @@ -46,6 +46,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs index 74db0d004f44..cfd4b23a30fa 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs @@ -7,8 +7,8 @@ using System.Threading; using System.Windows.Input; using Common.UI; -using interop; using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; +using PowerToys.Interop; using Wox.Infrastructure; using Wox.Plugin; diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs index aaf1564404a8..6c0b36f00be0 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs @@ -7,11 +7,11 @@ using System.IO; using System.Linq; using System.Threading; -using interop; using Microsoft.PowerToys.Run.Plugin.PowerToys.Components; using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; using Microsoft.PowerToys.Settings.UI.Library; using PowerToys.GPOWrapper; +using PowerToys.Interop; using Wox.Plugin.Logger; namespace Microsoft.PowerToys.Run.Plugin.PowerToys diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.csproj index 930f03aee1cb..09217cb199e5 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry.UnitTest/Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.csproj @@ -1,7 +1,7 @@  - net8.0-windows + net8.0-windows10.0.20348.0 enable false @@ -20,6 +20,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Microsoft.PowerToys.Run.Plugin.Registry.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Microsoft.PowerToys.Run.Plugin.Registry.csproj index a4773450c59d..a3094e344534 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Microsoft.PowerToys.Run.Plugin.Registry.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Microsoft.PowerToys.Run.Plugin.Registry.csproj @@ -1,7 +1,7 @@  - net8.0-windows + net8.0-windows10.0.20348.0 Microsoft.PowerToys.Run.Plugin.Registry Microsoft.PowerToys.Run.Plugin.Registry @@ -35,6 +35,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Microsoft.PowerToys.Run.Plugin.Service.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Microsoft.PowerToys.Run.Plugin.Service.csproj index 8143e31c388e..a869935929b5 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Microsoft.PowerToys.Run.Plugin.Service.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Microsoft.PowerToys.Run.Plugin.Service.csproj @@ -3,7 +3,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 Microsoft.PowerToys.Run.Plugin.Service Microsoft.PowerToys.Run.Plugin.Service @@ -33,6 +33,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/Microsoft.PowerToys.Run.Plugin.System.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/Microsoft.PowerToys.Run.Plugin.System.UnitTests.csproj index c7ba6e32a415..5060f802e019 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/Microsoft.PowerToys.Run.Plugin.System.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/Microsoft.PowerToys.Run.Plugin.System.UnitTests.csproj @@ -1,12 +1,13 @@  - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.PowerToys.Run.Plugin.System.UnitTests + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj index cbd48fa4a887..603aa344ff34 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj @@ -3,7 +3,7 @@ Library - net8.0-windows + net8.0-windows10.0.20348.0 Properties Microsoft.PowerToys.Run.Plugin.System Microsoft.PowerToys.Run.Plugin.System @@ -34,6 +34,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj index e6f3b80f8c8b..ffb127023a85 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests.csproj @@ -1,12 +1,13 @@  - net8.0-windows + net8.0-windows10.0.20348.0 false Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Microsoft.PowerToys.Run.Plugin.TimeDate.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Microsoft.PowerToys.Run.Plugin.TimeDate.csproj index e44a8b68f5bf..09643d55d46a 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Microsoft.PowerToys.Run.Plugin.TimeDate.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Microsoft.PowerToys.Run.Plugin.TimeDate.csproj @@ -3,7 +3,7 @@ Library - net8.0-windows + net8.0-windows10.0.20348.0 Properties Microsoft.PowerToys.Run.Plugin.TimeDate Microsoft.PowerToys.Run.Plugin.TimeDate @@ -34,6 +34,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Microsoft.PowerToys.Run.Plugin.WindowsSettings.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Microsoft.PowerToys.Run.Plugin.WindowsSettings.csproj index 9aad8dc12118..306ef06ff365 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Microsoft.PowerToys.Run.Plugin.WindowsSettings.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Microsoft.PowerToys.Run.Plugin.WindowsSettings.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {5043CECE-E6A7-4867-9CBE-02D27D83747A} Properties Microsoft.PowerToys.Run.Plugin.WindowsSettings @@ -43,6 +43,7 @@ + runtime diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/Microsoft.Plugin.WindowsTerminal.UnitTests.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/Microsoft.Plugin.WindowsTerminal.UnitTests.csproj index 3187d4c42e67..7e670c0fb395 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/Microsoft.Plugin.WindowsTerminal.UnitTests.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/Microsoft.Plugin.WindowsTerminal.UnitTests.csproj @@ -9,6 +9,7 @@ + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.csproj index b37b27e7c1c7..8a85e64d2c95 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.csproj @@ -34,6 +34,7 @@ + runtime diff --git a/src/modules/launcher/PowerLauncher.Telemetry/PowerLauncher.Telemetry.csproj b/src/modules/launcher/PowerLauncher.Telemetry/PowerLauncher.Telemetry.csproj index d403fdd1113a..45ab7fdeb2c1 100644 --- a/src/modules/launcher/PowerLauncher.Telemetry/PowerLauncher.Telemetry.csproj +++ b/src/modules/launcher/PowerLauncher.Telemetry/PowerLauncher.Telemetry.csproj @@ -1,7 +1,7 @@  - net8.0-windows + net8.0-windows10.0.20348.0 PowerToys PowerLauncher Telemetry PowerToys.PowerLauncher.Telemetry diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 04c395d40d94..eeba1bd49f2e 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -9,13 +9,13 @@ using System.Text; using System.Threading; using System.Windows; -using interop; using ManagedCommon; using Microsoft.PowerLauncher.Telemetry; using Microsoft.PowerToys.Telemetry; using PowerLauncher.Helper; using PowerLauncher.Plugin; using PowerLauncher.ViewModel; +using PowerToys.Interop; using Wox; using Wox.Infrastructure; using Wox.Infrastructure.Image; diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index e402ed44f87e..82dd8f7b90b1 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -14,13 +14,13 @@ using System.Windows.Interop; using System.Windows.Media.Imaging; using Common.UI; -using interop; using Microsoft.PowerLauncher.Telemetry; using Microsoft.PowerToys.Telemetry; using PowerLauncher.Helper; using PowerLauncher.Plugin; using PowerLauncher.Telemetry.Events; using PowerLauncher.ViewModel; +using PowerToys.Interop; using Wox.Infrastructure.UserSettings; using Wox.Plugin; using Wox.Plugin.Interfaces; diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 034744c9e9c9..fa0683b28b09 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -17,13 +17,13 @@ using System.Windows.Interop; using System.Windows.Threading; using Common.UI; -using interop; using Mages.Core.Runtime.Converters; using Microsoft.PowerLauncher.Telemetry; using Microsoft.PowerToys.Telemetry; using PowerLauncher.Helper; using PowerLauncher.Plugin; using PowerLauncher.Storage; +using PowerToys.Interop; using Wox.Infrastructure; using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Storage; diff --git a/src/modules/launcher/Wox.Infrastructure/Wox.Infrastructure.csproj b/src/modules/launcher/Wox.Infrastructure/Wox.Infrastructure.csproj index 4defd7acb499..9fb68cd25229 100644 --- a/src/modules/launcher/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/src/modules/launcher/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3} Library true @@ -48,6 +48,7 @@ + diff --git a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj index 02dcf7169a4a..3cb310602e70 100644 --- a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj +++ b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj @@ -2,7 +2,7 @@ - net8.0-windows + net8.0-windows10.0.20348.0 {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} true Library @@ -48,6 +48,7 @@ + diff --git a/src/modules/peek/Peek.Common/Peek.Common.csproj b/src/modules/peek/Peek.Common/Peek.Common.csproj index f6a18306d62a..efd791af896d 100644 --- a/src/modules/peek/Peek.Common/Peek.Common.csproj +++ b/src/modules/peek/Peek.Common/Peek.Common.csproj @@ -22,6 +22,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/modules/peek/Peek.FilePreviewer/Peek.FilePreviewer.csproj b/src/modules/peek/Peek.FilePreviewer/Peek.FilePreviewer.csproj index a304d2442fb7..981f5b6e68a5 100644 --- a/src/modules/peek/Peek.FilePreviewer/Peek.FilePreviewer.csproj +++ b/src/modules/peek/Peek.FilePreviewer/Peek.FilePreviewer.csproj @@ -30,6 +30,7 @@ + diff --git a/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs b/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs index 0c0d78a7574b..7cf417520438 100644 --- a/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs +++ b/src/modules/peek/Peek.UI/PeekXAML/App.xaml.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using interop; using ManagedCommon; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -15,6 +14,7 @@ using Peek.UI.Native; using Peek.UI.Telemetry.Events; using Peek.UI.Views; +using PowerToys.Interop; namespace Peek.UI { diff --git a/src/modules/poweraccent/PowerAccent.UI/Program.cs b/src/modules/poweraccent/PowerAccent.UI/Program.cs index d45b7c601c3f..4a9d166eb71c 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Program.cs +++ b/src/modules/poweraccent/PowerAccent.UI/Program.cs @@ -7,8 +7,8 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; -using interop; using ManagedCommon; +using PowerToys.Interop; namespace PowerAccent.UI; diff --git a/src/modules/previewpane/GcodePreviewHandler/Program.cs b/src/modules/previewpane/GcodePreviewHandler/Program.cs index cddf09cee44c..f8ed9bf3fd81 100644 --- a/src/modules/previewpane/GcodePreviewHandler/Program.cs +++ b/src/modules/previewpane/GcodePreviewHandler/Program.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Gcode { diff --git a/src/modules/previewpane/MarkdownPreviewHandler/Program.cs b/src/modules/previewpane/MarkdownPreviewHandler/Program.cs index 3d5fe7c2076e..ab1f3cbfef4d 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/Program.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/Program.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Markdown { diff --git a/src/modules/previewpane/MonacoPreviewHandler/Program.cs b/src/modules/previewpane/MonacoPreviewHandler/Program.cs index fabb0ca7101e..ed3f7333860e 100644 --- a/src/modules/previewpane/MonacoPreviewHandler/Program.cs +++ b/src/modules/previewpane/MonacoPreviewHandler/Program.cs @@ -5,8 +5,8 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; using ManagedCommon; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Monaco { diff --git a/src/modules/previewpane/PdfPreviewHandler/Program.cs b/src/modules/previewpane/PdfPreviewHandler/Program.cs index 7c883b79891b..03aec970eabf 100644 --- a/src/modules/previewpane/PdfPreviewHandler/Program.cs +++ b/src/modules/previewpane/PdfPreviewHandler/Program.cs @@ -4,7 +4,7 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Pdf { diff --git a/src/modules/previewpane/QoiPreviewHandler/Program.cs b/src/modules/previewpane/QoiPreviewHandler/Program.cs index 469d0c3b2534..4de89d6e807f 100644 --- a/src/modules/previewpane/QoiPreviewHandler/Program.cs +++ b/src/modules/previewpane/QoiPreviewHandler/Program.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Qoi { diff --git a/src/modules/previewpane/SvgPreviewHandler/Program.cs b/src/modules/previewpane/SvgPreviewHandler/Program.cs index e46e9f784c4d..dac1098c30bc 100644 --- a/src/modules/previewpane/SvgPreviewHandler/Program.cs +++ b/src/modules/previewpane/SvgPreviewHandler/Program.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Windows.Threading; using Common.UI; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.PreviewHandler.Svg { diff --git a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/UnitTests-PreviewHandlerCommon.csproj b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/UnitTests-PreviewHandlerCommon.csproj index 2d4b8494e06c..53bc48826248 100644 --- a/src/modules/previewpane/UnitTests-PreviewHandlerCommon/UnitTests-PreviewHandlerCommon.csproj +++ b/src/modules/previewpane/UnitTests-PreviewHandlerCommon/UnitTests-PreviewHandlerCommon.csproj @@ -9,7 +9,7 @@ {748417CA-F17E-487F-9411-CAFB6D3F4877} PreviewHandlerCommonUnitTests - net8.0-windows + net8.0-windows10.0.20348.0 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages diff --git a/src/modules/previewpane/common/PreviewHandlerCommon.csproj b/src/modules/previewpane/common/PreviewHandlerCommon.csproj index d50f8f6c2806..745358ec083f 100644 --- a/src/modules/previewpane/common/PreviewHandlerCommon.csproj +++ b/src/modules/previewpane/common/PreviewHandlerCommon.csproj @@ -14,7 +14,7 @@ {AF2349B8-E5B6-4004-9502-687C1C7730B1} - net8.0-windows + net8.0-windows10.0.20348.0 PowerToys.PreviewHandlerCommon diff --git a/src/modules/registrypreview/RegistryPreview/RegistryPreview.csproj b/src/modules/registrypreview/RegistryPreview/RegistryPreview.csproj index fd8b78d51da8..b689aa779d7a 100644 --- a/src/modules/registrypreview/RegistryPreview/RegistryPreview.csproj +++ b/src/modules/registrypreview/RegistryPreview/RegistryPreview.csproj @@ -38,6 +38,7 @@ + diff --git a/src/modules/videoconference/VideoConferenceShared/MicrophoneDevice.cpp b/src/modules/videoconference/VideoConferenceShared/MicrophoneDevice.cpp index 83a077b56a1a..f8e6f00a80e3 100644 --- a/src/modules/videoconference/VideoConferenceShared/MicrophoneDevice.cpp +++ b/src/modules/videoconference/VideoConferenceShared/MicrophoneDevice.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "MicrophoneDevice.h" #include "Logging.h" diff --git a/src/modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.cpp b/src/modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.cpp index 3ec325dbdd40..ba710a0453dc 100644 --- a/src/modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.cpp +++ b/src/modules/videoconference/VideoConferenceShared/VideoCaptureDeviceList.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "VideoCaptureDeviceList.h" #include "Logging.h" #include "MediaFoundationAPIProvider.h" diff --git a/src/modules/videoconference/VideoConferenceShared/VideoConferenceShared.vcxproj b/src/modules/videoconference/VideoConferenceShared/VideoConferenceShared.vcxproj index c97bb89b9a8a..a888f9087712 100644 --- a/src/modules/videoconference/VideoConferenceShared/VideoConferenceShared.vcxproj +++ b/src/modules/videoconference/VideoConferenceShared/VideoConferenceShared.vcxproj @@ -96,7 +96,7 @@ true MultiThreaded true - $(SolutionDir)\src\; + $(SolutionDir)\src\;%(AdditionalIncludeDirectories) ProgramDatabase @@ -123,6 +123,7 @@ + diff --git a/src/modules/videoconference/VideoConferenceShared/pch.h b/src/modules/videoconference/VideoConferenceShared/pch.h new file mode 100644 index 000000000000..128bb3589fa9 --- /dev/null +++ b/src/modules/videoconference/VideoConferenceShared/pch.h @@ -0,0 +1,2 @@ +#pragma once +// Dummy file to allow compiling VideoCaptureDeviceList.h and MicrophoneDevice.h in this project, since it's also used in PowerToys.Interop.vcxproj, which has a pch. diff --git a/src/settings-ui/Settings.UI.Library/GeneralSettings.cs b/src/settings-ui/Settings.UI.Library/GeneralSettings.cs index 79e18a07b584..6873b1962a0f 100644 --- a/src/settings-ui/Settings.UI.Library/GeneralSettings.cs +++ b/src/settings-ui/Settings.UI.Library/GeneralSettings.cs @@ -104,7 +104,7 @@ public string ToJsonString() private static string DefaultPowertoysVersion() { - return interop.CommonManaged.GetProductVersion(); + return global::PowerToys.Interop.CommonManaged.GetProductVersion(); } // This function is to implement the ISettingsConfig interface. diff --git a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs index d405d52d00c2..cc932b358457 100644 --- a/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs +++ b/src/settings-ui/Settings.UI.Library/HotkeySettingsControlHook.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using interop; +using PowerToys.Interop; namespace Microsoft.PowerToys.Settings.UI.Library { diff --git a/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj b/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj index d28cfa4bac2b..c1fdc1215a4d 100644 --- a/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj +++ b/src/settings-ui/Settings.UI.Library/Settings.UI.Library.csproj @@ -4,9 +4,8 @@ Condition="exists('$(SolutionDir)src\Common.SelfContained.props')" Project="$(SolutionDir)src\Common.SelfContained.props" /> - net8.0-windows win-x64;win-arm64 - net8.0-windows + net8.0-windows10.0.20348.0 PowerToys Settings UI Library PowerToys.Settings.UI.Lib @@ -24,6 +23,7 @@ + diff --git a/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs b/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs index af8aa34a4056..cace7f2288ea 100644 --- a/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs +++ b/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs @@ -96,7 +96,7 @@ public static string GetPowerToysInstallationFolder() return Directory.GetParent(settingsPath).FullName; } - private static readonly interop.LayoutMapManaged LayoutMap = new interop.LayoutMapManaged(); + private static readonly global::PowerToys.Interop.LayoutMapManaged LayoutMap = new global::PowerToys.Interop.LayoutMapManaged(); public static string GetKeyName(uint key) { @@ -110,7 +110,7 @@ public static uint GetKeyValue(string key) public static string GetProductVersion() { - return interop.CommonManaged.GetProductVersion(); + return global::PowerToys.Interop.CommonManaged.GetProductVersion(); } public static int CompareVersions(string version1, string version2) @@ -148,6 +148,6 @@ public static int CompareVersions(string version1, string version2) } } - public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH; + public static readonly uint VirtualKeyWindows = global::PowerToys.Interop.Constants.VK_WIN_BOTH; } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs index 263e0466f613..8d367853b925 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Text.Json; using System.Threading.Tasks; -using interop; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; @@ -18,6 +17,7 @@ using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Xaml; +using PowerToys.Interop; using Windows.UI.Popups; using WinRT.Interop; using WinUIEx; diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/AppsListPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/AppsListPage.xaml.cs index 6692ff6077a9..cc952772a989 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/AppsListPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/AppsListPage.xaml.cs @@ -5,13 +5,13 @@ using System.Collections.ObjectModel; using System.Threading; using global::Windows.System; -using interop; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.ViewModels; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; +using PowerToys.Interop; namespace Microsoft.PowerToys.Settings.UI.Flyout { diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs index 602a390dd414..4b4f5dc267a2 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Flyout/LaunchPage.xaml.cs @@ -4,7 +4,6 @@ using System; using System.Threading; using global::Windows.System; -using interop; using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Controls; using Microsoft.PowerToys.Settings.UI.Library; @@ -14,6 +13,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; +using PowerToys.Interop; using WinUIEx; namespace Microsoft.PowerToys.Settings.UI.Flyout diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs index 308aabb105f3..d02a2f8e1bd3 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeEnvironmentVariables.xaml.cs @@ -3,13 +3,13 @@ // See the LICENSE file in the project root for more information. using System.Threading; -using interop; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; +using PowerToys.Interop; namespace Microsoft.PowerToys.Settings.UI.OOBE.Views { diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs index 91b8160122d5..25dc69988992 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OOBE/Views/OobeHosts.xaml.cs @@ -3,13 +3,13 @@ // See the LICENSE file in the project root for more information. using System.Threading; -using interop; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; +using PowerToys.Interop; namespace Microsoft.PowerToys.Settings.UI.OOBE.Views { diff --git a/src/settings-ui/Settings.UI/SettingsXAML/OobeWindow.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/OobeWindow.xaml.cs index ff18d6591794..7fb66e711e8d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/OobeWindow.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/OobeWindow.xaml.cs @@ -3,13 +3,13 @@ // See the LICENSE file in the project root for more information. using System; -using interop; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.OOBE.Enums; using Microsoft.PowerToys.Settings.UI.OOBE.Views; using Microsoft.UI; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; +using PowerToys.Interop; using Windows.Graphics; using WinUIEx; using WinUIEx.Messaging; diff --git a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs index 124c67c89834..7a7960cff715 100644 --- a/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/EnvironmentVariablesViewModel.cs @@ -6,11 +6,11 @@ using System.Runtime.CompilerServices; using System.Threading; using global::PowerToys.GPOWrapper; -using interop; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using PowerToys.Interop; using Settings.UI.Library.Enumerations; namespace Microsoft.PowerToys.Settings.UI.ViewModels diff --git a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs index 09f090cea28d..235ae42bd615 100644 --- a/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs @@ -6,11 +6,11 @@ using System.Runtime.CompilerServices; using System.Threading; using global::PowerToys.GPOWrapper; -using interop; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; using Microsoft.PowerToys.Settings.UI.Library.Interfaces; using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands; +using PowerToys.Interop; using Settings.UI.Library.Enumerations; namespace Microsoft.PowerToys.Settings.UI.ViewModels diff --git a/src/settings-ui/Settings.UI/ViewModels/VideoConferenceViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/VideoConferenceViewModel.cs index 9dcda1e3c440..b3abc2a21580 100644 --- a/src/settings-ui/Settings.UI/ViewModels/VideoConferenceViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/VideoConferenceViewModel.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text.Json; @@ -58,8 +59,8 @@ public VideoConferenceViewModel( Settings = videoConferenceSettingsRepository.SettingsConfig; - CameraNames = interop.CommonManaged.GetAllVideoCaptureDeviceNames(); - MicrophoneNames = interop.CommonManaged.GetAllActiveMicrophoneDeviceNames(); + CameraNames = global::PowerToys.Interop.CommonManaged.GetAllVideoCaptureDeviceNames().ToList(); + MicrophoneNames = global::PowerToys.Interop.CommonManaged.GetAllActiveMicrophoneDeviceNames().ToList(); MicrophoneNames.Insert(0, "[All]"); var shouldSaveSettings = false;