Fix settings issue where settings.json would get reset on runner startup (#4524)

* Added flag to avoid saving before modules is initialized

* Added comment
This commit is contained in:
Arjun Balgovind 2020-06-26 14:46:47 -07:00 committed by GitHub
parent d17fc86fa4
commit 55272e5ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -114,7 +114,7 @@ GeneralSettings get_general_settings()
return settings; return settings;
} }
void apply_general_settings(const json::JsonObject& general_configs) void apply_general_settings(const json::JsonObject& general_configs, bool save)
{ {
run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false); run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false);
@ -195,9 +195,12 @@ void apply_general_settings(const json::JsonObject& general_configs)
settings_theme = general_configs.GetNamedString(L"theme"); settings_theme = general_configs.GetNamedString(L"theme");
} }
GeneralSettings save_settings = get_general_settings(); if (save)
PTSettingsHelper::save_general_settings(save_settings.to_json()); {
Trace::SettingsChanged(save_settings); GeneralSettings save_settings = get_general_settings();
PTSettingsHelper::save_general_settings(save_settings.to_json());
Trace::SettingsChanged(save_settings);
}
} }
void start_initial_powertoys() void start_initial_powertoys()

View File

@ -21,5 +21,5 @@ struct GeneralSettings
json::JsonObject load_general_settings(); json::JsonObject load_general_settings();
GeneralSettings get_general_settings(); GeneralSettings get_general_settings();
void apply_general_settings(const json::JsonObject& general_configs); void apply_general_settings(const json::JsonObject& general_configs, bool save = true);
void start_initial_powertoys(); void start_initial_powertoys();

View File

@ -376,7 +376,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
modules(); modules();
auto general_settings = load_general_settings(); auto general_settings = load_general_settings();
apply_general_settings(general_settings);
// Apply the general settings but don't save it as the modules() variable has not been loaded yet
apply_general_settings(general_settings, false);
int rvalue = 0; int rvalue = 0;
const bool elevated = is_process_elevated(); const bool elevated = is_process_elevated();
if ((elevated || if ((elevated ||