mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
Merge branch 'dev/feature/projects' of https://github.com/microsoft/PowerToys into dev/feature/projects
This commit is contained in:
@@ -17,7 +17,7 @@ namespace ProjectsEditor
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <atlbase.h>
|
||||
#include <ShlObj.h>
|
||||
#include <propvarutil.h>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <common/logger/logger.h>
|
||||
#include <common/utils/process_path.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
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<IShellItem> item = items;
|
||||
CComHeapPtr<wchar_t> 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<IPropertyStore> 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<wchar_t> 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<AppData> 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
|
||||
};
|
||||
|
||||
@@ -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<DWORD>(processPathUpper.length()));
|
||||
|
||||
static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder, NonLocalizable::System, NonLocalizable::System32, NonLocalizable::SystemWOW64 };
|
||||
static std::vector<std::wstring> 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<std::wstring> defaultExcludedApps = { NonLocalizable::CoreWindow, NonLocalizable::SearchUI, NonLocalizable::ProjectsEditor, NonLocalizable::ProjectsLauncher, NonLocalizable::ProjectsSnapshotTool };
|
||||
static std::vector<std::wstring> defaultExcludedApps = {
|
||||
NonLocalizable::CoreWindow,
|
||||
NonLocalizable::SearchUI,
|
||||
NonLocalizable::HelpWindow,
|
||||
NonLocalizable::ProjectsEditor,
|
||||
NonLocalizable::ProjectsLauncher,
|
||||
NonLocalizable::ProjectsSnapshotTool,
|
||||
};
|
||||
return (check_excluded_app(window, processPathUpper, defaultExcludedApps));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user