Sync run on startup with actual task scheduler (#14723)

This commit is contained in:
Stefan Markovic
2021-12-02 09:09:16 +01:00
committed by GitHub
parent 87f6278bf9
commit 0e61f41e31
2 changed files with 20 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
// 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 bool startup_disabled_manually = false;
static bool run_as_elevated = false;
static bool download_updates_automatically = true;
@@ -91,7 +92,20 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
if (json::has(general_configs, L"startup", json::JsonValueType::Boolean))
{
const bool startup = general_configs.GetNamedBoolean(L"startup");
if (startup)
auto settings = get_general_settings();
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)
{
startup_disabled_manually = true;
}
}
});
if (startup && !startup_disabled_manually)
{
if (is_process_elevated())
{
@@ -117,6 +131,7 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
else
{
delete_auto_start_task_for_this_user();
startup_disabled_manually = false;
}
}
if (json::has(general_configs, L"enabled"))

View File

@@ -404,6 +404,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
result = -1;
}
// Save settings on closing
auto general_settings = load_general_settings();
apply_general_settings(general_settings);
// We need to release the mutexes to be able to restart the application
if (msi_mutex)
{