From 9b8d86858f555878ad93de2bf5311f69b1e623d2 Mon Sep 17 00:00:00 2001 From: seraphima Date: Fri, 28 Jun 2024 14:49:20 +0200 Subject: [PATCH 1/3] logs --- .../Projects/projects-common/AppUtils.h | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/modules/Projects/projects-common/AppUtils.h b/src/modules/Projects/projects-common/AppUtils.h index 10921a52dc..8135bb375b 100644 --- a/src/modules/Projects/projects-common/AppUtils.h +++ b/src/modules/Projects/projects-common/AppUtils.h @@ -1,13 +1,14 @@ #pragma once -#include #include #include #include #include +#include #include +#include namespace Utils { @@ -41,6 +42,7 @@ namespace Utils HRESULT hr = SHGetKnownFolderItem(FOLDERID_AppsFolder, KF_FLAG_DEFAULT, nullptr, IID_PPV_ARGS(&folder)); if (FAILED(hr)) { + Logger::error(L"Failed to get known apps folder: {}", get_last_error_or_default(hr)); return result; } @@ -48,6 +50,7 @@ namespace Utils hr = folder->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&enumItems)); if (FAILED(hr)) { + Logger::error(L"Failed to bind to enum items handler: {}", get_last_error_or_default(hr)); return result; } @@ -57,8 +60,10 @@ namespace Utils CComPtr item = items; CComHeapPtr name; - if (FAILED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &name))) + hr = item->GetDisplayName(SIGDN_NORMALDISPLAY, &name); + if (FAILED(hr)) { + Logger::error(L"Failed to get display name for app: {}", get_last_error_or_default(hr)); continue; } @@ -68,8 +73,10 @@ namespace Utils // properties CComPtr store; - if (FAILED(item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store)))) + hr = item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store)); + if (FAILED(hr)) { + Logger::error(L"Failed to bind to property store handler: {}", get_last_error_or_default(hr)); continue; } @@ -78,8 +85,10 @@ namespace Utils for (DWORD i = 0; i < count; i++) { PROPERTYKEY pk; - if (FAILED(store->GetAt(i, &pk))) + hr = store->GetAt(i, &pk); + if (FAILED(hr)) { + Logger::error(L"Failed to get property key: {}", get_last_error_or_default(hr)); continue; } @@ -93,7 +102,8 @@ namespace Utils { PROPVARIANT pv; PropVariantInit(&pv); - if (SUCCEEDED(store->GetValue(pk, &pv))) + hr = store->GetValue(pk, &pv); + if (SUCCEEDED(hr)) { CComHeapPtr propVariantString; propVariantString.Allocate(512); @@ -109,6 +119,10 @@ namespace Utils data.installPath = propVariantString.m_pData; } } + else + { + Logger::error(L"Failed to get property value: {}", get_last_error_or_default(hr)); + } if (!data.packageFullName.empty() && !data.installPath.empty()) { @@ -133,20 +147,20 @@ namespace Utils inline std::optional GetApp(const std::wstring& appPath, const AppList& apps) { + std::wstring appPathUpper(appPath); + std::transform(appPathUpper.begin(), appPathUpper.end(), appPathUpper.begin(), towupper); + + // edge case, "Windows Software Development Kit" has the same app path as "File Explorer" + if (appPathUpper == NonLocalizable::FileExplorerPath) + { + return AppData{ + .name = NonLocalizable::FileExplorerName, + .installPath = appPath, + }; + } + for (const auto& appData : apps) { - std::wstring appPathUpper(appPath); - std::transform(appPathUpper.begin(), appPathUpper.end(), appPathUpper.begin(), towupper); - - // edge case, "Windows Software Development Kit" has the same app path as "File Explorer" - if (appPathUpper == NonLocalizable::FileExplorerPath) - { - return AppData{ - .name = NonLocalizable::FileExplorerName, - .installPath = appPath, - }; - } - if (!appData.installPath.empty()) { std::wstring installPathUpper(appData.installPath); @@ -166,7 +180,6 @@ namespace Utils } } - // TODO: not all installed apps found return AppData{ .installPath = appPath }; From 2643f00fa1272431665de8450e6ecdf6bf55e5da Mon Sep 17 00:00:00 2001 From: seraphima Date: Fri, 28 Jun 2024 14:50:10 +0200 Subject: [PATCH 2/3] exclude help windows https://github.com/JaneaSystems/PowerToys-DevProjects/issues/49 --- .../Projects/projects-common/WindowUtils.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/modules/Projects/projects-common/WindowUtils.h b/src/modules/Projects/projects-common/WindowUtils.h index 3cc4c1f85e..37a9c5bae5 100644 --- a/src/modules/Projects/projects-common/WindowUtils.h +++ b/src/modules/Projects/projects-common/WindowUtils.h @@ -22,6 +22,7 @@ namespace WindowUtils const char SplashClassName[] = "MsoSplash"; const wchar_t CoreWindow[] = L"WINDOWS.UI.CORE.COREWINDOW"; const wchar_t SearchUI[] = L"SEARCHUI.EXE"; + const wchar_t HelpWindow[] = L"C:\\WINDOWS\\HH.EXE"; const wchar_t ProjectsSnapshotTool[] = L"POWERTOYS.PROJECTSSNAPSHOTTOOL"; const wchar_t ProjectsEditor[] = L"POWERTOYS.PROJECTSEDITOR"; const wchar_t ProjectsLauncher[] = L"POWERTOYS.PROJECTSLAUNCHER"; @@ -53,7 +54,12 @@ namespace WindowUtils std::wstring processPathUpper = processPath; CharUpperBuffW(processPathUpper.data(), static_cast(processPathUpper.length())); - static std::vector defaultExcludedFolders = { NonLocalizable::SystemAppsFolder, NonLocalizable::System, NonLocalizable::System32, NonLocalizable::SystemWOW64 }; + static std::vector defaultExcludedFolders = { + NonLocalizable::SystemAppsFolder, + NonLocalizable::System, + NonLocalizable::System32, + NonLocalizable::SystemWOW64 + }; if (find_folder_in_path(processPathUpper, defaultExcludedFolders)) { return true; @@ -71,7 +77,14 @@ namespace WindowUtils return true; } - static std::vector defaultExcludedApps = { NonLocalizable::CoreWindow, NonLocalizable::SearchUI, NonLocalizable::ProjectsEditor, NonLocalizable::ProjectsLauncher, NonLocalizable::ProjectsSnapshotTool }; + static std::vector defaultExcludedApps = { + NonLocalizable::CoreWindow, + NonLocalizable::SearchUI, + NonLocalizable::HelpWindow, + NonLocalizable::ProjectsEditor, + NonLocalizable::ProjectsLauncher, + NonLocalizable::ProjectsSnapshotTool, + }; return (check_excluded_app(window, processPathUpper, defaultExcludedApps)); } From aae69ab125a90493508564d8ae8acea1ea23b3d7 Mon Sep 17 00:00:00 2001 From: seraphima Date: Fri, 28 Jun 2024 15:41:26 +0200 Subject: [PATCH 3/3] mutex fix --- src/modules/Projects/ProjectsEditor/App.xaml.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index e454b4f8be..9188150718 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -17,7 +17,7 @@ namespace ProjectsEditor /// public partial class App : Application, IDisposable { - private static Mutex mutex; + private static Mutex _instanceMutex; public static ProjectsEditorIO ProjectsEditorIO { get; private set; } @@ -41,10 +41,11 @@ namespace ProjectsEditor const string appName = "Local\\PowerToys_Projects_Editor_InstanceMutex"; bool createdNew; - mutex = new Mutex(true, appName, out createdNew); + _instanceMutex = new Mutex(true, appName, out createdNew); if (!createdNew) { Logger.LogWarning("Another instance of Projects Editor is already running. Exiting this instance."); + _instanceMutex = null; Shutdown(0); return; } @@ -90,7 +91,11 @@ namespace ProjectsEditor private void OnExit(object sender, ExitEventArgs e) { - mutex?.ReleaseMutex(); + if (_instanceMutex != null) + { + _instanceMutex.ReleaseMutex(); + } + Dispose(); } @@ -106,6 +111,7 @@ namespace ProjectsEditor if (disposing) { _themeManager?.Dispose(); + _instanceMutex?.Dispose(); } _isDisposed = true;