mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
updating: do not update update_check date when we couldn't do it (#9038)
* updating: do not update update_check date when we couldn't do it - improve general settings page "Last Checked" feature
This commit is contained in:
@@ -85,19 +85,25 @@ std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObjec
|
||||
}
|
||||
else if (action == L"check_for_updates")
|
||||
{
|
||||
auto new_version_info = check_for_updates();
|
||||
const VersionHelper latestVersion =
|
||||
new_version_info ? new_version_info->version :
|
||||
VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION };
|
||||
if (auto update_check_result = check_for_updates())
|
||||
{
|
||||
VersionHelper latestVersion{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION };
|
||||
bool isVersionLatest = true;
|
||||
if (auto new_version = std::get_if<updating::new_version_download_info>(&*update_check_result))
|
||||
{
|
||||
latestVersion = new_version->version;
|
||||
isVersionLatest = false;
|
||||
}
|
||||
json::JsonObject json;
|
||||
json.SetNamedValue(L"version", json::value(latestVersion.toWstring()));
|
||||
json.SetNamedValue(L"isVersionLatest", json::value(isVersionLatest));
|
||||
|
||||
json::JsonObject json;
|
||||
json.SetNamedValue(L"version", json::JsonValue::CreateStringValue(latestVersion.toWstring()));
|
||||
json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(!new_version_info));
|
||||
result.emplace(json.Stringify());
|
||||
|
||||
result.emplace(json.Stringify());
|
||||
UpdateState::store([](UpdateState& state) {
|
||||
state.github_update_last_checked_date.emplace(timeutil::now());
|
||||
});
|
||||
UpdateState::store([](UpdateState& state) {
|
||||
state.github_update_last_checked_date.emplace(timeutil::now());
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (action == L"request_update_state_date")
|
||||
{
|
||||
@@ -107,7 +113,7 @@ std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObjec
|
||||
if (update_state.github_update_last_checked_date)
|
||||
{
|
||||
const time_t date = *update_state.github_update_last_checked_date;
|
||||
json.SetNamedValue(L"updateStateDate", json::JsonValue::CreateStringValue(std::to_wstring(date)));
|
||||
json.SetNamedValue(L"updateStateDate", json::value(std::to_wstring(date)));
|
||||
}
|
||||
|
||||
result.emplace(json.Stringify());
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
|
||||
auto Strings = create_notifications_strings();
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr int64_t UPDATE_CHECK_INTERVAL_MINUTES = 60 * 24;
|
||||
constexpr int64_t UPDATE_CHECK_AFTER_FAILED_INTERVAL_MINUTES = 60 * 2;
|
||||
}
|
||||
|
||||
bool start_msi_uninstallation_sequence()
|
||||
{
|
||||
const auto package_path = updating::get_msi_package_path();
|
||||
@@ -40,8 +46,6 @@ bool start_msi_uninstallation_sequence()
|
||||
|
||||
void github_update_worker()
|
||||
{
|
||||
const int64_t update_check_period_minutes = 60 * 24;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
auto state = UpdateState::read();
|
||||
@@ -51,40 +55,57 @@ void github_update_worker()
|
||||
int64_t last_checked_minutes_ago = timeutil::diff::in_minutes(timeutil::now(), *state.github_update_last_checked_date);
|
||||
if (last_checked_minutes_ago < 0)
|
||||
{
|
||||
last_checked_minutes_ago = update_check_period_minutes;
|
||||
last_checked_minutes_ago = UPDATE_CHECK_INTERVAL_MINUTES;
|
||||
}
|
||||
sleep_minutes_till_next_update = max(0, update_check_period_minutes - last_checked_minutes_ago);
|
||||
sleep_minutes_till_next_update = max(0, UPDATE_CHECK_INTERVAL_MINUTES - last_checked_minutes_ago);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::minutes(sleep_minutes_till_next_update));
|
||||
std::this_thread::sleep_for(std::chrono::minutes{ sleep_minutes_till_next_update });
|
||||
const bool download_updates_automatically = get_general_settings().downloadUpdatesAutomatically;
|
||||
bool update_check_ok = false;
|
||||
try
|
||||
{
|
||||
updating::try_autoupdate(download_updates_automatically, Strings).get();
|
||||
update_check_ok = updating::try_autoupdate(download_updates_automatically, Strings).get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Couldn't autoupdate
|
||||
update_check_ok = false;
|
||||
}
|
||||
|
||||
if (update_check_ok)
|
||||
{
|
||||
UpdateState::store([](UpdateState& state) {
|
||||
state.github_update_last_checked_date.emplace(timeutil::now());
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::minutes{ UPDATE_CHECK_AFTER_FAILED_INTERVAL_MINUTES });
|
||||
}
|
||||
UpdateState::store([](UpdateState& state) {
|
||||
state.github_update_last_checked_date.emplace(timeutil::now());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<updating::new_version_download_info> check_for_updates()
|
||||
std::optional<updating::github_version_info> check_for_updates()
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto new_version = updating::get_new_github_version_info_async(Strings).get();
|
||||
if (!new_version)
|
||||
auto version_check_result = updating::get_github_version_info_async(Strings).get();
|
||||
if (!version_check_result)
|
||||
{
|
||||
updating::notifications::show_unavailable(Strings, std::move(new_version.error()));
|
||||
updating::notifications::show_unavailable(Strings, std::move(version_check_result.error()));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
updating::notifications::show_available(new_version.value(), Strings);
|
||||
return std::move(new_version.value());
|
||||
if (std::holds_alternative<updating::version_up_to_date>(*version_check_result))
|
||||
{
|
||||
updating::notifications::show_unavailable(Strings, Strings.GITHUB_NEW_VERSION_UP_TO_DATE);
|
||||
return std::move(*version_check_result);
|
||||
}
|
||||
|
||||
auto new_version = std::get<updating::new_version_download_info>(*version_check_result);
|
||||
updating::notifications::show_available(new_version, Strings);
|
||||
return std::move(new_version);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
|
||||
bool start_msi_uninstallation_sequence();
|
||||
void github_update_worker();
|
||||
std::optional<updating::new_version_download_info> check_for_updates();
|
||||
std::optional<updating::github_version_info> check_for_updates();
|
||||
bool launch_pending_update();
|
||||
Reference in New Issue
Block a user