Skip to content

Commit

Permalink
fix: 修复启用“以管理者身份运行该程序”兼容性选项时 ToucherHelper 无法获得 UIAccess 权限的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Sep 9, 2024
1 parent 650c60f commit 2ac8802
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Magpie.App/TouchHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ bool TouchHelper::TryLaunchTouchHelper(bool& isTouchSupportEnabled) noexcept {
return false;
}

if (!Win32Utils::ShellOpen(path.c_str(), nullptr, false)) {
// GH#992: 必须委托 explorer 启动 ToucherHelper,否则如果启用了“以管理者身份运行该程序”
// 兼容性选项,ToucherHelper 将无法获得 UIAccess 权限
if (!Win32Utils::ShellOpen(path.c_str(), nullptr, true)) {
Logger::Get().Error("启动 TouchHelper.exe 失败");
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Magpie.Core/ScalingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ LRESULT ScalingWindow::_MessageHandler(UINT msg, WPARAM wParam, LPARAM lParam) n
}

switch (msg) {
case WM_CREATE:
{
// TouchHelper 的权限可能比我们低
if (!ChangeWindowMessageFilterEx(Handle(), WM_MAGPIE_TOUCHHELPER, MSGFLT_ADD, nullptr)) {
Logger::Get().Win32Error("ChangeWindowMessageFilter 失败");
}

break;
}
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
{
Expand Down
10 changes: 5 additions & 5 deletions src/Magpie/XamlApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ static UINT WM_MAGPIE_QUIT;
static void InitMessages() noexcept {
WM_MAGPIE_SHOWME = RegisterWindowMessage(CommonSharedConstants::WM_MAGPIE_SHOWME);
WM_MAGPIE_QUIT = RegisterWindowMessage(CommonSharedConstants::WM_MAGPIE_QUIT);

// 允许被权限更低的实例唤醒
if (!ChangeWindowMessageFilter(WM_MAGPIE_SHOWME, MSGFLT_ADD)) {
Logger::Get().Win32Error("ChangeWindowMessageFilter 失败");
}
}

// 我们需要尽可能高的时钟分辨率来提高渲染帧率。
Expand Down Expand Up @@ -203,11 +208,6 @@ bool XamlApp::_CheckSingleInstance() noexcept {
PostMessage(HWND_BROADCAST, WM_MAGPIE_SHOWME, 0, 0);
return false;
}

// 以管理员身份运行时允许接收 WM_MAGPIE_SHOWME 消息,否则无法被该消息唤醒
if (!ChangeWindowMessageFilter(WM_MAGPIE_SHOWME, MSGFLT_ADD)) {
Logger::Get().Win32Error("ChangeWindowMessageFilter 失败");
}
}

bool alreadyExists = false;
Expand Down

0 comments on commit 2ac8802

Please sign in to comment.