From 9c4b0b7ce459765fa1a63b410c3423b90f0d2a5f Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 7 May 2024 17:22:49 +0100 Subject: node: update uiInterface whenever warnings updated This commit introduces slight behaviour change. Previously, the GUI status bar would be updated for most warnings, namely UNKNOWN_NEW_RULES_ACTIVATED, CLOCK_OUT_OF_SYNC and PRE_RELEASE_TEST_BUILD, but not for LARGE_WORK_INVALID_CHAIN (and not for FATAL_INTERNAL_ERROR, but that is not really meaningful). Fix this by always updating the status bar when the warnings are changed. --- src/node/kernel_notifications.cpp | 1 - src/node/timeoffsets.cpp | 3 --- src/node/warnings.cpp | 6 +++++- src/node/warnings.h | 9 +++++---- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/node') diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp index e18919f503..c1a9e351b9 100644 --- a/src/node/kernel_notifications.cpp +++ b/src/node/kernel_notifications.cpp @@ -29,7 +29,6 @@ using util::ReplaceAll; static void AlertNotify(const std::string& strMessage) { - uiInterface.NotifyAlertChanged(); #if HAVE_SYSTEM std::string strCmd = gArgs.GetArg("-alertnotify", ""); if (strCmd.empty()) return; diff --git a/src/node/timeoffsets.cpp b/src/node/timeoffsets.cpp index b839b60565..d06a07b15a 100644 --- a/src/node/timeoffsets.cpp +++ b/src/node/timeoffsets.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include #include #include @@ -50,7 +49,6 @@ bool TimeOffsets::WarnIfOutOfSync() const auto median{std::max(Median(), std::chrono::seconds(std::numeric_limits::min() + 1))}; if (std::chrono::abs(median) <= WARN_THRESHOLD) { node::g_warnings.Unset(node::Warning::CLOCK_OUT_OF_SYNC); - uiInterface.NotifyAlertChanged(); return false; } @@ -64,6 +62,5 @@ bool TimeOffsets::WarnIfOutOfSync() const ), Ticks(WARN_THRESHOLD))}; LogWarning("%s\n", msg.original); node::g_warnings.Set(node::Warning::CLOCK_OUT_OF_SYNC, msg); - uiInterface.NotifyAlertChanged(); return true; } diff --git a/src/node/warnings.cpp b/src/node/warnings.cpp index 8a94eb0bd2..4e7fd3941c 100644 --- a/src/node/warnings.cpp +++ b/src/node/warnings.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -31,12 +32,15 @@ bool Warnings::Set(warning_type id, bilingual_str message) { LOCK(m_mutex); const auto& [_, inserted]{m_warnings.insert({id, std::move(message)})}; + if (inserted) uiInterface.NotifyAlertChanged(); return inserted; } bool Warnings::Unset(warning_type id) { - return WITH_LOCK(m_mutex, return m_warnings.erase(id)); + auto success{WITH_LOCK(m_mutex, return m_warnings.erase(id))}; + if (success) uiInterface.NotifyAlertChanged(); + return success; } std::vector Warnings::GetMessages() const diff --git a/src/node/warnings.h b/src/node/warnings.h index c85e8a16a9..b7ff74ecf4 100644 --- a/src/node/warnings.h +++ b/src/node/warnings.h @@ -31,7 +31,7 @@ enum class Warning { * @brief Manages warning messages within a node. * * The Warnings class provides mechanisms to set, unset, and retrieve - * warning messages. + * warning messages. It updates the GUI when warnings are changed. * * This class is designed to be non-copyable to ensure warnings * are managed centrally. @@ -52,7 +52,7 @@ public: * @brief Set a warning message. If a warning with the specified * `id` is already active, false is returned and the new * warning is ignored. If `id` does not yet exist, the - * warning is set, and true is returned. + * warning is set, the UI is updated, and true is returned. * * @param[in] id Unique identifier of the warning. * @param[in] message Warning message to be shown. @@ -63,8 +63,9 @@ public: bool Set(warning_type id, bilingual_str message) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex); /** * @brief Unset a warning message. If a warning with the specified - * `id` is active, it is unset, and true is returned. - * Otherwise, no warning is unset and false is returned. + * `id` is active, it is unset, the UI is updated, and true + * is returned. Otherwise, no warning is unset and false is + * returned. * * @param[in] id Unique identifier of the warning. * -- cgit v1.2.3