Skip to content
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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

donlaci
Copy link
Collaborator

@donlaci donlaci commented Nov 13, 2024

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.

This comment has been minimized.

This comment has been minimized.

@crutkas crutkas added the Needs-Review This Pull Request awaits the review of a maintainer. label Nov 13, 2024

This comment has been minimized.

…y (code cleaning) and updating json parser in Launcher
Copy link
Collaborator

@SeraphimaZykova SeraphimaZykova left a 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.

Comment on lines 3 to 16
#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>
Copy link
Collaborator

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.

Suggested change
#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")

Comment on lines 15 to 17
#include <tlhelp32.h>
#include <winternl.h>
#include <initguid.h>
Copy link
Collaborator

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.

Comment on lines 178 to 179
DWORD err = GetLastError();
Logger::error(L"Failed to open the process, error: {}", err);
Copy link
Collaborator

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.

Suggested change
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);
Copy link
Collaborator

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.

Comment on lines 166 to 168
std::map<std::wstring, std::wstring> pwaAumidToAppId;
std::vector<std::wstring> chromeAppIds;
std::map<std::wstring, std::wstring> pwaAppIdsToAppNames;
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Comment on lines 115 to 116
IAppResolver_7* AppResolver;
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(&AppResolver));
Copy link
Collaborator

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.

Suggested change
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()));

Comment on lines 119 to 125
WCHAR* pszAppId;
hr = AppResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL);
if (SUCCEEDED(hr))
{
*result = std::wstring(pszAppId);
CoTaskMemFree(pszAppId);
}
Copy link
Collaborator

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.

Suggested change
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))
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Review This Pull Request awaits the review of a maintainer.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants