[Runner]Fix elevation issues due to syncing settings with scheduler state (#17254)

This commit is contained in:
Andrey Nekrasov
2022-03-25 13:04:29 +03:00
committed by GitHub
parent 75f2be1891
commit 724620a24e
2 changed files with 2 additions and 17 deletions

View File

@@ -14,7 +14,6 @@
// TODO: would be nice to get rid of these globals, since they're basically cached json settings // TODO: would be nice to get rid of these globals, since they're basically cached json settings
static std::wstring settings_theme = L"system"; static std::wstring settings_theme = L"system";
static bool startup_disabled_manually = false;
static bool run_as_elevated = false; static bool run_as_elevated = false;
static bool download_updates_automatically = true; static bool download_updates_automatically = true;
@@ -94,20 +93,7 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
{ {
const bool startup = general_configs.GetNamedBoolean(L"startup"); const bool startup = general_configs.GetNamedBoolean(L"startup");
auto settings = get_general_settings(); if (startup)
static std::once_flag once_flag;
std::call_once(once_flag, [settings, startup, general_configs] {
if (json::has(general_configs, L"startup", json::JsonValueType::Boolean))
{
if (startup == true && settings.isStartupEnabled == false)
{
Logger::info("PowerToys run at startup disabled manually");
startup_disabled_manually = true;
}
}
});
if (startup && !startup_disabled_manually)
{ {
if (is_process_elevated()) if (is_process_elevated())
{ {
@@ -133,7 +119,6 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
else else
{ {
delete_auto_start_task_for_this_user(); delete_auto_start_task_for_this_user();
startup_disabled_manually = false;
} }
} }
if (json::has(general_configs, L"enabled")) if (json::has(general_configs, L"enabled"))

View File

@@ -52,5 +52,5 @@ bool restart_same_elevation()
constexpr DWORD exe_path_size = 0xFFFF; constexpr DWORD exe_path_size = 0xFFFF;
auto exe_path = std::make_unique<wchar_t[]>(exe_path_size); auto exe_path = std::make_unique<wchar_t[]>(exe_path_size);
GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size); GetModuleFileNameW(nullptr, exe_path.get(), exe_path_size);
return run_same_elevation(exe_path.get(), L"", nullptr); return run_same_elevation(exe_path.get(), L"--dont-elevate", nullptr);
} }