there's no way that just works, right?

This commit is contained in:
Mike Griese
2025-11-16 20:55:16 -06:00
parent 34c37f2d38
commit 0d73747572
2 changed files with 32 additions and 0 deletions

View File

@@ -58,6 +58,7 @@
</ClCompile> </ClCompile>
<Link> <Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>

View File

@@ -14,6 +14,7 @@
#include <common/utils/winapi_error.h> #include <common/utils/winapi_error.h>
#include <common/interop/shared_constants.h> #include <common/interop/shared_constants.h>
#include <Psapi.h> #include <Psapi.h>
#include <Shlwapi.h>
#include <TlHelp32.h> #include <TlHelp32.h>
#include <thread> #include <thread>
@@ -49,6 +50,29 @@ private:
// Track if this is the first call to enable // Track if this is the first call to enable
bool firstEnableCall = true; bool firstEnableCall = true;
static bool IsUriProtocolRegistered(const std::wstring& protocol)
{
WCHAR executable[MAX_PATH] = { 0 };
DWORD buffer_length = MAX_PATH;
// Query if there's an executable associated with this URI protocol
HRESULT hr = AssocQueryString(ASSOCF_INIT_IGNOREUNKNOWN,
ASSOCSTR_EXECUTABLE,
protocol.c_str(),
nullptr,
executable,
&buffer_length);
if (SUCCEEDED(hr) && buffer_length > 0)
{
Logger::trace(L"URI protocol '{}' is registered with executable: {}", protocol, executable);
return true;
}
Logger::trace(L"URI protocol '{}' is not registered. HRESULT: 0x{:X}", protocol, static_cast<unsigned long>(hr));
return false;
}
static bool LaunchApp(const std::wstring& appPath, const std::wstring& commandLineArgs, bool elevated, bool silentFail) static bool LaunchApp(const std::wstring& appPath, const std::wstring& commandLineArgs, bool elevated, bool silentFail)
{ {
std::wstring dir = std::filesystem::path(appPath).parent_path(); std::wstring dir = std::filesystem::path(appPath).parent_path();
@@ -269,6 +293,13 @@ public:
return; return;
} }
// Check if x-cmdpal URI protocol handler is registered
if (!IsUriProtocolRegistered(L"x-cmdpal"))
{
Logger::error("x-cmdpal URI protocol handler is not registered. Cannot launch CmdPal.");
return;
}
if (!firstEnableCall) if (!firstEnableCall)
{ {
Logger::trace("Not first attempt, try to launch"); Logger::trace("Not first attempt, try to launch");