mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
launcher logger
This commit is contained in:
@@ -69,6 +69,8 @@ struct LogSettings
|
||||
inline const static std::string environmentVariablesLoggerName = "environment-variables";
|
||||
inline const static std::wstring cmdNotFoundLogPath = L"Logs\\cmd-not-found-log.txt";
|
||||
inline const static std::string cmdNotFoundLoggerName = "cmd-not-found";
|
||||
inline const static std::string projectsLauncherLoggerName = "projects-launcher";
|
||||
inline const static std::wstring projectsLauncherLogPath = L"projects-launcher-log.txt";
|
||||
inline const static int retention = 30;
|
||||
std::wstring logLevel;
|
||||
LogSettings();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <projects-common/WindowFilter.h>
|
||||
|
||||
#include <common/Display/dpi_aware.h>
|
||||
#include <common/utils/winapi_error.h>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace Windows::Foundation;
|
||||
@@ -122,8 +123,7 @@ namespace FancyZones
|
||||
auto result = ::SetWindowPlacement(window, &placement);
|
||||
if (!result)
|
||||
{
|
||||
std::wcout << "Set window placement failed" << std::endl;
|
||||
//Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
||||
Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -138,8 +138,7 @@ namespace FancyZones
|
||||
result = ::SetWindowPlacement(window, &placement);
|
||||
if (!result)
|
||||
{
|
||||
std::wcout << "Set window placement failed" << std::endl;
|
||||
//Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
||||
Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -165,7 +164,7 @@ bool LaunchApp(const std::wstring& appPath, std::wstring commandLineArgs)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wcerr << L"Failed to launch process. Error code: " << GetLastError() << std::endl;
|
||||
Logger::error(L"Failed to launch process. {}", get_last_error_or_default(GetLastError()));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -191,14 +190,14 @@ bool LaunchPackagedApp(const std::wstring& packageFullName)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wcout << L"No app entries found for the package." << std::endl;
|
||||
Logger::error(L"No app entries found for the package.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const hresult_error& ex)
|
||||
{
|
||||
std::wcerr << L"Error: " << ex.message().c_str() << std::endl;
|
||||
Logger::error(L"Packaged app launching error: {}", ex.message());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -209,26 +208,26 @@ bool Launch(const Project::Application& app)
|
||||
bool launched;
|
||||
if (!app.packageFullName.empty() && app.commandLineArgs.empty())
|
||||
{
|
||||
std::wcout << L"Launching packaged " << app.name << std::endl;
|
||||
Logger::trace(L"Launching packaged {}", app.name);
|
||||
launched = LaunchPackagedApp(app.packageFullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: verify app path is up to date.
|
||||
// Packaged apps have version in the path, it will be outdated after update.
|
||||
std::wcout << L"Launching " << app.name << " at " << app.path << std::endl;
|
||||
Logger::trace(L"Launching {} at {}", app.name, app.path);
|
||||
|
||||
DWORD dwAttrib = GetFileAttributesW(app.path.c_str());
|
||||
if (dwAttrib == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
std::wcout << L" File not found at " << app.path << std::endl;
|
||||
Logger::error(L"File not found at {}", app.path);
|
||||
return false;
|
||||
}
|
||||
|
||||
launched = LaunchApp(app.path, app.commandLineArgs);
|
||||
}
|
||||
|
||||
std::wcout << app.name << (launched ? L" launched" : L" not launched") << std::endl;
|
||||
Logger::trace(L"{} {} at {}", app.name, (launched ? L"launched" : L"not launched"), app.path);
|
||||
return launched;
|
||||
}
|
||||
|
||||
@@ -276,12 +275,12 @@ void Launch(const Project& project)
|
||||
auto res = std::find_if(launchedWindows.begin(), launchedWindows.end(), [&](const std::pair<Project::Application, HWND>& val) { return val.second == nullptr; });
|
||||
if (res == launchedWindows.end())
|
||||
{
|
||||
std::wcout << "All windows found." << std::endl;
|
||||
Logger::trace(L"All windows found.");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wcout << "Not all windows found, retry." << std::endl;
|
||||
Logger::trace(L"Not all windows found, retry.");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
@@ -311,17 +310,17 @@ void Launch(const Project& project)
|
||||
{
|
||||
if (window == nullptr)
|
||||
{
|
||||
std::wcout << app.name << " window not found." << std::endl;
|
||||
Logger::warn(L"{} window not found.", app.name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FancyZones::SizeWindowToRect(window, app.isMinimized, app.isMaximized, app.position.toRect()))
|
||||
{
|
||||
std::wcout << L"Placed " << app.name << std::endl;
|
||||
Logger::trace(L"Placed {}", app.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wcout << L"Failed placing " << app.name << std::endl;
|
||||
Logger::error(L"Failed placing {}", app.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>shcore.lib;Shell32.lib;propsys.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>shcore.lib;Shell32.lib;propsys.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
@@ -119,7 +119,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>shcore.lib;Shell32.lib;propsys.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>shcore.lib;Shell32.lib;propsys.lib;DbgHelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,8 +6,17 @@
|
||||
|
||||
#include <AppLauncher.h>
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow)
|
||||
#include <common/utils/logger_helper.h>
|
||||
#include <common/utils/UnhandledExceptionHandler.h>
|
||||
|
||||
const std::wstring moduleName = L"Projects\\ProjectsLauncher";
|
||||
const std::wstring internalPath = L"";
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cmdshow)
|
||||
{
|
||||
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::projectsLauncherLoggerName);
|
||||
InitUnhandledExceptionHandler();
|
||||
|
||||
// read projects
|
||||
std::vector<Project> projects;
|
||||
try
|
||||
@@ -22,24 +31,25 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmd
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception)
|
||||
catch (std::exception ex)
|
||||
{
|
||||
Logger::error("Exception on reading projects: {}", ex.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (projects.empty())
|
||||
{
|
||||
Logger::warn("Projects file is empty");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Project projectToLaunch = projects[0];
|
||||
|
||||
int len = MultiByteToWideChar(CP_ACP, 0, cmdline, -1, NULL, 0);
|
||||
if (len > 1)
|
||||
std::string idStr(cmdline);
|
||||
std::wstring id(idStr.begin(), idStr.end());
|
||||
Logger::info(L"command line: {}", id);
|
||||
if (!id.empty())
|
||||
{
|
||||
std::wstring id(len, L'\0');
|
||||
MultiByteToWideChar(CP_ACP, 0, cmdline, -1, &id[0], len);
|
||||
|
||||
for (const auto& proj : projects)
|
||||
{
|
||||
if (proj.id == id)
|
||||
@@ -50,6 +60,8 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmd
|
||||
}
|
||||
}
|
||||
|
||||
Logger::info(L"Launch Project {} : {}", projectToLaunch.name, projectToLaunch.id);
|
||||
|
||||
// launch apps
|
||||
Launch(projectToLaunch);
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <common/logger/logger.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
|
||||
Reference in New Issue
Block a user