mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[runner] Add logging (#16503)
This commit is contained in:
@@ -189,6 +189,7 @@ inline bool drop_elevated_privileges()
|
|||||||
// Run command as elevated user, returns true if succeeded
|
// Run command as elevated user, returns true if succeeded
|
||||||
inline HANDLE run_elevated(const std::wstring& file, const std::wstring& params)
|
inline HANDLE run_elevated(const std::wstring& file, const std::wstring& params)
|
||||||
{
|
{
|
||||||
|
Logger::info(L"run_elevated with params={}", params);
|
||||||
SHELLEXECUTEINFOW exec_info = { 0 };
|
SHELLEXECUTEINFOW exec_info = { 0 };
|
||||||
exec_info.cbSize = sizeof(SHELLEXECUTEINFOW);
|
exec_info.cbSize = sizeof(SHELLEXECUTEINFOW);
|
||||||
exec_info.lpVerb = L"runas";
|
exec_info.lpVerb = L"runas";
|
||||||
@@ -206,6 +207,7 @@ inline HANDLE run_elevated(const std::wstring& file, const std::wstring& params)
|
|||||||
// Run command as non-elevated user, returns true if succeeded, puts the process id into returnPid if returnPid != NULL
|
// Run command as non-elevated user, returns true if succeeded, puts the process id into returnPid if returnPid != NULL
|
||||||
inline bool run_non_elevated(const std::wstring& file, const std::wstring& params, DWORD* returnPid)
|
inline bool run_non_elevated(const std::wstring& file, const std::wstring& params, DWORD* returnPid)
|
||||||
{
|
{
|
||||||
|
Logger::info(L"run_non_elevated with params={}", params);
|
||||||
auto executable_args = L"\"" + file + L"\"";
|
auto executable_args = L"\"" + file + L"\"";
|
||||||
if (!params.empty())
|
if (!params.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ GeneralSettings get_general_settings()
|
|||||||
|
|
||||||
void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
||||||
{
|
{
|
||||||
|
Logger::info(L"apply_general_settings: {}", std::wstring{ general_configs.ToString() });
|
||||||
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
|
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
|
||||||
|
|
||||||
download_updates_automatically = general_configs.GetNamedBoolean(L"download_updates_automatically", true);
|
download_updates_automatically = general_configs.GetNamedBoolean(L"download_updates_automatically", true);
|
||||||
@@ -100,6 +101,7 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
|||||||
{
|
{
|
||||||
if (startup == true && settings.isStartupEnabled == false)
|
if (startup == true && settings.isStartupEnabled == false)
|
||||||
{
|
{
|
||||||
|
Logger::info("PowerToys run at startup disabled manually");
|
||||||
startup_disabled_manually = true;
|
startup_disabled_manually = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,10 +160,12 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
|
|||||||
}
|
}
|
||||||
if (target_enabled)
|
if (target_enabled)
|
||||||
{
|
{
|
||||||
|
Logger::info(L"apply_general_settings: Enabling powertoy {}", name);
|
||||||
powertoy->enable();
|
powertoy->enable();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger::info(L"apply_general_settings: Disabling powertoy {}", name);
|
||||||
powertoy->disable();
|
powertoy->disable();
|
||||||
}
|
}
|
||||||
// Sync the hotkey state with the module state, so it can be removed for disabled modules.
|
// Sync the hotkey state with the module state, so it can be removed for disabled modules.
|
||||||
@@ -205,11 +209,13 @@ void start_enabled_powertoys()
|
|||||||
// Disable explicitly disabled modules
|
// Disable explicitly disabled modules
|
||||||
if (!disabled_element.Value().GetBoolean())
|
if (!disabled_element.Value().GetBoolean())
|
||||||
{
|
{
|
||||||
|
Logger::info(L"start_enabled_powertoys: Powertoy {} explicitly disabled", disable_module_name);
|
||||||
powertoys_to_disable.emplace(std::move(disable_module_name));
|
powertoys_to_disable.emplace(std::move(disable_module_name));
|
||||||
}
|
}
|
||||||
// If module was scheduled for disable, but it's enabled in the settings - override default value
|
// If module was scheduled for disable, but it's enabled in the settings - override default value
|
||||||
else if (auto it = powertoys_to_disable.find(disable_module_name); it != end(powertoys_to_disable))
|
else if (auto it = powertoys_to_disable.find(disable_module_name); it != end(powertoys_to_disable))
|
||||||
{
|
{
|
||||||
|
Logger::info(L"start_enabled_powertoys: Overriding default enabled value for {} powertoy", disable_module_name);
|
||||||
powertoys_to_disable.erase(it);
|
powertoys_to_disable.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,6 +229,7 @@ void start_enabled_powertoys()
|
|||||||
{
|
{
|
||||||
if (!powertoys_to_disable.contains(name))
|
if (!powertoys_to_disable.contains(name))
|
||||||
{
|
{
|
||||||
|
Logger::info(L"start_enabled_powertoys: Enabling powertoy {}", name);
|
||||||
powertoy->enable();
|
powertoy->enable();
|
||||||
powertoy.UpdateHotkeyEx();
|
powertoy.UpdateHotkeyEx();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,6 +344,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
Logger::init(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
|
Logger::init(LogSettings::runnerLoggerName, logFilePath.wstring(), PTSettingsHelper::get_log_settings_file_location());
|
||||||
|
|
||||||
const std::string cmdLine{ lpCmdLine };
|
const std::string cmdLine{ lpCmdLine };
|
||||||
|
Logger::info("Running powertoys with cmd args: {}", cmdLine);
|
||||||
|
|
||||||
auto open_settings_it = cmdLine.find("--open-settings");
|
auto open_settings_it = cmdLine.find("--open-settings");
|
||||||
const bool open_settings = open_settings_it != std::string::npos;
|
const bool open_settings = open_settings_it != std::string::npos;
|
||||||
// Check if opening specific settings window
|
// Check if opening specific settings window
|
||||||
@@ -408,6 +410,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
if (elevated && with_dont_elevate_arg && !run_elevated_setting)
|
if (elevated && with_dont_elevate_arg && !run_elevated_setting)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Logger::info("Scheduling restart as non elevated");
|
||||||
schedule_restart_as_non_elevated();
|
schedule_restart_as_non_elevated();
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
@@ -422,6 +425,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger::info("Scheduling restart as elevated");
|
||||||
schedule_restart_as_elevated(open_settings);
|
schedule_restart_as_elevated(open_settings);
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user