mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-03 03:19:08 +08:00
fix excluded apps check (#30138)
This commit is contained in:
parent
3e7cc723a5
commit
b3804a9f38
@ -32,7 +32,7 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector<std
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_TITLE_LENGTH 255
|
#define MAX_TITLE_LENGTH 255
|
||||||
inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
|
inline bool check_excluded_app_with_title(const HWND& hwnd, const std::vector<std::wstring>& excludedApps)
|
||||||
{
|
{
|
||||||
WCHAR title[MAX_TITLE_LENGTH];
|
WCHAR title[MAX_TITLE_LENGTH];
|
||||||
int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH);
|
int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH);
|
||||||
@ -42,23 +42,25 @@ inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& proces
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::wstring titleStr(title);
|
std::wstring titleStr(title);
|
||||||
auto lastBackslashPos = processPath.find_last_of(L'\\');
|
CharUpperBuffW(titleStr.data(), static_cast<DWORD>(titleStr.length()));
|
||||||
if (lastBackslashPos != std::wstring::npos)
|
|
||||||
|
for (const auto& app : excludedApps)
|
||||||
{
|
{
|
||||||
processPath = processPath.substr(0, lastBackslashPos + 1); // retain up to the last backslash
|
if (titleStr.contains(app))
|
||||||
processPath.append(titleStr); // append the title
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
|
return false;
|
||||||
return find_app_name_in_path(processPath, excludedApps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool check_excluded_app(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
|
inline bool check_excluded_app(const HWND& hwnd, const std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
|
||||||
{
|
{
|
||||||
bool res = find_app_name_in_path(processPath, excludedApps);
|
bool res = find_app_name_in_path(processPath, excludedApps);
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
res = check_excluded_app_with_title(hwnd, processPath, excludedApps);
|
res = check_excluded_app_with_title(hwnd, excludedApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -202,12 +202,12 @@ bool FancyZonesWindowUtils::IsExcluded(HWND window)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept
|
bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept
|
||||||
{
|
{
|
||||||
return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray));
|
return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept
|
bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept
|
||||||
{
|
{
|
||||||
static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder };
|
static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder };
|
||||||
if (find_folder_in_path(processPath, defaultExcludedFolders))
|
if (find_folder_in_path(processPath, defaultExcludedFolders))
|
||||||
|
@ -27,8 +27,8 @@ namespace FancyZonesWindowUtils
|
|||||||
bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated
|
bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated
|
||||||
|
|
||||||
bool IsExcluded(HWND window);
|
bool IsExcluded(HWND window);
|
||||||
bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept;
|
bool IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept;
|
||||||
bool IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept;
|
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept;
|
||||||
|
|
||||||
void SwitchToWindow(HWND window) noexcept;
|
void SwitchToWindow(HWND window) noexcept;
|
||||||
void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
||||||
|
Loading…
Reference in New Issue
Block a user