-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workspaces] Implement PWA recognition, launch. #35913
base: main
Are you sure you want to change the base?
Conversation
…controls to the editor
…ocesses. Update LauncherUI, Launcher
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…y (code cleaning) and updating json parser in Launcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on identifying and launching PWA apps!
There are a few comments about the code; after addressing these, it will be good to go.
src/modules/Workspaces/WorkspacesCsharpLibrary/WorkspacesCsharpLibrary.csproj
Outdated
Show resolved
Hide resolved
src/modules/Workspaces/WorkspacesEditor/ViewModels/MainViewModel.cs
Outdated
Show resolved
Hide resolved
src/modules/Workspaces/WorkspacesEditor/ViewModels/MainViewModel.cs
Outdated
Show resolved
Hide resolved
#include <comdef.h> | ||
#include <Wbemidl.h> | ||
|
||
#include <common/utils/elevation.h> | ||
#include <common/utils/process_path.h> | ||
#include <common/notifications/NotificationUtil.h> | ||
|
||
#include <workspaces-common/WindowEnumerator.h> | ||
#include <workspaces-common/WindowFilter.h> | ||
|
||
#include <WorkspacesLib/AppUtils.h> | ||
#include <tlhelp32.h> | ||
#include <winternl.h> | ||
#include <initguid.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave only what's used here.
#include <comdef.h> | |
#include <Wbemidl.h> | |
#include <common/utils/elevation.h> | |
#include <common/utils/process_path.h> | |
#include <common/notifications/NotificationUtil.h> | |
#include <workspaces-common/WindowEnumerator.h> | |
#include <workspaces-common/WindowFilter.h> | |
#include <WorkspacesLib/AppUtils.h> | |
#include <tlhelp32.h> | |
#include <winternl.h> | |
#include <initguid.h> | |
#include <ShlObj.h> | |
#include <tlhelp32.h> | |
#include <winternl.h> | |
#include <initguid.h> | |
#include <filesystem> | |
#include <wil/result_macros.h> | |
#include <common/logger/logger.h> | |
#include <common/utils/winapi_error.h> | |
#pragma comment(lib, "ntdll.lib") |
#include <tlhelp32.h> | ||
#include <winternl.h> | ||
#include <initguid.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary includes after moving the code to PwaHelper, please remove them.
DWORD err = GetLastError(); | ||
Logger::error(L"Failed to open the process, error: {}", err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps to get the error message.
DWORD err = GetLastError(); | |
Logger::error(L"Failed to open the process, error: {}", err); | |
Logger::error(L"Failed to open the process, error: {}", get_last_error_or_default(GetLastError())); |
std::wstring pwaName = L""; | ||
if (IsEdge(data.value())) | ||
{ | ||
CoInitialize(NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling CoInitialize()
and CoUninitialize()
repeatedly can introduce significant overhead. These functions are intended for setting up and tearing down the COM library, and repeated calls can be costly in terms of performance. It's enough that we call them once in main.cpp
.
std::map<std::wstring, std::wstring> pwaAumidToAppId; | ||
std::vector<std::wstring> chromeAppIds; | ||
std::map<std::wstring, std::wstring> pwaAppIdsToAppNames; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please convert the global variables into class members within the PwaHelper class.
return pwaHelperProcessIds; | ||
} | ||
|
||
void PwaHelper::InitAumidToAppId(DWORD pid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pid
is unused, please remove it.
IAppResolver_7* AppResolver; | ||
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(&AppResolver)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using smart pointers instead.
IAppResolver_7* AppResolver; | |
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(&AppResolver)); | |
wil::com_ptr<IAppResolver_7> appResolver; | |
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(appResolver.put())); | |
WCHAR* pszAppId; | ||
hr = AppResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
*result = std::wstring(pszAppId); | ||
CoTaskMemFree(pszAppId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using smart pointers for strings, too.
WCHAR* pszAppId; | |
hr = AppResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL); | |
if (SUCCEEDED(hr)) | |
{ | |
*result = std::wstring(pszAppId); | |
CoTaskMemFree(pszAppId); | |
} | |
wil::unique_cotaskmem_string pszAppId; | |
hr = appResolver->GetAppIDForWindow(hWnd, &pszAppId, NULL, NULL, NULL); | |
if (SUCCEEDED(hr)) | |
{ | |
*result = std::wstring(pszAppId.get()); | |
} |
{ | ||
std::filesystem::path fsPath(path); | ||
fsPath /= NonLocalizable::EdgeBase; | ||
for (auto& directory : std::filesystem::directory_iterator(fsPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use const auto&
whenever you read a value without modifying it.
Summary of the Pull Request
With this code addition the Workspaces will be able to handle PWA applications installed in Edge or Chrome.
The snapshot tool will detect the running PWA apps, get their PwaAppId, which will be stored in the workspaces.json file.
The Editor (and later the Launcher UI) will show the corresponding app name and the app icon.
The launcher will launch the Pwa apps.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Tested locally on a scenarios where there were 3 different edge-Pwa-apps, 3 different chrome-Pwa-apps, edge and chrome also and other apss too.