mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-06 12:27:01 +01:00
Compare commits
24 Commits
feature/UI
...
shawn/reve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
788b59d843 | ||
|
|
713b11db82 | ||
|
|
a6caca3ba9 | ||
|
|
839104207e | ||
|
|
b433ebf432 | ||
|
|
2af8bf47f1 | ||
|
|
1020c5abae | ||
|
|
cc14fc3c89 | ||
|
|
66380cc1d3 | ||
|
|
59f23bded4 | ||
|
|
09c9eeb48e | ||
|
|
4737ec987e | ||
|
|
c83be3e74c | ||
|
|
5d9a1ad404 | ||
|
|
04bba95972 | ||
|
|
350b9b78fe | ||
|
|
c487638758 | ||
|
|
252dbb5853 | ||
|
|
655398e173 | ||
|
|
f7257bf1d1 | ||
|
|
bdedc02ea5 | ||
|
|
b2d7182dcd | ||
|
|
82e9d42e02 | ||
|
|
74d92df078 |
5
.github/actions/spell-check/expect.txt
vendored
5
.github/actions/spell-check/expect.txt
vendored
@@ -156,6 +156,7 @@ builttoroam
|
||||
BVal
|
||||
BValue
|
||||
byapp
|
||||
BYCOMMAND
|
||||
BYPOSITION
|
||||
CALCRECT
|
||||
CALG
|
||||
@@ -203,6 +204,7 @@ CLIPSIBLINGS
|
||||
closesocket
|
||||
clp
|
||||
CLSCTX
|
||||
CLSCTXLOCALSERVER
|
||||
clsids
|
||||
Clusion
|
||||
cmder
|
||||
@@ -825,6 +827,7 @@ LOCALDISPLAY
|
||||
localpackage
|
||||
LOCALSYSTEM
|
||||
LOCATIONCHANGE
|
||||
LOCKTYPE
|
||||
LOGFONT
|
||||
LOGFONTW
|
||||
logon
|
||||
@@ -1728,6 +1731,7 @@ trx
|
||||
tsa
|
||||
TSender
|
||||
TServer
|
||||
tskill
|
||||
tstoi
|
||||
TStr
|
||||
tweakme
|
||||
@@ -1961,6 +1965,7 @@ Wwanpp
|
||||
XAxis
|
||||
xclip
|
||||
xcopy
|
||||
XDeployment
|
||||
XDocument
|
||||
XElement
|
||||
xfd
|
||||
|
||||
@@ -102,7 +102,7 @@ jobs:
|
||||
${{ else }}:
|
||||
OutputBuildPlatform: ${{ platform }}
|
||||
variables:
|
||||
MakeAppxPath: 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86\MakeAppx.exe'
|
||||
MakeAppxPath: 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x86\MakeAppx.exe'
|
||||
# Azure DevOps abhors a vacuum
|
||||
# If these are blank, expansion will fail later on... which will result in direct substitution of the variable *names*
|
||||
# later on. We'll just... set them to a single space and if we need to, check IsNullOrWhiteSpace.
|
||||
@@ -335,6 +335,7 @@ jobs:
|
||||
/p:VCRTForwarders-IncludeDebugCRT=false
|
||||
/p:PowerToysRoot=$(Build.SourcesDirectory)
|
||||
/p:PublishProfile=InstallationPublishProfile.pubxml
|
||||
/p:TargetFramework=net9.0-windows10.0.26100.0
|
||||
/bl:$(LogOutputDirectory)\publish-${{ join('_',split(project, '/')) }}.binlog
|
||||
$(RestoreAdditionalProjectSourcesArg)
|
||||
platform: $(BuildPlatform)
|
||||
|
||||
@@ -60,4 +60,16 @@ stages:
|
||||
useLatestWinAppSDK: ${{ parameters.useLatestWinAppSDK }}
|
||||
${{ if eq(parameters.useLatestWinAppSDK, true) }}:
|
||||
winAppSDKVersionNumber: ${{ parameters.winAppSDKVersionNumber }}
|
||||
useExperimentalVersion: ${{ parameters.useExperimentalVersion }}
|
||||
useExperimentalVersion: ${{ parameters.useExperimentalVersion }}
|
||||
|
||||
- ${{ if and(eq(parameters.runTests, true), not(and(eq(platform, 'arm64'), eq(variables['System.PullRequest.IsFork'], true)))) }}:
|
||||
- stage: Test_${{ platform }}
|
||||
displayName: Test ${{ platform }}
|
||||
dependsOn:
|
||||
- Build_${{platform}}
|
||||
jobs:
|
||||
- template: job-test-project.yml
|
||||
parameters:
|
||||
platform: ${{ platform }}
|
||||
configuration: Release
|
||||
useLatestWebView2: ${{ parameters.useLatestWebView2 }}
|
||||
@@ -9,6 +9,7 @@
|
||||
"Microsoft.VisualStudio.Component.Windows10SDK.19041",
|
||||
"Microsoft.VisualStudio.Component.Windows10SDK.20348",
|
||||
"Microsoft.VisualStudio.Component.Windows10SDK.22621",
|
||||
"Microsoft.VisualStudio.Component.Windows10SDK.26100",
|
||||
"Microsoft.VisualStudio.ComponentGroup.UWP.VC",
|
||||
"Microsoft.VisualStudio.Component.UWP.VC.ARM64",
|
||||
"Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre",
|
||||
|
||||
@@ -96,8 +96,8 @@
|
||||
|
||||
<!-- Global props OverrideWindowsTargetPlatformVersion-->
|
||||
<PropertyGroup Label="Globals">
|
||||
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>10.0.22621.0</TargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>10.0.26100.0</TargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.19041.0</WindowsTargetPlatformMinVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@
|
||||
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="9.0.6" />
|
||||
<PackageVersion Include="Microsoft.WindowsPackageManager.ComInterop" Version="1.10.340" />
|
||||
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="9.0.6" />
|
||||
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.2.46-beta" />
|
||||
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.183" />
|
||||
<!-- CsWinRT version needs to be set to have a WinRT.Runtime.dll at the same version contained inside the NET SDK we're currently building on CI. -->
|
||||
<!--
|
||||
TODO: in Common.Dotnet.CsWinRT.props, on upgrade, verify RemoveCsWinRTPackageAnalyzer is no longer needed.
|
||||
This is present due to a bug in CsWinRT where WPF projects cause the analyzer to fail.
|
||||
-->
|
||||
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
|
||||
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4188" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.7.250513003" />
|
||||
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
|
||||
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
|
||||
|
||||
@@ -1533,9 +1533,9 @@ SOFTWARE.
|
||||
- Microsoft.Web.WebView2 1.0.2903.40
|
||||
- Microsoft.Win32.SystemEvents 9.0.6
|
||||
- Microsoft.Windows.Compatibility 9.0.6
|
||||
- Microsoft.Windows.CsWin32 0.2.46-beta
|
||||
- Microsoft.Windows.CsWin32 0.3.183
|
||||
- Microsoft.Windows.CsWinRT 2.2.0
|
||||
- Microsoft.Windows.SDK.BuildTools 10.0.22621.2428
|
||||
- Microsoft.Windows.SDK.BuildTools 10.0.26100.4188
|
||||
- Microsoft.WindowsAppSDK 1.7.250513003
|
||||
- Microsoft.WindowsPackageManager.ComInterop 1.10.340
|
||||
- Microsoft.Xaml.Behaviors.WinUI.Managed 2.0.9
|
||||
|
||||
@@ -723,6 +723,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkspacesEditorUITest", "s
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalculatorEngineCommon", "src\common\CalculatorEngineCommon\CalculatorEngineCommon.vcxproj", "{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCsWin32", "src\common\ManagedCsWin32\ManagedCsWin32.csproj", "{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
@@ -2649,6 +2651,14 @@ Global
|
||||
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|x64.ActiveCfg = Release|x64
|
||||
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6}.Release|x64.Build.0 = Release|x64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Debug|x64.Build.0 = Debug|x64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|x64.ActiveCfg = Release|x64
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -2926,6 +2936,7 @@ Global
|
||||
{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2} = {3846508C-77EB-4034-A702-F8BB263C4F79}
|
||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
|
||||
{2CF78CF7-8FEB-4BE1-9591-55FA25B48FC6} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||
{14AFD976-B4D2-49D0-9E6C-AA93CC061B8A} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
||||
@@ -17,6 +17,7 @@ The bug report includes the following files:
|
||||
* `context-menu-packages.txt` - Information about the packages that are registered for the new Windows 11 context menu.
|
||||
* `dotnet-installation-info.txt` - Information about the installed .NET versions.
|
||||
* `EventViewer-*.xml` - These files contain event logs from the Windows Event Viewer for the executable specified in the file name.
|
||||
* `EventViewer-Microsoft-Windows-AppXDeploymentServer/Operational.xml` - Contains event logs from the AppXDeployment-Server which are useful for diagnosing MSIX installation issues.
|
||||
* `gpo-configuration-info.txt` - Information about the configured [GPO](/doc/gpo/README.md).
|
||||
* `installationFolderStructure.txt` - Information about the folder structure of the installation. All lines with files have the following structure: `FileName Version MD5Hash`.
|
||||
* `last_version_run.json` - Information about the last version of PowerToys that was run.
|
||||
|
||||
@@ -8,10 +8,10 @@ SET VCToolsVersion=!VCToolsVersion!
|
||||
SET ClearDevCommandPromptEnvVars=false
|
||||
|
||||
rem In case of Release we should not use Debug CRT in VCRT forwarders
|
||||
msbuild !PTRoot!\src\modules\previewpane\MonacoPreviewHandler\MonacoPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml
|
||||
msbuild !PTRoot!\src\modules\previewpane\MonacoPreviewHandler\MonacoPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml -p:TargetFramework=net9.0-windows10.0.26100.0
|
||||
|
||||
msbuild !PTRoot!\src\modules\previewpane\MarkdownPreviewHandler\MarkdownPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml
|
||||
msbuild !PTRoot!\src\modules\previewpane\MarkdownPreviewHandler\MarkdownPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml -p:TargetFramework=net9.0-windows10.0.26100.0
|
||||
|
||||
msbuild !PTRoot!\src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml
|
||||
msbuild !PTRoot!\src\modules\previewpane\SvgPreviewHandler\SvgPreviewHandler.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml -p:TargetFramework=net9.0-windows10.0.26100.0
|
||||
|
||||
msbuild !PTRoot!\src\modules\previewpane\SvgThumbnailProvider\SvgThumbnailProvider.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml
|
||||
msbuild !PTRoot!\src\modules\previewpane\SvgThumbnailProvider\SvgThumbnailProvider.csproj -t:Publish -p:Configuration="Release" -p:Platform="!PlatformArg!" -p:AppxBundle=Never -p:PowerToysRoot=!PTRoot! -p:VCRTForwarders-IncludeDebugCRT=false -p:PublishProfile=InstallationPublishProfile.pubxml -p:TargetFramework=net9.0-windows10.0.26100.0
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<Import Project=".\Common.Dotnet.PrepareGeneratedFolder.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<WindowsSdkPackageVersion>10.0.22621.57</WindowsSdkPackageVersion>
|
||||
<TargetFramework>net9.0-windows10.0.22621.0</TargetFramework>
|
||||
<WindowsSdkPackageVersion>10.0.26100.68-preview</WindowsSdkPackageVersion>
|
||||
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
|
||||
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
|
||||
19
src/common/ManagedCsWin32/CLSID.cs
Normal file
19
src/common/ManagedCsWin32/CLSID.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static partial class CLSID
|
||||
{
|
||||
public static readonly Guid SearchManager = new Guid("7D096C5F-AC08-4F1F-BEB7-5C22C517CE39");
|
||||
public static readonly Guid CollatorDataSource = new Guid("9E175B8B-F52A-11D8-B9A5-505054503030");
|
||||
public static readonly Guid ApplicationActivationManager = new Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C");
|
||||
public static readonly Guid VirtualDesktopManager = new("aa509086-5ca9-4c25-8f95-589d3c07b48a");
|
||||
}
|
||||
45
src/common/ManagedCsWin32/ComHelper.cs
Normal file
45
src/common/ManagedCsWin32/ComHelper.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static class ComHelper
|
||||
{
|
||||
private static StrategyBasedComWrappers cw = new StrategyBasedComWrappers();
|
||||
|
||||
public static T CreateComInstance<T>(ref Guid rclsid, CLSCTX dwClsContext)
|
||||
{
|
||||
var riid = typeof(T).GUID;
|
||||
|
||||
var hr = Ole32.CoCreateInstance(ref rclsid, IntPtr.Zero, dwClsContext, ref riid, out IntPtr comPtr);
|
||||
if (hr != 0)
|
||||
{
|
||||
throw new ArgumentException($"Failed to create {typeof(T).Name} instance. HR: {hr}");
|
||||
}
|
||||
|
||||
if (comPtr == IntPtr.Zero)
|
||||
{
|
||||
throw new ArgumentException($"Failed to create {typeof(T).Name} instance. CoCreateInstance return null ptr.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var comObject = cw.GetOrCreateObjectForComInstance(comPtr, CreateObjectFlags.None);
|
||||
if (comObject == null)
|
||||
{
|
||||
throw new ArgumentException($"Failed to create {typeof(T).Name} instance. Cast error.");
|
||||
}
|
||||
|
||||
return (T)comObject;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.Release(comPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/common/ManagedCsWin32/IID.cs
Normal file
19
src/common/ManagedCsWin32/IID.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static partial class IID
|
||||
{
|
||||
public static readonly Guid ISearchManager = new Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69");
|
||||
public static readonly Guid IPropertyStore = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");
|
||||
public static readonly Guid IApplicationActivationManager = new Guid("2e941141-7f97-4756-ba1d-9decde894a3d");
|
||||
public static readonly Guid IVirtualDesktopManager = new("a5cd92ff-29be-454c-8d04-d82879fb3f1b");
|
||||
}
|
||||
145
src/common/ManagedCsWin32/Kernel32.cs
Normal file
145
src/common/ManagedCsWin32/Kernel32.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static partial class Kernel32
|
||||
{
|
||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool DeviceIoControl(
|
||||
IntPtr hDevice,
|
||||
uint dwIoControlCode,
|
||||
IntPtr inBuffer,
|
||||
int nInBufferSize,
|
||||
IntPtr outBuffer,
|
||||
int nOutBufferSize,
|
||||
out int pBytesReturned,
|
||||
IntPtr lpOverlapped);
|
||||
|
||||
[LibraryImport("kernel32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
|
||||
public static partial int CreateFile(
|
||||
string lpFileName,
|
||||
FileAccessType dwDesiredAccess,
|
||||
FileShareType dwShareMode,
|
||||
IntPtr lpSecurityAttributes,
|
||||
CreationDisposition dwCreationDisposition,
|
||||
FileAttributes dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile);
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FileAccessType : uint
|
||||
{
|
||||
DELETE = 0x00010000,
|
||||
READ_CONTROL = 0x00020000,
|
||||
WRITE_DAC = 0x00040000,
|
||||
WRITE_OWNER = 0x00080000,
|
||||
SYNCHRONIZE = 0x00100000,
|
||||
|
||||
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
|
||||
|
||||
STANDARD_RIGHTS_READ = READ_CONTROL,
|
||||
STANDARD_RIGHTS_WRITE = READ_CONTROL,
|
||||
STANDARD_RIGHTS_EXECUTE = READ_CONTROL,
|
||||
|
||||
STANDARD_RIGHTS_ALL = 0x001F0000,
|
||||
|
||||
SPECIFIC_RIGHTS_ALL = 0x0000FFFF,
|
||||
|
||||
ACCESS_SYSTEM_SECURITY = 0x01000000,
|
||||
|
||||
MAXIMUM_ALLOWED = 0x02000000,
|
||||
|
||||
GENERIC_READ = 0x80000000,
|
||||
GENERIC_WRITE = 0x40000000,
|
||||
GENERIC_EXECUTE = 0x20000000,
|
||||
GENERIC_ALL = 0x10000000,
|
||||
|
||||
FILE_READ_DATA = 0x0001,
|
||||
FILE_WRITE_DATA = 0x0002,
|
||||
FILE_APPEND_DATA = 0x0004,
|
||||
FILE_READ_EA = 0x0008,
|
||||
FILE_WRITE_EA = 0x0010,
|
||||
FILE_EXECUTE = 0x0020,
|
||||
FILE_READ_ATTRIBUTES = 0x0080,
|
||||
FILE_WRITE_ATTRIBUTES = 0x0100,
|
||||
|
||||
FILE_ALL_ACCESS =
|
||||
STANDARD_RIGHTS_REQUIRED |
|
||||
SYNCHRONIZE
|
||||
| 0x1FF,
|
||||
|
||||
FILE_GENERIC_READ =
|
||||
STANDARD_RIGHTS_READ |
|
||||
FILE_READ_DATA |
|
||||
FILE_READ_ATTRIBUTES |
|
||||
FILE_READ_EA |
|
||||
SYNCHRONIZE,
|
||||
|
||||
FILE_GENERIC_WRITE =
|
||||
STANDARD_RIGHTS_WRITE |
|
||||
FILE_WRITE_DATA |
|
||||
FILE_WRITE_ATTRIBUTES |
|
||||
FILE_WRITE_EA |
|
||||
FILE_APPEND_DATA |
|
||||
SYNCHRONIZE,
|
||||
|
||||
FILE_GENERIC_EXECUTE =
|
||||
STANDARD_RIGHTS_EXECUTE |
|
||||
FILE_READ_ATTRIBUTES |
|
||||
FILE_EXECUTE |
|
||||
SYNCHRONIZE,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FileShareType : uint
|
||||
{
|
||||
None = 0x00000000,
|
||||
Read = 0x00000001,
|
||||
Write = 0x00000002,
|
||||
Delete = 0x00000004,
|
||||
}
|
||||
|
||||
public enum CreationDisposition : uint
|
||||
{
|
||||
New = 1,
|
||||
CreateAlways = 2,
|
||||
OpenExisting = 3,
|
||||
OpenAlways = 4,
|
||||
TruncateExisting = 5,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FileAttributes : uint
|
||||
{
|
||||
Readonly = 0x00000001,
|
||||
Hidden = 0x00000002,
|
||||
System = 0x00000004,
|
||||
Directory = 0x00000010,
|
||||
Archive = 0x00000020,
|
||||
Device = 0x00000040,
|
||||
Normal = 0x00000080,
|
||||
Temporary = 0x00000100,
|
||||
SparseFile = 0x00000200,
|
||||
ReparsePoint = 0x00000400,
|
||||
Compressed = 0x00000800,
|
||||
Offline = 0x00001000,
|
||||
NotContentIndexed = 0x00002000,
|
||||
Encrypted = 0x00004000,
|
||||
Write_Through = 0x80000000,
|
||||
Overlapped = 0x40000000,
|
||||
NoBuffering = 0x20000000,
|
||||
RandomAccess = 0x10000000,
|
||||
SequentialScan = 0x08000000,
|
||||
DeleteOnClose = 0x04000000,
|
||||
BackupSemantics = 0x02000000,
|
||||
PosixSemantics = 0x01000000,
|
||||
OpenReparsePoint = 0x00200000,
|
||||
OpenNoRecall = 0x00100000,
|
||||
FirstPipeInstance = 0x00080000,
|
||||
}
|
||||
9
src/common/ManagedCsWin32/ManagedCsWin32.csproj
Normal file
9
src/common/ManagedCsWin32/ManagedCsWin32.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="..\..\.\Common.Dotnet.CsWinRT.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>PowerToys ManagedCsWin32</Description>
|
||||
<AssemblyName>PowerToys.ManagedCsWin32</AssemblyName>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
58
src/common/ManagedCsWin32/Ole32.cs
Normal file
58
src/common/ManagedCsWin32/Ole32.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static partial class Ole32
|
||||
{
|
||||
[LibraryImport("ole32.dll")]
|
||||
public static partial int CoCreateInstance(
|
||||
ref Guid rclsid,
|
||||
IntPtr pUnkOuter,
|
||||
CLSCTX dwClsContext,
|
||||
ref Guid riid,
|
||||
out IntPtr rReturnedComObject);
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CLSCTX : uint
|
||||
{
|
||||
InProcServer = 0x1,
|
||||
InProcHandler = 0x2,
|
||||
LocalServer = 0x4,
|
||||
InProcServer16 = 0x8,
|
||||
RemoteServer = 0x10,
|
||||
InProcHandler16 = 0x20,
|
||||
Reserved1 = 0x40,
|
||||
Reserved2 = 0x80,
|
||||
Reserved3 = 0x100,
|
||||
Reserved4 = 0x200,
|
||||
NoCodeDownload = 0x400,
|
||||
Reserved5 = 0x800,
|
||||
NoCustomMarshal = 0x1000,
|
||||
EnableCodeDownload = 0x2000,
|
||||
NoFailureLog = 0x4000,
|
||||
DisableAAA = 0x8000,
|
||||
EnableAAA = 0x10000,
|
||||
FromDefaultContext = 0x20000,
|
||||
ActivateX86Server = 0x40000,
|
||||
#pragma warning disable CA1069 // Keep the original defines for compatibility
|
||||
Activate32BitServer = 0x40000, // Same as ActivateX86Server
|
||||
#pragma warning restore CA1069 // Keep the original defines for compatibility
|
||||
Activate64BitServer = 0x80000,
|
||||
EnableCloaking = 0x100000,
|
||||
AppContainer = 0x400000,
|
||||
ActivateAAAAsIU = 0x800000,
|
||||
Reserved6 = 0x1000000,
|
||||
ActivateARM32Server = 0x2000000,
|
||||
AllowLowerTrustRegistration = 0x4000000,
|
||||
PSDll = 0x80000000,
|
||||
|
||||
INPROC = InProcServer | InProcHandler,
|
||||
SERVER = InProcServer | LocalServer | RemoteServer,
|
||||
ALL = InProcHandler | SERVER,
|
||||
}
|
||||
36
src/common/ManagedCsWin32/Shell32.cs
Normal file
36
src/common/ManagedCsWin32/Shell32.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ManagedCsWin32;
|
||||
|
||||
public static partial class Shell32
|
||||
{
|
||||
[LibraryImport("SHELL32.dll", EntryPoint = "ShellExecuteExW", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool ShellExecuteEx(ref SHELLEXECUTEINFOW lpExecInfo);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHELLEXECUTEINFOW
|
||||
{
|
||||
public uint CbSize;
|
||||
public uint FMask;
|
||||
public IntPtr Hwnd;
|
||||
|
||||
public IntPtr LpVerb;
|
||||
public IntPtr LpFile;
|
||||
public IntPtr LpParameters;
|
||||
public IntPtr LpDirectory;
|
||||
public int Show;
|
||||
public IntPtr HInstApp;
|
||||
public IntPtr LpIDList;
|
||||
public IntPtr LpClass;
|
||||
public IntPtr HkeyClass;
|
||||
public uint DwHotKey;
|
||||
public IntPtr HIconOrMonitor;
|
||||
public IntPtr Process;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// project, where bugs will be filed
|
||||
"org": "microsoft",
|
||||
"project": "OS",
|
||||
"AssignedTo": "leilzh@microsoft.com",
|
||||
"AssignedTo": "PowerToys@microsoft.com",
|
||||
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
|
||||
"IterationPath": "OS\\Future"
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
1) Per-Monitor for >= Windows 10 Anniversary Update
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
@@ -10,7 +10,7 @@
|
||||
<ProjectGuid>{f5e1146e-b7b3-4e11-85fd-270a500bd78c}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>CropAndLock</RootNamespace>
|
||||
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22621.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.26100.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.19041.0</WindowsTargetPlatformMinVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
@@ -154,6 +154,9 @@
|
||||
<ProjectReference Include="..\..\..\common\Telemetry\EtwTrace\EtwTrace.vcxproj">
|
||||
<Project>{8f021b46-362b-485c-bfba-ccf83e820cbd}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\common\Themes\Themes.vcxproj">
|
||||
<Project>{98537082-0fdb-40de-abd8-0dc5a4269bab}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<Import Project="..\..\..\..\deps\spdlog.props" />
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#include <common/Telemetry/EtwTrace/EtwTrace.h>
|
||||
|
||||
#include <common/Themes/theme_helpers.h>
|
||||
#include <common/Themes/theme_listener.h>
|
||||
|
||||
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||
|
||||
namespace winrt
|
||||
@@ -35,6 +38,23 @@ namespace util
|
||||
const std::wstring instanceMutexName = L"Local\\PowerToys_CropAndLock_InstanceMutex";
|
||||
bool m_running = true;
|
||||
|
||||
// Theming
|
||||
ThemeListener theme_listener{};
|
||||
// Keep a list of our cropped windows
|
||||
std::vector<std::shared_ptr<CropAndLockWindow>> croppedWindows;
|
||||
|
||||
void handleTheme()
|
||||
{
|
||||
auto theme = theme_listener.AppTheme;
|
||||
auto isDark = theme == Theme::Dark;
|
||||
Logger::info(L"Theme is now {}", isDark ? L"Dark" : L"Light");
|
||||
for (auto&& croppedWindow : croppedWindows)
|
||||
{
|
||||
ThemeHelpers::SetImmersiveDarkMode(croppedWindow->Handle(), isDark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _In_ int)
|
||||
{
|
||||
// Initialize COM
|
||||
@@ -42,6 +62,8 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
|
||||
Trace::CropAndLock::RegisterProvider();
|
||||
|
||||
theme_listener.AddChangedHandler(handleTheme);
|
||||
|
||||
Shared::Trace::ETWTrace trace;
|
||||
trace.UpdateState(true);
|
||||
|
||||
@@ -107,8 +129,6 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
// Create our overlay window
|
||||
std::unique_ptr<OverlayWindow> overlayWindow;
|
||||
|
||||
// Keep a list of our cropped windows
|
||||
std::vector<std::shared_ptr<CropAndLockWindow>> croppedWindows;
|
||||
|
||||
// Handles and thread for the events sent from runner
|
||||
HANDLE m_reparent_event_handle;
|
||||
@@ -167,6 +187,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I
|
||||
croppedWindow->CropAndLock(targetWindow, cropRect);
|
||||
croppedWindow->OnClosed(removeWindowCallback);
|
||||
croppedWindows.push_back(croppedWindow);
|
||||
handleTheme();
|
||||
};
|
||||
|
||||
overlayWindow.reset();
|
||||
|
||||
@@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<TargetFramework>net9.0-windows10.0.22621.0</TargetFramework>
|
||||
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
|
||||
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
||||
<PublishDir>$(PowerToysRoot)\$(Platform)\$(Configuration)\WinUI3Apps</PublishDir>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
// project, where bugs will be filed
|
||||
"org": "microsoft",
|
||||
"project": "OS",
|
||||
"AssignedTo": "mengyuanchen@microsoft.com",
|
||||
"AssignedTo": "PowerToys@microsoft.com",
|
||||
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
|
||||
"IterationPath": "OS\\Future"
|
||||
},
|
||||
"jobNotificationEmail": "mengyuanchen@microsoft.com",
|
||||
"jobNotificationEmail": "PowerToys@microsoft.com",
|
||||
"skip": false,
|
||||
"rebootAfterSetup": false,
|
||||
"oneFuzzJobs": [
|
||||
@@ -57,11 +57,11 @@
|
||||
// project, where bugs will be filed
|
||||
"org": "microsoft",
|
||||
"project": "OS",
|
||||
"AssignedTo": "mengyuanchen@microsoft.com",
|
||||
"AssignedTo": "PowerToys@microsoft.com",
|
||||
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
|
||||
"IterationPath": "OS\\Future"
|
||||
},
|
||||
"jobNotificationEmail": "mengyuanchen@microsoft.com",
|
||||
"jobNotificationEmail": "PowerToys@microsoft.com",
|
||||
"skip": false,
|
||||
"rebootAfterSetup": false,
|
||||
"oneFuzzJobs": [
|
||||
@@ -98,11 +98,11 @@
|
||||
// project, where bugs will be filed
|
||||
"org": "microsoft",
|
||||
"project": "OS",
|
||||
"AssignedTo": "mengyuanchen@microsoft.com",
|
||||
"AssignedTo": "PowerToys@microsoft.com",
|
||||
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
|
||||
"IterationPath": "OS\\Future"
|
||||
},
|
||||
"jobNotificationEmail": "mengyuanchen@microsoft.com",
|
||||
"jobNotificationEmail": "PowerToys@microsoft.com",
|
||||
"skip": false,
|
||||
"rebootAfterSetup": false,
|
||||
"oneFuzzJobs": [
|
||||
@@ -139,7 +139,7 @@
|
||||
// project, where bugs will be filed
|
||||
"org": "microsoft",
|
||||
"project": "OS",
|
||||
"AssignedTo": "mengyuanchen@microsoft.com",
|
||||
"AssignedTo": "PowerToys@microsoft.com",
|
||||
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
|
||||
"IterationPath": "OS\\Future"
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.props')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.props')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.props')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<CppWinRTOptimized>true</CppWinRTOptimized>
|
||||
@@ -139,7 +139,7 @@
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets')" />
|
||||
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.targets')" />
|
||||
</ImportGroup>
|
||||
@@ -150,8 +150,8 @@
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.2428\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.4188\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Web.WebView2.1.0.2903.40\build\native\Microsoft.Web.WebView2.targets'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.props'))" />
|
||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.7.250513003\build\native\Microsoft.WindowsAppSDK.targets'))" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="Microsoft.Web.WebView2" version="1.0.2903.40" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.2428" targetFramework="native" />
|
||||
<package id="Microsoft.Windows.SDK.BuildTools" version="10.0.26100.4188" targetFramework="native" />
|
||||
<package id="Microsoft.WindowsAppSDK" version="1.7.250513003" targetFramework="native" />
|
||||
</packages>
|
||||
@@ -9,7 +9,7 @@
|
||||
2) System < Windows 10 Anniversary Update
|
||||
-->
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{0db0f63a-d2f8-4da3-a650-2d0b8724218e}</ProjectGuid>
|
||||
<RootNamespace>NewPlusShellExtensionWin10</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.26100.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
@@ -49,6 +49,8 @@ namespace WorkspacesEditor.Data
|
||||
public WindowPositionWrapper Position { get; set; }
|
||||
|
||||
public int Monitor { get; set; }
|
||||
|
||||
public string Version { get; set; }
|
||||
}
|
||||
|
||||
public struct MonitorConfigurationWrapper
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace WorkspacesEditor.Models
|
||||
Maximized = other.Maximized;
|
||||
Position = other.Position;
|
||||
MonitorNumber = other.MonitorNumber;
|
||||
Version = other.Version;
|
||||
|
||||
Parent = other.Parent;
|
||||
IsNotFound = other.IsNotFound;
|
||||
@@ -274,5 +275,7 @@ namespace WorkspacesEditor.Models
|
||||
CommandLineArguments = newCommandLineValue;
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppMainParams)));
|
||||
}
|
||||
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,6 +246,7 @@ namespace WorkspacesEditor.Models
|
||||
AppPath = app.ApplicationPath,
|
||||
AppTitle = app.Title,
|
||||
PwaAppId = string.IsNullOrEmpty(app.PwaAppId) ? string.Empty : app.PwaAppId,
|
||||
Version = string.IsNullOrEmpty(app.Version) ? string.Empty : app.Version,
|
||||
PackageFullName = app.PackageFullName,
|
||||
AppUserModelId = app.AppUserModelId,
|
||||
Parent = this,
|
||||
|
||||
@@ -107,6 +107,7 @@ namespace WorkspacesEditor.Utils
|
||||
CommandLineArguments = app.CommandLineArguments,
|
||||
IsElevated = app.IsElevated,
|
||||
CanLaunchElevated = app.CanLaunchElevated,
|
||||
Version = app.Version,
|
||||
Maximized = app.Maximized,
|
||||
Minimized = app.Minimized,
|
||||
Position = new ProjectData.ApplicationWrapper.WindowPositionWrapper
|
||||
|
||||
@@ -165,16 +165,52 @@ namespace AppLauncher
|
||||
|
||||
if (!launched && !app.pwaAppId.empty())
|
||||
{
|
||||
std::filesystem::path appPath(app.path);
|
||||
if (appPath.filename() == NonLocalizable::EdgeFilename)
|
||||
int version = 0;
|
||||
|
||||
if (app.version != L"")
|
||||
{
|
||||
appPathFinal = appPath.parent_path() / NonLocalizable::EdgePwaFilename;
|
||||
commandLineArgsFinal = NonLocalizable::PwaCommandLineAddition + app.pwaAppId + L" " + app.commandLineArgs;
|
||||
try
|
||||
{
|
||||
version = std::stoi(app.version);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
{
|
||||
Logger::error(L"Invalid version format: {}", app.version);
|
||||
version = 0;
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
Logger::error(L"Version out of range: {}", app.version);
|
||||
version = 0;
|
||||
}
|
||||
}
|
||||
if (appPath.filename() == NonLocalizable::ChromeFilename)
|
||||
|
||||
if (version >= 1)
|
||||
{
|
||||
appPathFinal = appPath.parent_path() / NonLocalizable::ChromePwaFilename;
|
||||
commandLineArgsFinal = NonLocalizable::PwaCommandLineAddition + app.pwaAppId + L" " + app.commandLineArgs;
|
||||
auto res = LaunchApp(L"shell:AppsFolder\\" + app.appUserModelId, app.commandLineArgs, app.isElevated);
|
||||
if (res.isOk())
|
||||
{
|
||||
launched = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
launchErrors.push_back({ app.appUserModelId, res.error() });
|
||||
}
|
||||
}
|
||||
|
||||
if (!launched)
|
||||
{
|
||||
std::filesystem::path appPath(app.path);
|
||||
if (appPath.filename() == NonLocalizable::EdgeFilename)
|
||||
{
|
||||
appPathFinal = appPath.parent_path() / NonLocalizable::EdgePwaFilename;
|
||||
commandLineArgsFinal = NonLocalizable::PwaCommandLineAddition + app.pwaAppId + L" " + app.commandLineArgs;
|
||||
}
|
||||
if (appPath.filename() == NonLocalizable::ChromeFilename)
|
||||
{
|
||||
appPathFinal = appPath.parent_path() / NonLocalizable::ChromePwaFilename;
|
||||
commandLineArgsFinal = NonLocalizable::PwaCommandLineAddition + app.pwaAppId + L" " + app.commandLineArgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,19 +76,6 @@ namespace WorkspacesLibUnitTests
|
||||
Assert::IsTrue(result == nonExistentWindowAumid);
|
||||
}
|
||||
|
||||
TEST_METHOD (PwaHelper_GetAUMIDFromWindow_InvalidWindow_ReturnsEmpty)
|
||||
{
|
||||
// Arrange
|
||||
Utils::PwaHelper helper;
|
||||
HWND invalidWindow = nullptr;
|
||||
|
||||
// Act
|
||||
std::wstring result = helper.GetAUMIDFromWindow(invalidWindow);
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(result.empty());
|
||||
}
|
||||
|
||||
TEST_METHOD (PwaHelper_GetEdgeAppId_ValidConstruction_DoesNotCrash)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "PwaHelper.h"
|
||||
#include "WindowUtils.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
@@ -51,7 +52,7 @@ namespace Utils
|
||||
localFolder = L""; // Ensure it is explicitly set to empty on failure
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return localFolder;
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ namespace Utils
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
std::optional<std::wstring> PwaHelper::GetChromeAppId(const std::wstring& windowAumid) const
|
||||
{
|
||||
const auto appIdIndexStart = windowAumid.find(NonLocalizable::ChromeAppIdIdentifier);
|
||||
@@ -256,85 +257,4 @@ namespace Utils
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring PwaHelper::GetAUMIDFromWindow(HWND hwnd) const
|
||||
{
|
||||
std::wstring result{};
|
||||
if (hwnd == NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IPropertyStore> propertyStore;
|
||||
HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&propertyStore));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
PROPVARIANT propVariant;
|
||||
PropVariantInit(&propVariant);
|
||||
|
||||
hr = propertyStore->GetValue(PKEY_AppUserModel_ID, &propVariant);
|
||||
if (SUCCEEDED(hr) && propVariant.vt == VT_LPWSTR && propVariant.pwszVal != nullptr)
|
||||
{
|
||||
result = propVariant.pwszVal;
|
||||
}
|
||||
|
||||
PropVariantClear(&propVariant);
|
||||
|
||||
Logger::info(L"Found a window with aumid {}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring PwaHelper::GetAUMIDFromProcessId(DWORD processId) const
|
||||
{
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
||||
if (hProcess == NULL)
|
||||
{
|
||||
Logger::error(L"Failed to open process handle. Error: {}", get_last_error_or_default(GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// Get the package full name for the process
|
||||
UINT32 packageFullNameLength = 0;
|
||||
LONG rc = GetPackageFullName(hProcess, &packageFullNameLength, nullptr);
|
||||
if (rc != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
Logger::error(L"Failed to get package full name length. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<wchar_t> packageFullName(packageFullNameLength);
|
||||
rc = GetPackageFullName(hProcess, &packageFullNameLength, packageFullName.data());
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
Logger::error(L"Failed to get package full name. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
// Get the AUMID for the package
|
||||
UINT32 appModelIdLength = 0;
|
||||
rc = GetApplicationUserModelId(hProcess, &appModelIdLength, nullptr);
|
||||
if (rc != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
Logger::error(L"Failed to get AppUserModelId length. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<wchar_t> appModelId(appModelIdLength);
|
||||
rc = GetApplicationUserModelId(hProcess, &appModelIdLength, appModelId.data());
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
Logger::error(L"Failed to get AppUserModelId. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
return std::wstring(appModelId.data());
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,16 @@ namespace Utils
|
||||
PwaHelper();
|
||||
~PwaHelper() = default;
|
||||
|
||||
std::wstring GetAUMIDFromWindow(HWND hWnd) const;
|
||||
|
||||
std::optional<std::wstring> GetEdgeAppId(const std::wstring& windowAumid) const;
|
||||
std::optional<std::wstring> GetChromeAppId(const std::wstring& windowAumid) const;
|
||||
std::optional<std::wstring> GetChromeAppId(const std::wstring& windowAumid) const;
|
||||
std::wstring SearchPwaName(const std::wstring& pwaAppId, const std::wstring& windowAumid) const;
|
||||
|
||||
|
||||
private:
|
||||
void InitAppIds(const std::wstring& browserDataFolder, const std::wstring& browserDirPrefix, const std::function<void(const std::wstring&)>& addingAppIdCallback);
|
||||
void InitEdgeAppIds();
|
||||
void InitChromeAppIds();
|
||||
|
||||
std::wstring GetAppIdFromCommandLineArgs(const std::wstring& commandLineArgs) const;
|
||||
std::wstring GetAUMIDFromProcessId(DWORD processId) const;
|
||||
|
||||
std::map<std::wstring, std::wstring> m_edgeAppIds;
|
||||
std::vector<std::wstring> m_chromeAppIds;
|
||||
|
||||
18
src/modules/Workspaces/WorkspacesLib/StringUtils.cpp
Normal file
18
src/modules/Workspaces/WorkspacesLib/StringUtils.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
|
||||
namespace StringUtils
|
||||
{
|
||||
bool CaseInsensitiveEquals(const std::wstring& str1, const std::wstring& str2)
|
||||
{
|
||||
if (str1.size() != str2.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::equal(str1.begin(), str1.end(), str2.begin(), [](wchar_t ch1, wchar_t ch2) {
|
||||
return towupper(ch1) == towupper(ch2);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,5 @@
|
||||
|
||||
namespace StringUtils
|
||||
{
|
||||
inline bool CaseInsensitiveEquals(const std::wstring& str1, const std::wstring& str2)
|
||||
{
|
||||
if (str1.size() != str2.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::equal(str1.begin(), str1.end(), str2.begin(), [](wchar_t ch1, wchar_t ch2) {
|
||||
return towupper(ch1) == towupper(ch2);
|
||||
});
|
||||
}
|
||||
bool CaseInsensitiveEquals(const std::wstring& str1, const std::wstring& str2);
|
||||
}
|
||||
|
||||
105
src/modules/Workspaces/WorkspacesLib/WindowUtils.cpp
Normal file
105
src/modules/Workspaces/WorkspacesLib/WindowUtils.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "pch.h"
|
||||
#include "WindowUtils.h"
|
||||
#include <filesystem>
|
||||
|
||||
#include <appmodel.h>
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <ShlObj.h>
|
||||
#include <shobjidl.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <wrl.h>
|
||||
#include <propkey.h>
|
||||
|
||||
#include <wil/com.h>
|
||||
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
#include <WorkspacesLib/AppUtils.h>
|
||||
#include <WorkspacesLib/CommandLineArgsHelper.h>
|
||||
#include <WorkspacesLib/StringUtils.h>
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
std::wstring GetAUMIDFromProcessId(DWORD processId)
|
||||
{
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
||||
if (hProcess == NULL)
|
||||
{
|
||||
Logger::error(L"Failed to open process handle. Error: {}", get_last_error_or_default(GetLastError()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// Get the package full name for the process
|
||||
UINT32 packageFullNameLength = 0;
|
||||
LONG rc = GetPackageFullName(hProcess, &packageFullNameLength, nullptr);
|
||||
if (rc != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
Logger::error(L"Failed to get package full name length. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<wchar_t> packageFullName(packageFullNameLength);
|
||||
rc = GetPackageFullName(hProcess, &packageFullNameLength, packageFullName.data());
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
Logger::error(L"Failed to get package full name. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
// Get the AUMID for the package
|
||||
UINT32 appModelIdLength = 0;
|
||||
rc = GetApplicationUserModelId(hProcess, &appModelIdLength, nullptr);
|
||||
if (rc != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
Logger::error(L"Failed to get AppUserModelId length. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<wchar_t> appModelId(appModelIdLength);
|
||||
rc = GetApplicationUserModelId(hProcess, &appModelIdLength, appModelId.data());
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
Logger::error(L"Failed to get AppUserModelId. Error code: {}", rc);
|
||||
CloseHandle(hProcess);
|
||||
return {};
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
return std::wstring(appModelId.data());
|
||||
}
|
||||
|
||||
std::wstring GetAUMIDFromWindow(HWND hwnd)
|
||||
{
|
||||
std::wstring result{};
|
||||
if (hwnd == NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IPropertyStore> propertyStore;
|
||||
HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&propertyStore));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
PROPVARIANT propVariant;
|
||||
PropVariantInit(&propVariant);
|
||||
|
||||
hr = propertyStore->GetValue(PKEY_AppUserModel_ID, &propVariant);
|
||||
if (SUCCEEDED(hr) && propVariant.vt == VT_LPWSTR && propVariant.pwszVal != nullptr)
|
||||
{
|
||||
result = propVariant.pwszVal;
|
||||
}
|
||||
|
||||
PropVariantClear(&propVariant);
|
||||
|
||||
Logger::info(L"Found a window with aumid {}", result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
12
src/modules/Workspaces/WorkspacesLib/WindowUtils.h
Normal file
12
src/modules/Workspaces/WorkspacesLib/WindowUtils.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <WorkspacesLib/AppUtils.h>
|
||||
#include <wtypes.h>
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
std::wstring GetAUMIDFromWindow(HWND hWnd);
|
||||
std::wstring GetAUMIDFromProcessId(DWORD processId);
|
||||
};
|
||||
@@ -87,6 +87,7 @@ namespace WorkspacesData
|
||||
const static wchar_t* MaximizedID = L"maximized";
|
||||
const static wchar_t* PositionID = L"position";
|
||||
const static wchar_t* MonitorID = L"monitor";
|
||||
const static wchar_t* VersionID = L"version";
|
||||
}
|
||||
|
||||
json::JsonObject ToJson(const WorkspacesProject::Application& data)
|
||||
@@ -106,6 +107,7 @@ namespace WorkspacesData
|
||||
json.SetNamedValue(NonLocalizable::MaximizedID, json::value(data.isMaximized));
|
||||
json.SetNamedValue(NonLocalizable::PositionID, PositionJSON::ToJson(data.position));
|
||||
json.SetNamedValue(NonLocalizable::MonitorID, json::value(data.monitor));
|
||||
json.SetNamedValue(NonLocalizable::VersionID, json::value(data.version));
|
||||
|
||||
return json;
|
||||
}
|
||||
@@ -168,6 +170,11 @@ namespace WorkspacesData
|
||||
|
||||
result.position = position.value();
|
||||
}
|
||||
|
||||
if (json.HasKey(NonLocalizable::VersionID))
|
||||
{
|
||||
result.version = json.GetNamedString(NonLocalizable::VersionID);
|
||||
}
|
||||
}
|
||||
catch (const winrt::hresult_error&)
|
||||
{
|
||||
@@ -286,6 +293,7 @@ namespace WorkspacesData
|
||||
const static wchar_t* MoveExistingWindowsID = L"move-existing-windows";
|
||||
const static wchar_t* MonitorConfigurationID = L"monitor-configuration";
|
||||
const static wchar_t* AppsID = L"applications";
|
||||
const static wchar_t* Version = L"version";
|
||||
}
|
||||
|
||||
json::JsonObject ToJson(const WorkspacesProject& data)
|
||||
|
||||
@@ -33,6 +33,9 @@ namespace WorkspacesData
|
||||
std::wstring appUserModelId;
|
||||
std::wstring pwaAppId;
|
||||
std::wstring commandLineArgs;
|
||||
|
||||
// empty to 1,
|
||||
std::wstring version;
|
||||
bool isElevated{};
|
||||
bool canLaunchElevated{};
|
||||
bool isMinimized{};
|
||||
@@ -86,7 +89,7 @@ namespace WorkspacesData
|
||||
{
|
||||
WorkspacesData::WorkspacesProject::Application application;
|
||||
HWND window{};
|
||||
LaunchingState state { LaunchingState::Waiting };
|
||||
LaunchingState state{ LaunchingState::Waiting };
|
||||
};
|
||||
|
||||
using LaunchingAppStateMap = std::map<WorkspacesData::WorkspacesProject::Application, LaunchingAppState>;
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
<ClInclude Include="StringUtils.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
<ClInclude Include="WbemHelper.h" />
|
||||
<ClInclude Include="WindowUtils.h" />
|
||||
<ClInclude Include="WorkspacesData.h" />
|
||||
<ClInclude Include="trace.h" />
|
||||
</ItemGroup>
|
||||
@@ -59,8 +60,10 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="PwaHelper.cpp" />
|
||||
<ClCompile Include="SteamGameHelper.cpp" />
|
||||
<ClCompile Include="StringUtils.cpp" />
|
||||
<ClCompile Include="two_way_pipe_message_ipc.cpp" />
|
||||
<ClCompile Include="WbemHelper.cpp" />
|
||||
<ClCompile Include="WindowUtils.cpp" />
|
||||
<ClCompile Include="WorkspacesData.cpp" />
|
||||
<ClCompile Include="trace.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
<ClInclude Include="SteamHelper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="WindowUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@@ -94,6 +97,12 @@
|
||||
<ClCompile Include="SteamGameHelper.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WindowUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StringUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <WorkspacesLib/AppUtils.h>
|
||||
#include <WorkspacesLib/PwaHelper.h>
|
||||
#include <WorkspacesLib/WindowUtils.h>
|
||||
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
||||
|
||||
#include "Generated Files/resource.h"
|
||||
@@ -139,7 +140,7 @@ namespace SnapshotUtils
|
||||
bool isChrome = appData.IsChrome();
|
||||
if (isEdge || isChrome)
|
||||
{
|
||||
auto windowAumid = pwaHelper.GetAUMIDFromWindow(window);
|
||||
auto windowAumid = Utils::GetAUMIDFromWindow(window);
|
||||
std::optional<std::wstring> pwaAppId{};
|
||||
|
||||
if (isEdge)
|
||||
@@ -158,6 +159,8 @@ namespace SnapshotUtils
|
||||
|
||||
appData.pwaAppId = pwaAppId.value();
|
||||
appData.name = pwaName + L" (" + appData.name + L")";
|
||||
// If it's pwa app, appUserModelId should be their own pwa id.
|
||||
appData.appUserModelId = windowAumid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +188,7 @@ namespace SnapshotUtils
|
||||
.appUserModelId = appData.appUserModelId,
|
||||
.pwaAppId = appData.pwaAppId,
|
||||
.commandLineArgs = L"",
|
||||
.version = L"1",
|
||||
.isElevated = IsProcessElevated(pid),
|
||||
.canLaunchElevated = appData.canLaunchElevated,
|
||||
.isMinimized = isMinimized,
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
||||
#include <WorkspacesLib/PwaHelper.h>
|
||||
#include <WorkspacesLib/WindowUtils.h>
|
||||
|
||||
namespace NonLocalizable
|
||||
{
|
||||
@@ -203,7 +204,7 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa
|
||||
|
||||
if (!data->IsSteamGame() && !WindowUtils::HasThickFrame(window))
|
||||
{
|
||||
// Only care about steam games if it has no thick frame to remain consistent with
|
||||
// Only care about steam games if it has no thick frame to remain consistent with
|
||||
// the behavior as before.
|
||||
continue;
|
||||
}
|
||||
@@ -220,7 +221,7 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa
|
||||
bool isChrome = appData.IsChrome();
|
||||
if (isEdge || isChrome)
|
||||
{
|
||||
auto windowAumid = pwaHelper.GetAUMIDFromWindow(window);
|
||||
auto windowAumid = Utils::GetAUMIDFromWindow(window);
|
||||
std::optional<std::wstring> pwaAppId{};
|
||||
|
||||
if (isEdge)
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</trustInfo>
|
||||
<application>
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">per monitor</dpiAware>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
||||
<dpiAware>true</dpiAware>
|
||||
<asmv3:windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
@@ -6,9 +6,9 @@
|
||||
<PackageVersion Include="Microsoft.CommandPalette.Extensions" Version="0.2.0" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0-preview.24508.2" />
|
||||
<PackageVersion Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
|
||||
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.2.46-beta" />
|
||||
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.183" />
|
||||
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
|
||||
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.4188" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.7.250513003" />
|
||||
<PackageVersion Include="Shmuelie.WinRTServer" Version="2.1.1" />
|
||||
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<RootNamespace>TemplateCmdPalExtension</RootNamespace>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
|
||||
<WindowsSdkPackageVersion>10.0.22621.57</WindowsSdkPackageVersion>
|
||||
<TargetFramework>net9.0-windows10.0.22621.0</TargetFramework>
|
||||
<WindowsSdkPackageVersion>10.0.26100.68-preview</WindowsSdkPackageVersion>
|
||||
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
|
||||
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
@@ -107,17 +107,17 @@ public class ExtensionWrapper : IExtensionWrapper
|
||||
{
|
||||
Logger.LogDebug($"Starting {ExtensionDisplayName} ({ExtensionClassId})");
|
||||
|
||||
var extensionPtr = nint.Zero;
|
||||
try
|
||||
unsafe
|
||||
{
|
||||
// -2147024809: E_INVALIDARG
|
||||
// -2147467262: E_NOINTERFACE
|
||||
// -2147024893: E_PATH_NOT_FOUND
|
||||
var guid = typeof(IExtension).GUID;
|
||||
|
||||
unsafe
|
||||
var extensionPtr = (void*)nint.Zero;
|
||||
try
|
||||
{
|
||||
var hr = PInvoke.CoCreateInstance(Guid.Parse(ExtensionClassId), null, CLSCTX.CLSCTX_LOCAL_SERVER, guid, out var extensionObj);
|
||||
// -2147024809: E_INVALIDARG
|
||||
// -2147467262: E_NOINTERFACE
|
||||
// -2147024893: E_PATH_NOT_FOUND
|
||||
var guid = typeof(IExtension).GUID;
|
||||
|
||||
var hr = PInvoke.CoCreateInstance(Guid.Parse(ExtensionClassId), null, CLSCTX.CLSCTX_LOCAL_SERVER, guid, out extensionPtr);
|
||||
|
||||
if (hr.Value == -2147024893)
|
||||
{
|
||||
@@ -128,28 +128,19 @@ public class ExtensionWrapper : IExtensionWrapper
|
||||
return;
|
||||
}
|
||||
|
||||
extensionPtr = Marshal.GetIUnknownForObject((nint)extensionObj);
|
||||
if (hr < 0)
|
||||
{
|
||||
Logger.LogDebug($"Failed to instantiate {ExtensionDisplayName}: {hr}");
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
}
|
||||
|
||||
// extensionPtr = Marshal.GetIUnknownForObject(extensionObj);
|
||||
extensionPtr = (nint)extensionObj;
|
||||
if (hr < 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
}
|
||||
|
||||
_extensionObject = MarshalInterface<IExtension>.FromAbi(extensionPtr);
|
||||
// Marshal.ThrowExceptionForHR(hr);
|
||||
_extensionObject = MarshalInterface<IExtension>.FromAbi((nint)extensionPtr);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (extensionPtr != nint.Zero)
|
||||
catch (Exception e)
|
||||
{
|
||||
Marshal.Release(extensionPtr);
|
||||
Logger.LogDebug($"Failed to start {ExtensionDisplayName}. ex: {e.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ((nint)extensionPtr != nint.Zero)
|
||||
{
|
||||
Marshal.Release((nint)extensionPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ using Microsoft.CmdPal.Common.Services;
|
||||
using Microsoft.CmdPal.Ext.Apps;
|
||||
using Microsoft.CmdPal.Ext.Bookmarks;
|
||||
using Microsoft.CmdPal.Ext.Calc;
|
||||
using Microsoft.CmdPal.Ext.ClipboardHistory;
|
||||
using Microsoft.CmdPal.Ext.Indexer;
|
||||
using Microsoft.CmdPal.Ext.Registry;
|
||||
using Microsoft.CmdPal.Ext.Shell;
|
||||
@@ -103,7 +102,6 @@ public partial class App : Application
|
||||
services.AddSingleton<ICommandProvider, IndexerCommandsProvider>();
|
||||
services.AddSingleton<ICommandProvider, BookmarksCommandProvider>();
|
||||
|
||||
services.AddSingleton<ICommandProvider, ClipboardHistoryCommandsProvider>();
|
||||
services.AddSingleton<ICommandProvider, WindowWalkerCommandsProvider>();
|
||||
services.AddSingleton<ICommandProvider, WebSearchCommandsProvider>();
|
||||
|
||||
|
||||
@@ -57,7 +57,11 @@ public sealed partial class MainWindow : WindowEx,
|
||||
InitializeComponent();
|
||||
|
||||
_hwnd = new HWND(WinRT.Interop.WindowNative.GetWindowHandle(this).ToInt32());
|
||||
CommandPaletteHost.SetHostHwnd((ulong)_hwnd.Value);
|
||||
|
||||
unsafe
|
||||
{
|
||||
CommandPaletteHost.SetHostHwnd((ulong)_hwnd.Value);
|
||||
}
|
||||
|
||||
_keyboardListener = new KeyboardListener();
|
||||
_keyboardListener.Start();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<PropertyGroup Condition="'$(CIBuild)'=='true'">
|
||||
<GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -122,7 +122,6 @@
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Apps\Microsoft.CmdPal.Ext.Apps.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Bookmark\Microsoft.CmdPal.Ext.Bookmarks.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Calc\Microsoft.CmdPal.Ext.Calc.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.ClipboardHistory\Microsoft.CmdPal.Ext.ClipboardHistory.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Registry\Microsoft.CmdPal.Ext.Registry.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Shell\Microsoft.CmdPal.Ext.Shell.csproj" />
|
||||
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.TimeDate\Microsoft.CmdPal.Ext.TimeDate.csproj" />
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<AppContainerApplication>false</AppContainerApplication>
|
||||
<ApplicationType>Windows Store</ApplicationType>
|
||||
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
||||
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.22621.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.26100.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.19041.0</WindowsTargetPlatformMinVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<XesUseOneStoreVersioning>true</XesUseOneStoreVersioning>
|
||||
<XesBaseYearForStoreVersion>2025</XesBaseYearForStoreVersion>
|
||||
<VersionMajor>0</VersionMajor>
|
||||
<VersionMinor>2</VersionMinor>
|
||||
<VersionMinor>3</VersionMinor>
|
||||
<VersionInfoProductName>Microsoft Command Palette</VersionInfoProductName>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<PackageReference Include="WyHash" />
|
||||
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCsWin32\ManagedCsWin32.csproj" />
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Apps.Programs;
|
||||
|
||||
@@ -36,118 +34,6 @@ public static partial class ReparsePoint
|
||||
private const int E_INVALID_PROTOCOL_FORMAT = unchecked((int)0x83760002);
|
||||
#pragma warning restore SA1310 // Field names should not contain underscore
|
||||
|
||||
[Flags]
|
||||
internal enum FileAccessType : uint
|
||||
{
|
||||
DELETE = 0x00010000,
|
||||
READ_CONTROL = 0x00020000,
|
||||
WRITE_DAC = 0x00040000,
|
||||
WRITE_OWNER = 0x00080000,
|
||||
SYNCHRONIZE = 0x00100000,
|
||||
|
||||
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
|
||||
|
||||
STANDARD_RIGHTS_READ = READ_CONTROL,
|
||||
STANDARD_RIGHTS_WRITE = READ_CONTROL,
|
||||
STANDARD_RIGHTS_EXECUTE = READ_CONTROL,
|
||||
|
||||
STANDARD_RIGHTS_ALL = 0x001F0000,
|
||||
|
||||
SPECIFIC_RIGHTS_ALL = 0x0000FFFF,
|
||||
|
||||
ACCESS_SYSTEM_SECURITY = 0x01000000,
|
||||
|
||||
MAXIMUM_ALLOWED = 0x02000000,
|
||||
|
||||
GENERIC_READ = 0x80000000,
|
||||
GENERIC_WRITE = 0x40000000,
|
||||
GENERIC_EXECUTE = 0x20000000,
|
||||
GENERIC_ALL = 0x10000000,
|
||||
|
||||
FILE_READ_DATA = 0x0001,
|
||||
FILE_WRITE_DATA = 0x0002,
|
||||
FILE_APPEND_DATA = 0x0004,
|
||||
FILE_READ_EA = 0x0008,
|
||||
FILE_WRITE_EA = 0x0010,
|
||||
FILE_EXECUTE = 0x0020,
|
||||
FILE_READ_ATTRIBUTES = 0x0080,
|
||||
FILE_WRITE_ATTRIBUTES = 0x0100,
|
||||
|
||||
FILE_ALL_ACCESS =
|
||||
STANDARD_RIGHTS_REQUIRED |
|
||||
SYNCHRONIZE
|
||||
| 0x1FF,
|
||||
|
||||
FILE_GENERIC_READ =
|
||||
STANDARD_RIGHTS_READ |
|
||||
FILE_READ_DATA |
|
||||
FILE_READ_ATTRIBUTES |
|
||||
FILE_READ_EA |
|
||||
SYNCHRONIZE,
|
||||
|
||||
FILE_GENERIC_WRITE =
|
||||
STANDARD_RIGHTS_WRITE |
|
||||
FILE_WRITE_DATA |
|
||||
FILE_WRITE_ATTRIBUTES |
|
||||
FILE_WRITE_EA |
|
||||
FILE_APPEND_DATA |
|
||||
SYNCHRONIZE,
|
||||
|
||||
FILE_GENERIC_EXECUTE =
|
||||
STANDARD_RIGHTS_EXECUTE |
|
||||
FILE_READ_ATTRIBUTES |
|
||||
FILE_EXECUTE |
|
||||
SYNCHRONIZE,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum FileShareType : uint
|
||||
{
|
||||
None = 0x00000000,
|
||||
Read = 0x00000001,
|
||||
Write = 0x00000002,
|
||||
Delete = 0x00000004,
|
||||
}
|
||||
|
||||
internal enum CreationDisposition : uint
|
||||
{
|
||||
New = 1,
|
||||
CreateAlways = 2,
|
||||
OpenExisting = 3,
|
||||
OpenAlways = 4,
|
||||
TruncateExisting = 5,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum FileAttributes : uint
|
||||
{
|
||||
Readonly = 0x00000001,
|
||||
Hidden = 0x00000002,
|
||||
System = 0x00000004,
|
||||
Directory = 0x00000010,
|
||||
Archive = 0x00000020,
|
||||
Device = 0x00000040,
|
||||
Normal = 0x00000080,
|
||||
Temporary = 0x00000100,
|
||||
SparseFile = 0x00000200,
|
||||
ReparsePoint = 0x00000400,
|
||||
Compressed = 0x00000800,
|
||||
Offline = 0x00001000,
|
||||
NotContentIndexed = 0x00002000,
|
||||
Encrypted = 0x00004000,
|
||||
Write_Through = 0x80000000,
|
||||
Overlapped = 0x40000000,
|
||||
NoBuffering = 0x20000000,
|
||||
RandomAccess = 0x10000000,
|
||||
SequentialScan = 0x08000000,
|
||||
DeleteOnClose = 0x04000000,
|
||||
BackupSemantics = 0x02000000,
|
||||
PosixSemantics = 0x01000000,
|
||||
OpenReparsePoint = 0x00200000,
|
||||
OpenNoRecall = 0x00100000,
|
||||
FirstPipeInstance = 0x00080000,
|
||||
}
|
||||
|
||||
private enum AppExecutionAliasReparseTagBufferLayoutVersion : uint
|
||||
{
|
||||
Invalid = 0,
|
||||
@@ -196,28 +82,6 @@ public static partial class ReparsePoint
|
||||
public AppExecutionAliasReparseTagBufferLayoutVersion Version;
|
||||
}
|
||||
|
||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static partial bool DeviceIoControl(
|
||||
IntPtr hDevice,
|
||||
uint dwIoControlCode,
|
||||
IntPtr inBuffer,
|
||||
int nInBufferSize,
|
||||
IntPtr outBuffer,
|
||||
int nOutBufferSize,
|
||||
out int pBytesReturned,
|
||||
IntPtr lpOverlapped);
|
||||
|
||||
[LibraryImport("kernel32.dll", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
|
||||
internal static partial int CreateFile(
|
||||
string lpFileName,
|
||||
FileAccessType dwDesiredAccess,
|
||||
FileShareType dwShareMode,
|
||||
IntPtr lpSecurityAttributes,
|
||||
CreationDisposition dwCreationDisposition,
|
||||
FileAttributes dwFlagsAndAttributes,
|
||||
IntPtr hTemplateFile);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target of the specified reparse point.
|
||||
/// </summary>
|
||||
@@ -231,13 +95,13 @@ public static partial class ReparsePoint
|
||||
public static string? GetTarget(string reparsePoint)
|
||||
{
|
||||
using (SafeFileHandle reparsePointHandle = new SafeFileHandle(
|
||||
CreateFile(
|
||||
Kernel32.CreateFile(
|
||||
reparsePoint,
|
||||
FileAccessType.FILE_READ_ATTRIBUTES | FileAccessType.FILE_READ_EA,
|
||||
FileShareType.Delete | FileShareType.Read | FileShareType.Write,
|
||||
IntPtr.Zero,
|
||||
CreationDisposition.OpenExisting,
|
||||
FileAttributes.OpenReparsePoint,
|
||||
ManagedCsWin32.FileAttributes.OpenReparsePoint,
|
||||
IntPtr.Zero),
|
||||
true))
|
||||
{
|
||||
@@ -255,7 +119,7 @@ public static partial class ReparsePoint
|
||||
for (var i = 0; i < 2; ++i)
|
||||
{
|
||||
int bytesReturned;
|
||||
var result = DeviceIoControl(
|
||||
var result = Kernel32.DeviceIoControl(
|
||||
reparsePointHandle.DangerousGetHandle(),
|
||||
FSCTL_GET_REPARSE_POINT,
|
||||
IntPtr.Zero,
|
||||
|
||||
@@ -221,11 +221,10 @@ public class UWPApplication : IProgram
|
||||
var capacity = 1024U;
|
||||
PWSTR outBuffer = new PWSTR((char*)(void*)Marshal.AllocHGlobal((int)capacity * sizeof(char)));
|
||||
var source = $"@{{{packageFullName}? {parsed}}}";
|
||||
void* reserved = null;
|
||||
|
||||
try
|
||||
{
|
||||
PInvoke.SHLoadIndirectString(source, outBuffer, capacity, ref reserved).ThrowOnFailure();
|
||||
PInvoke.SHLoadIndirectString(source, outBuffer.AsSpan()).ThrowOnFailure();
|
||||
|
||||
var loaded = outBuffer.ToString();
|
||||
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
|
||||
@@ -235,7 +234,7 @@ public class UWPApplication : IProgram
|
||||
try
|
||||
{
|
||||
var sourceFallback = $"@{{{packageFullName}?{parsedFallback}}}";
|
||||
PInvoke.SHLoadIndirectString(sourceFallback, outBuffer, capacity, ref reserved).ThrowOnFailure();
|
||||
PInvoke.SHLoadIndirectString(sourceFallback, outBuffer.AsSpan()).ThrowOnFailure();
|
||||
var loaded = outBuffer.ToString();
|
||||
return string.IsNullOrEmpty(loaded) ? string.Empty : loaded;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ManagedCsWin32;
|
||||
using WinRT;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Data;
|
||||
|
||||
internal static class ActionRuntimeFactory
|
||||
{
|
||||
private const string ActionRuntimeClsidStr = "C36FEF7E-35F3-4192-9F2C-AF1FD425FB85";
|
||||
|
||||
// typeof(Windows.AI.Actions.IActionRuntime).GUID
|
||||
private static readonly Guid IActionRuntimeIID = Guid.Parse("206EFA2C-C909-508A-B4B0-9482BE96DB9C");
|
||||
|
||||
public static unsafe global::Windows.AI.Actions.ActionRuntime CreateActionRuntime()
|
||||
{
|
||||
IntPtr abiPtr = default;
|
||||
try
|
||||
{
|
||||
Guid classId = Guid.Parse(ActionRuntimeClsidStr);
|
||||
Guid iid = IActionRuntimeIID;
|
||||
|
||||
var hresult = Ole32.CoCreateInstance(ref Unsafe.AsRef(in classId), IntPtr.Zero, CLSCTX.LocalServer, ref iid, out abiPtr);
|
||||
Marshal.ThrowExceptionForHR((int)hresult);
|
||||
|
||||
return MarshalInterface<global::Windows.AI.Actions.ActionRuntime>.FromAbi(abiPtr);
|
||||
}
|
||||
finally
|
||||
{
|
||||
MarshalInspectable<object>.DisposeAbi(abiPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.AI.Actions.Hosting;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
|
||||
internal sealed partial class ExecuteActionCommand : InvokableCommand
|
||||
{
|
||||
private readonly ActionInstance actionInstance;
|
||||
|
||||
internal ExecuteActionCommand(ActionInstance actionInstance)
|
||||
{
|
||||
this.actionInstance = actionInstance;
|
||||
this.Name = actionInstance.DisplayInfo.Description;
|
||||
this.Icon = new IconInfo(actionInstance.Definition.IconFullPath);
|
||||
}
|
||||
|
||||
public override CommandResult Invoke()
|
||||
{
|
||||
var task = Task.Run(InvokeAsync);
|
||||
task.Wait();
|
||||
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
private async Task<CommandResult> InvokeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await actionInstance.InvokeAsync();
|
||||
return CommandResult.GoHome();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return CommandResult.ShowToast("Failed to invoke action " + actionInstance.Definition.Id + ": " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,14 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Data;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.UI.Shell;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
using static Microsoft.CmdPal.Ext.Indexer.Native.NativeMethods;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
|
||||
@@ -29,16 +25,16 @@ internal sealed partial class OpenPropertiesCommand : InvokableCommand
|
||||
|
||||
try
|
||||
{
|
||||
var info = new SHELLEXECUTEINFOW
|
||||
var info = new Shell32.SHELLEXECUTEINFOW
|
||||
{
|
||||
cbSize = (uint)sizeof(SHELLEXECUTEINFOW),
|
||||
lpVerb = propertiesPtr,
|
||||
lpFile = filenamePtr,
|
||||
nShow = (int)SHOW_WINDOW_CMD.SW_SHOW,
|
||||
fMask = NativeHelpers.SEEMASKINVOKEIDLIST,
|
||||
CbSize = (uint)sizeof(Shell32.SHELLEXECUTEINFOW),
|
||||
LpVerb = propertiesPtr,
|
||||
LpFile = filenamePtr,
|
||||
Show = (int)SHOW_WINDOW_CMD.SW_SHOW,
|
||||
FMask = NativeHelpers.SEEMASKINVOKEIDLIST,
|
||||
};
|
||||
|
||||
return ShellExecuteEx(ref info);
|
||||
return Shell32.ShellExecuteEx(ref info);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -2,18 +2,13 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Data;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.UI.Shell;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
using static Microsoft.CmdPal.Ext.Indexer.Native.NativeMethods;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
|
||||
@@ -28,16 +23,16 @@ internal sealed partial class OpenWithCommand : InvokableCommand
|
||||
|
||||
try
|
||||
{
|
||||
var info = new SHELLEXECUTEINFOW
|
||||
var info = new Shell32.SHELLEXECUTEINFOW
|
||||
{
|
||||
cbSize = (uint)sizeof(SHELLEXECUTEINFOW),
|
||||
lpVerb = verbPtr,
|
||||
lpFile = filenamePtr,
|
||||
nShow = (int)SHOW_WINDOW_CMD.SW_SHOWNORMAL,
|
||||
fMask = NativeHelpers.SEEMASKINVOKEIDLIST,
|
||||
CbSize = (uint)sizeof(Shell32.SHELLEXECUTEINFOW),
|
||||
LpVerb = verbPtr,
|
||||
LpFile = filenamePtr,
|
||||
Show = (int)SHOW_WINDOW_CMD.SW_SHOWNORMAL,
|
||||
FMask = NativeHelpers.SEEMASKINVOKEIDLIST,
|
||||
};
|
||||
|
||||
return ShellExecuteEx(ref info);
|
||||
return Shell32.ShellExecuteEx(ref info);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Pages;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Foundation.Metadata;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Data;
|
||||
|
||||
@@ -38,9 +41,24 @@ internal sealed partial class IndexerListItem : ListItem
|
||||
}
|
||||
}
|
||||
|
||||
MoreCommands = [
|
||||
IContextItem[] moreCommands = [
|
||||
..context,
|
||||
new CommandContextItem(new OpenWithCommand(indexerItem)),
|
||||
new CommandContextItem(new OpenWithCommand(indexerItem))];
|
||||
|
||||
if (ApiInformation.IsApiContractPresent("Windows.AI.Actions.ActionsContract", 4))
|
||||
{
|
||||
var actionsListContextItem = new ActionsListContextItem(indexerItem.FullPath);
|
||||
if (actionsListContextItem.AnyActions())
|
||||
{
|
||||
moreCommands = [
|
||||
.. moreCommands,
|
||||
actionsListContextItem
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
MoreCommands = [
|
||||
.. moreCommands,
|
||||
new CommandContextItem(new ShowFileInFolderCommand(indexerItem.FullPath) { Name = Resources.Indexer_Command_ShowInFolder }),
|
||||
new CommandContextItem(new CopyPathCommand(indexerItem)),
|
||||
new CommandContextItem(new OpenInConsoleCommand(indexerItem)),
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
|
||||
|
||||
@@ -29,35 +27,19 @@ internal static class DataSourceManager
|
||||
private static bool InitializeDataSource()
|
||||
{
|
||||
var riid = typeof(IDBInitialize).GUID;
|
||||
var hr = NativeMethods.CoCreateInstance(ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.CLSIDCollatorDataSource), IntPtr.Zero, NativeHelpers.CLSCTXINPROCALL, ref riid, out var dataSourceObjPtr);
|
||||
if (hr != 0)
|
||||
|
||||
try
|
||||
{
|
||||
Logger.LogError("CoCreateInstance failed: " + hr);
|
||||
return false;
|
||||
_dataSource = ComHelper.CreateComInstance<IDBInitialize>(ref Unsafe.AsRef(in CLSID.CollatorDataSource), CLSCTX.InProcServer);
|
||||
}
|
||||
|
||||
if (dataSourceObjPtr == IntPtr.Zero)
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("CoCreateInstance failed: dataSourceObjPtr is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
var comWrappers = new StrategyBasedComWrappers();
|
||||
_dataSource = (IDBInitialize)comWrappers.GetOrCreateObjectForComInstance(dataSourceObjPtr, CreateObjectFlags.None);
|
||||
|
||||
if (_dataSource == null)
|
||||
{
|
||||
Logger.LogError("CoCreateInstance failed: dataSourceObj is null");
|
||||
Logger.LogError($"Failed to create datasource. ex: {e.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
_dataSource.Initialize();
|
||||
|
||||
if (dataSourceObjPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.Release(dataSourceObjPtr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
using Windows.Win32.Storage.IndexServer;
|
||||
using Windows.Win32.System.Com.StructuredStorage;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
|
||||
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.OleDB;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
using static Microsoft.CmdPal.Ext.Indexer.Native.NativeHelpers;
|
||||
using static Microsoft.CmdPal.Ext.Indexer.Indexer.Utils.NativeHelpers;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
|
||||
|
||||
@@ -143,9 +144,7 @@ internal sealed partial class SearchQuery : IDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
var riid = CsWin32GUID.PropertyStore;
|
||||
|
||||
getRow.GetRowFromHROW(null, rowHandle, ref riid, out var propertyStore);
|
||||
getRow.GetRowFromHROW(null, rowHandle, ref Unsafe.AsRef(in IID.IPropertyStore), out var propertyStore);
|
||||
|
||||
if (propertyStore == null)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Runtime.InteropServices;
|
||||
using ManagedCommon;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
|
||||
|
||||
|
||||
@@ -3,13 +3,8 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
|
||||
public sealed partial class NativeHelpers
|
||||
{
|
||||
public const uint SEEMASKINVOKEIDLIST = 12;
|
||||
|
||||
public struct PropertyKeys
|
||||
{
|
||||
public static readonly PropertyKey PKEYItemNameDisplay = new() { FmtID = new Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), PID = 10 };
|
||||
public static readonly PropertyKey PKEYItemUrl = new() { FmtID = new Guid("49691C90-7E17-101A-A91C-08002B2ECDA9"), PID = 9 };
|
||||
public static readonly PropertyKey PKEYKindText = new() { FmtID = new Guid("F04BEF95-C585-4197-A2B7-DF46FDC9EE6D"), PID = 100 };
|
||||
}
|
||||
|
||||
public static class OleDb
|
||||
{
|
||||
public static readonly Guid DbGuidDefault = new("C8B521FB-5CF3-11CE-ADE5-00AA0044773D");
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,9 @@ using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Indexer.Utils;
|
||||
|
||||
@@ -29,21 +30,16 @@ internal sealed partial class QueryStringBuilder
|
||||
{
|
||||
if (queryHelper == null)
|
||||
{
|
||||
ComWrappers cw = new StrategyBasedComWrappers();
|
||||
var searchManagerPtr = IntPtr.Zero;
|
||||
ISearchManager searchManager;
|
||||
|
||||
var hr = NativeMethods.CoCreateInstance(ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.CLSIDSearchManager), IntPtr.Zero, NativeHelpers.CLSCTXINPROCALL, ref Unsafe.AsRef(in NativeHelpers.CsWin32GUID.IIDISearchManager), out searchManagerPtr);
|
||||
if (hr != 0)
|
||||
try
|
||||
{
|
||||
throw new ArgumentException($"Failed to create SearchManager instance. HR: 0x{hr:X}");
|
||||
searchManager = ComHelper.CreateComInstance<ISearchManager>(ref Unsafe.AsRef(in CLSID.SearchManager), CLSCTX.LocalServer);
|
||||
}
|
||||
|
||||
var searchManager = (ISearchManager)cw.GetOrCreateObjectForComInstance(
|
||||
searchManagerPtr, CreateObjectFlags.None);
|
||||
|
||||
if (searchManager == null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ArgumentException("Failed to get ISearchManager interface");
|
||||
Logger.LogError($"Failed to create searchManager. ex: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
|
||||
ISearchCatalogManager catalogManager = searchManager.GetCatalog(SystemIndex);
|
||||
@@ -52,11 +48,6 @@ internal sealed partial class QueryStringBuilder
|
||||
throw new ArgumentException($"Failed to get catalog manager for {SystemIndex}");
|
||||
}
|
||||
|
||||
if (searchManagerPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.Release(searchManagerPtr);
|
||||
}
|
||||
|
||||
queryHelper = catalogManager.GetQueryHelper();
|
||||
if (queryHelper == null)
|
||||
{
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCsWin32\ManagedCsWin32.csproj" />
|
||||
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -34,6 +35,9 @@
|
||||
<Content Update="Assets\FileExplorer.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="Assets\Actions.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="Assets\FileExplorer.svg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
public sealed partial class NativeHelpers
|
||||
{
|
||||
public const uint SEEMASKINVOKEIDLIST = 12;
|
||||
|
||||
public const uint CLSCTXINPROCALL = 0x17;
|
||||
|
||||
public struct PropertyKeys
|
||||
{
|
||||
public static readonly PropertyKey PKEYItemNameDisplay = new() { FmtID = new System.Guid("B725F130-47EF-101A-A5F1-02608C9EEBAC"), PID = 10 };
|
||||
public static readonly PropertyKey PKEYItemUrl = new() { FmtID = new System.Guid("49691C90-7E17-101A-A91C-08002B2ECDA9"), PID = 9 };
|
||||
public static readonly PropertyKey PKEYKindText = new() { FmtID = new System.Guid("F04BEF95-C585-4197-A2B7-DF46FDC9EE6D"), PID = 100 };
|
||||
}
|
||||
|
||||
public static class OleDb
|
||||
{
|
||||
public static readonly Guid DbGuidDefault = new("C8B521FB-5CF3-11CE-ADE5-00AA0044773D");
|
||||
}
|
||||
|
||||
public static class CsWin32GUID
|
||||
{
|
||||
public static readonly Guid CLSIDSearchManager = new Guid("7D096C5F-AC08-4F1F-BEB7-5C22C517CE39");
|
||||
public static readonly Guid IIDISearchManager = new Guid("AB310581-AC80-11D1-8DF3-00C04FB6EF69");
|
||||
public static readonly Guid CLSIDCollatorDataSource = new Guid("9E175B8B-F52A-11D8-B9A5-505054503030");
|
||||
public static readonly Guid PropertyStore = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using Windows.Win32.UI.Shell;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Native;
|
||||
|
||||
public sealed partial class NativeMethods
|
||||
{
|
||||
[LibraryImport("ole32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.U4)]
|
||||
public static partial uint CoCreateInstance(
|
||||
ref Guid rclsid,
|
||||
IntPtr pUnkOuter,
|
||||
uint dwClsContext,
|
||||
ref Guid riid,
|
||||
out IntPtr rReturnedComObject);
|
||||
|
||||
[LibraryImport("SHELL32.dll", EntryPoint = "ShellExecuteExW", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static partial bool ShellExecuteEx(ref SHELLEXECUTEINFOW lpExecInfo);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct SHELLEXECUTEINFOW
|
||||
{
|
||||
public uint cbSize;
|
||||
public uint fMask;
|
||||
public IntPtr hwnd;
|
||||
|
||||
public IntPtr lpVerb;
|
||||
public IntPtr lpFile;
|
||||
public IntPtr lpParameters;
|
||||
public IntPtr lpDirectory;
|
||||
public int nShow;
|
||||
public IntPtr hInstApp;
|
||||
public IntPtr lpIDList;
|
||||
public IntPtr lpClass;
|
||||
public IntPtr hkeyClass;
|
||||
public uint dwHotKey;
|
||||
public IntPtr hIconOrMonitor;
|
||||
public IntPtr hProcess;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "https://aka.ms/CsWin32.schema.json",
|
||||
"allowMarshaling": false,
|
||||
"emitSingleFile": false,
|
||||
"public": true
|
||||
"comInterop": {
|
||||
"preserveSigMethods": [ "*" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Commands;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Data;
|
||||
using Microsoft.CmdPal.Ext.Indexer.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.AI.Actions;
|
||||
using Windows.System;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.Indexer.Pages;
|
||||
|
||||
internal sealed partial class ActionsListContextItem : CommandContextItem
|
||||
{
|
||||
private readonly string fullPath;
|
||||
private readonly List<CommandContextItem> actions = [];
|
||||
private static readonly Lock UpdateMoreCommandsLock = new();
|
||||
private static ActionRuntime actionRuntime;
|
||||
|
||||
public ActionsListContextItem(string fullPath)
|
||||
: base(new NoOpCommand())
|
||||
{
|
||||
Title = Resources.Indexer_Command_Actions;
|
||||
Icon = Icons.Actions;
|
||||
RequestedShortcut = KeyChordHelpers.FromModifiers(alt: true, vkey: VirtualKey.A);
|
||||
this.fullPath = fullPath;
|
||||
UpdateMoreCommands();
|
||||
}
|
||||
|
||||
public bool AnyActions() => actions.Count != 0;
|
||||
|
||||
private void ActionCatalog_Changed(global::Windows.AI.Actions.Hosting.ActionCatalog sender, object args)
|
||||
{
|
||||
UpdateMoreCommands();
|
||||
}
|
||||
|
||||
private void UpdateMoreCommands()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (UpdateMoreCommandsLock)
|
||||
{
|
||||
if (actionRuntime == null)
|
||||
{
|
||||
actionRuntime = ActionRuntimeFactory.CreateActionRuntime();
|
||||
Task.Delay(500).Wait();
|
||||
}
|
||||
|
||||
actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed;
|
||||
actionRuntime.ActionCatalog.Changed += ActionCatalog_Changed;
|
||||
}
|
||||
|
||||
var extension = System.IO.Path.GetExtension(fullPath).ToLower(CultureInfo.InvariantCulture);
|
||||
ActionEntity entity = null;
|
||||
if (extension != null)
|
||||
{
|
||||
if (extension == ".jpg" || extension == ".jpeg" || extension == ".png")
|
||||
{
|
||||
entity = actionRuntime.EntityFactory.CreatePhotoEntity(fullPath);
|
||||
}
|
||||
else if (extension == ".docx" || extension == ".doc" || extension == ".pdf" || extension == ".txt")
|
||||
{
|
||||
entity = actionRuntime.EntityFactory.CreateDocumentEntity(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = actionRuntime.EntityFactory.CreateFileEntity(fullPath);
|
||||
}
|
||||
|
||||
lock (actions)
|
||||
{
|
||||
actions.Clear();
|
||||
foreach (var actionInstance in actionRuntime.ActionCatalog.GetActionsForInputs([entity]))
|
||||
{
|
||||
actions.Add(new CommandContextItem(new ExecuteActionCommand(actionInstance)));
|
||||
}
|
||||
|
||||
MoreCommands = [.. actions];
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
actionRuntime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ internal sealed class Icons
|
||||
|
||||
internal static IconInfo FileExplorer { get; } = IconHelpers.FromRelativePath("Assets\\FileExplorer.png");
|
||||
|
||||
internal static IconInfo Actions { get; } = IconHelpers.FromRelativePath("Assets\\Actions.png");
|
||||
|
||||
internal static IconInfo OpenFile { get; } = new("\uE8E5"); // OpenFile
|
||||
|
||||
internal static IconInfo Document { get; } = new("\uE8A5"); // Document
|
||||
|
||||
@@ -60,6 +60,15 @@ namespace Microsoft.CmdPal.Ext.Indexer.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Actions.
|
||||
/// </summary>
|
||||
internal static string Indexer_Command_Actions {
|
||||
get {
|
||||
return ResourceManager.GetString("Indexer_Command_Actions", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Browse.
|
||||
/// </summary>
|
||||
|
||||
@@ -138,6 +138,9 @@
|
||||
<data name="Indexer_Command_OpenWith" xml:space="preserve">
|
||||
<value>Open with</value>
|
||||
</data>
|
||||
<data name="Indexer_Command_Actions" xml:space="preserve">
|
||||
<value>Actions...</value>
|
||||
</data>
|
||||
<data name="Indexer_Command_ShowInFolder" xml:space="preserve">
|
||||
<value>Show in folder</value>
|
||||
</data>
|
||||
|
||||
@@ -110,6 +110,13 @@ internal static class Commands
|
||||
});
|
||||
}
|
||||
|
||||
results.Add(new ListItem(new ExecuteCommandConfirmation(Resources.Microsoft_plugin_sys_RestartShell_name!, confirmCommands, Resources.Microsoft_plugin_sys_RestartShell_confirmation!, static () => OpenInShellHelper.OpenInShell("cmd", "/C tskill explorer && start explorer", runWithHiddenWindow: true)))
|
||||
{
|
||||
Title = Resources.Microsoft_plugin_sys_RestartShell!,
|
||||
Subtitle = Resources.Microsoft_plugin_sys_RestartShell_description!,
|
||||
Icon = Icons.RestartShellIcon,
|
||||
});
|
||||
|
||||
// UEFI command/result. It is only available on systems booted in UEFI mode.
|
||||
if (isUefi)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,8 @@ public static partial class Icons
|
||||
|
||||
public static IconInfo RestartIcon { get; } = new IconInfo("\uE777");
|
||||
|
||||
public static IconInfo RestartShellIcon { get; } = new IconInfo("\uEC50");
|
||||
|
||||
public static IconInfo ShutdownIcon { get; } = new IconInfo("\uE7E8");
|
||||
|
||||
public static IconInfo SleepIcon { get; } = new IconInfo("\uE708");
|
||||
|
||||
@@ -645,6 +645,42 @@ namespace Microsoft.CmdPal.Ext.System {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Restart Windows Explorer.
|
||||
/// </summary>
|
||||
public static string Microsoft_plugin_sys_RestartShell {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_RestartShell", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You are about to restart Windows Explorer, are you sure?.
|
||||
/// </summary>
|
||||
public static string Microsoft_plugin_sys_RestartShell_confirmation {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_RestartShell_confirmation", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to End and restart the Windows Explorer shell process.
|
||||
/// </summary>
|
||||
public static string Microsoft_plugin_sys_RestartShell_description {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_RestartShell_description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Restart.
|
||||
/// </summary>
|
||||
public static string Microsoft_plugin_sys_RestartShell_name {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_RestartShell_name", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to ip; mac; address.
|
||||
/// </summary>
|
||||
|
||||
@@ -417,4 +417,16 @@
|
||||
<data name="Microsoft_plugin_ext_fallback_display_title" xml:space="preserve">
|
||||
<value>Open System Command</value>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_RestartShell" xml:space="preserve">
|
||||
<value>Restart Windows Explorer</value>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_RestartShell_description" xml:space="preserve">
|
||||
<value>End and restart the Windows Explorer shell process</value>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_RestartShell_name" xml:space="preserve">
|
||||
<value>Restart</value>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_RestartShell_confirmation" xml:space="preserve">
|
||||
<value>You are about to restart Windows Explorer, are you sure?</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -68,6 +68,7 @@ internal sealed partial class FallbackTimeDateItem : FallbackCommandItem
|
||||
Title = result.Title;
|
||||
Subtitle = result.Subtitle;
|
||||
Icon = result.Icon;
|
||||
Command = result.Command;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Microsoft.CmdPal.Ext.TimeDate</RootNamespace>
|
||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\WinUI3Apps\CmdPal</OutputPath>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||
@@ -32,8 +33,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="Assets\TimeDate.png" />
|
||||
<None Remove="Assets\TimeDate.png" />
|
||||
<None Remove="Assets\TimeDate.svg" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="Assets\TimeDate.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using ManagedCommon;
|
||||
@@ -78,8 +79,11 @@ public static class DefaultBrowserInfo
|
||||
try
|
||||
{
|
||||
var progId = GetRegistryValue(
|
||||
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
|
||||
"ProgId");
|
||||
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoiceLatest\ProgId",
|
||||
"ProgId")
|
||||
?? GetRegistryValue(
|
||||
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
|
||||
"ProgId");
|
||||
var appName = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\Application", "ApplicationName")
|
||||
?? GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}", "FriendlyTypeName");
|
||||
|
||||
@@ -188,17 +192,20 @@ public static class DefaultBrowserInfo
|
||||
{
|
||||
var buffer = stackalloc char[128];
|
||||
var capacity = 128;
|
||||
void* reserved = null;
|
||||
var firstChar = str[0];
|
||||
var strPtr = &firstChar;
|
||||
|
||||
// S_OK == 0
|
||||
if (global::Windows.Win32.PInvoke.SHLoadIndirectString(
|
||||
str,
|
||||
fixed (char* pszSourceLocal = str)
|
||||
{
|
||||
if (global::Windows.Win32.PInvoke.SHLoadIndirectString(
|
||||
pszSourceLocal,
|
||||
buffer,
|
||||
(uint)capacity,
|
||||
ref reserved)
|
||||
== 0)
|
||||
{
|
||||
return new string(buffer);
|
||||
default) == 0)
|
||||
{
|
||||
return new string(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
@@ -98,15 +98,6 @@ public static partial class NativeMethods
|
||||
[DllImport("kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetFirmwareType(ref FirmwareType FirmwareType);
|
||||
|
||||
[LibraryImport("ole32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.U4)]
|
||||
public static partial uint CoCreateInstance(
|
||||
ref Guid rclsid,
|
||||
IntPtr pUnkOuter,
|
||||
uint dwClsContext,
|
||||
ref Guid riid,
|
||||
out IntPtr rReturnedComObject);
|
||||
}
|
||||
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "These are the names used by win32.")]
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using System.Text;
|
||||
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.WindowWalker.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Microsoft.Win32;
|
||||
@@ -49,10 +50,6 @@ public class VirtualDesktopHelper
|
||||
/// </summary>
|
||||
private readonly List<Guid> _availableDesktops = [];
|
||||
|
||||
#pragma warning disable SA1306 // Field names should begin with lower-case letter
|
||||
private readonly uint CLSCTXINPROCALL = 0x17;
|
||||
#pragma warning restore SA1306 // Field names should begin with lower-case letter
|
||||
|
||||
/// <summary>
|
||||
/// Id of the current visible Desktop.
|
||||
/// </summary>
|
||||
@@ -60,10 +57,6 @@ public class VirtualDesktopHelper
|
||||
|
||||
private static readonly CompositeFormat VirtualDesktopHelperDesktop = System.Text.CompositeFormat.Parse(Properties.Resources.VirtualDesktopHelper_Desktop);
|
||||
|
||||
private Guid iVirtualDesktopManagerCLSID = new("aa509086-5ca9-4c25-8f95-589d3c07b48a");
|
||||
|
||||
private Guid iVirtualDesktopManagerIID = new("a5cd92ff-29be-454c-8d04-d82879fb3f1b");
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VirtualDesktopHelper"/> class.
|
||||
/// </summary>
|
||||
@@ -71,30 +64,16 @@ public class VirtualDesktopHelper
|
||||
public VirtualDesktopHelper(bool desktopListUpdate = false)
|
||||
{
|
||||
var cw = new StrategyBasedComWrappers();
|
||||
var virtualDesktopManagerPtr = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
var hr = NativeMethods.CoCreateInstance(ref this.iVirtualDesktopManagerCLSID, nint.Zero, CLSCTXINPROCALL, ref iVirtualDesktopManagerIID, out virtualDesktopManagerPtr);
|
||||
if (hr != 0)
|
||||
{
|
||||
throw new ArgumentException($"Failed to create IVirtualDesktopManager instance. HR: 0x{hr:X}");
|
||||
}
|
||||
|
||||
_virtualDesktopManager = (IVirtualDesktopManager)cw.GetOrCreateObjectForComInstance(virtualDesktopManagerPtr, CreateObjectFlags.None);
|
||||
_virtualDesktopManager = ComHelper.CreateComInstance<IVirtualDesktopManager>(ref Unsafe.AsRef(in CLSID.VirtualDesktopManager), CLSCTX.InProcServer);
|
||||
}
|
||||
catch (COMException ex)
|
||||
{
|
||||
ExtensionHost.LogMessage(new LogMessage() { Message = $"Initialization of <VirtualDesktopHelper> failed: An exception was thrown when creating the instance of COM interface <IVirtualDesktopManager>. {ex} " });
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (virtualDesktopManagerPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.Release(virtualDesktopManagerPtr);
|
||||
}
|
||||
}
|
||||
|
||||
_isWindowsEleven = OSVersionHelper.IsWindows11();
|
||||
_desktopListAutoUpdate = desktopListUpdate;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\extensionsdk\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj" />
|
||||
<ProjectReference Include="..\..\..\..\common\ManagedCsWin32\ManagedCsWin32.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using ManagedCommon;
|
||||
using ManagedCsWin32;
|
||||
using Microsoft.CmdPal.Ext.WindowsTerminal.Helpers;
|
||||
using Microsoft.CmdPal.Ext.WindowsTerminal.Properties;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
@@ -63,22 +64,16 @@ internal sealed partial class LaunchProfileAsAdminCommand : InvokableCommand
|
||||
|
||||
private void Launch(string id, string profile)
|
||||
{
|
||||
ComWrappers cw = new StrategyBasedComWrappers();
|
||||
var appManagerPtr = IntPtr.Zero;
|
||||
IApplicationActivationManager appManager;
|
||||
|
||||
var hr = NativeHelpers.CoCreateInstance(ref Unsafe.AsRef(in NativeHelpers.ApplicationActivationManagerCLSID), IntPtr.Zero, NativeHelpers.CLSCTXINPROCALL, ref Unsafe.AsRef(in NativeHelpers.ApplicationActivationManagerIID), out appManagerPtr);
|
||||
|
||||
if (hr != 0)
|
||||
try
|
||||
{
|
||||
throw new ArgumentException($"Failed to create IApplicationActivationManager instance. HR: 0x{hr:X}");
|
||||
appManager = ComHelper.CreateComInstance<IApplicationActivationManager>(ref Unsafe.AsRef(in CLSID.ApplicationActivationManager), CLSCTX.InProcServer);
|
||||
}
|
||||
|
||||
var appManager = (IApplicationActivationManager)cw.GetOrCreateObjectForComInstance(
|
||||
appManagerPtr, CreateObjectFlags.None);
|
||||
|
||||
if (appManager == null)
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentException("Failed to get IApplicationActivationManager interface");
|
||||
Logger.LogError($"Failed to create IApplicationActivationManager instance. ex: {e.Message}");
|
||||
throw;
|
||||
}
|
||||
|
||||
const ActivateOptions noFlags = ActivateOptions.None;
|
||||
@@ -97,13 +92,6 @@ internal sealed partial class LaunchProfileAsAdminCommand : InvokableCommand
|
||||
// _context.API.ShowMsg(name, message, string.Empty);
|
||||
Logger.LogError($"Failed to open Windows Terminal: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (appManagerPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.Release(appManagerPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0059, CS0168
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user