[Client] Improve card database update visibility (#7458)

* [Client] Improve card database update visibility

Addresses Cockatrice/Cockatrice#7431.

Cockatrice previously offered no in-client feedback while the card
database updater ran: the only progress UI lived in the first-run
wizard, stderr/stdout were not parsed in interactive runs, and starting
a second update with Oracle already open or with a hidden background run
active just showed a confusing 'already running' guard - even though
Oracle is launched as a separate process with no lifecycle tracking.

- Add a status-bar widget (CardDatabaseUpdateStatusBar) that appears
  while an update runs and shows the Downloading/Parsing/Importing
  stages with percent progress; it is also used in the quit-confirm
  prompt so users see an unfinished update before cancelling it.
- Parse the updater's PROGRESS lines (new CardUpdateProgressParser,
  unit-tested) in both foreground and background runs and log stage
  changes to the new card_database.update category, throttled to at
  most one line per second; forward Oracle stderr to the logs.
- Show a tray balloon when a background update starts and on finish or
  failure instead of staying silent.
- Request a running Oracle instance to raise itself (QLocalServer
  CockatriceOracleRaise-<user>) when the user starts another update, and
  demote the 'already running' guard to an informative message only when
  no running instance can be found.
- Emit download/scan/import progress unconditionally from Oracle so
  interactive and background runs behave the same.
- Document the new log category in the troubleshooting guide.

* [Client] Address card database update review feedback

* [Client] Add setting to control card database update tray notifications

* [Client] Address remaining card database update review nits

- Rename card_update_progress_parser.{h,cpp} to card_update_progress.{h,cpp}
- Store the CardUpdateProgress struct in the status bar widget

* Lint.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-09 11:07:48 +02:00 • committed by GitHub
parent 6bed5d6f67
commit a44757bd11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 702 additions and 67 deletions

View file

@ -22,6 +22,7 @@ add_test(NAME report_categories_test COMMAND report_categories_test)
add_test(NAME lag_monitor_test COMMAND lag_monitor_test)
add_test(NAME latency_tracker_test COMMAND latency_tracker_test)
add_test(NAME metrics_registry_test COMMAND metrics_registry_test)
add_test(NAME card_update_progress_test COMMAND card_update_progress_test)
add_test(NAME loader_local_matching_test COMMAND loader_local_matching_test)
add_test(NAME deck_hash_performance_test COMMAND deck_hash_performance_test)
@ -75,6 +76,11 @@ add_executable(lag_monitor_test ${CMAKE_SOURCE_DIR}/cockatrice/src/client/lag_mo
target_include_directories(lag_monitor_test PRIVATE ${CMAKE_SOURCE_DIR}/cockatrice/src)
add_executable(latency_tracker_test latency_tracker_test.cpp)
add_executable(metrics_registry_test ../servatrice/src/metrics_registry.cpp metrics_registry_test.cpp)
add_executable(
card_update_progress_test ${CMAKE_SOURCE_DIR}/cockatrice/src/interface/card_database_update/card_update_progress.cpp
card_update_progress_test.cpp
)
target_include_directories(card_update_progress_test PRIVATE ${CMAKE_SOURCE_DIR}/cockatrice/src)
add_executable(
loader_local_matching_test
${CMAKE_SOURCE_DIR}/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp
@ -94,6 +100,7 @@ if(WITH_CLIENT)
single_instance_manager_test.cpp
)
target_include_directories(single_instance_manager_test PRIVATE ${CMAKE_SOURCE_DIR}/cockatrice/src)
target_include_directories(single_instance_manager_test PRIVATE ${CMAKE_SOURCE_DIR}/libcockatrice_utility)
add_test(NAME single_instance_manager_test COMMAND single_instance_manager_test)
endif()
@ -143,6 +150,7 @@ if(NOT GTEST_FOUND)
add_dependencies(lag_monitor_test gtest)
add_dependencies(latency_tracker_test gtest)
add_dependencies(metrics_registry_test gtest)
add_dependencies(card_update_progress_test gtest)
add_dependencies(loader_local_matching_test gtest)
add_dependencies(single_instance_manager_test gtest)
endif()
@ -201,6 +209,7 @@ target_link_libraries(
)
target_include_directories(metrics_registry_test PRIVATE ${CMAKE_SOURCE_DIR}/servatrice/src)
target_link_libraries(metrics_registry_test ${TEST_QT_MODULES} Threads::Threads ${GTEST_BOTH_LIBRARIES})
target_link_libraries(card_update_progress_test Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
target_link_libraries(
loader_local_matching_test libcockatrice_settings Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
)

View file

@ -0,0 +1,93 @@
#include "interface/card_database_update/card_update_progress.h"
#include <QByteArray>
#include <QString>
#include <gtest/gtest.h>
namespace
{
std::optional<CardUpdateProgress> parseLine(const QByteArray &line)
{
return CardUpdateProgress::fromProtocolLine(line);
}
} // namespace
TEST(CardUpdateProgressTest, ParsesAValidDownloadLine)
{
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS download 42 100");
ASSERT_TRUE(progress.has_value());
EXPECT_EQ(CardUpdateStage::Download, progress->stage);
EXPECT_EQ(42, progress->done);
EXPECT_EQ(100, progress->total);
}
TEST(CardUpdateProgressTest, ParsesTrailingNewline)
{
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS scan 7 99\n");
ASSERT_TRUE(progress.has_value());
EXPECT_EQ(CardUpdateStage::Scan, progress->stage);
EXPECT_EQ(7, progress->done);
EXPECT_EQ(99, progress->total);
}
TEST(CardUpdateProgressTest, ParsesWithSurroundingWhitespace)
{
const std::optional<CardUpdateProgress> progress = parseLine(QByteArray(" PROGRESS import 3 10 "));
ASSERT_TRUE(progress.has_value());
EXPECT_EQ(CardUpdateStage::Import, progress->stage);
EXPECT_EQ(3, progress->done);
EXPECT_EQ(10, progress->total);
}
TEST(CardUpdateProgressTest, AcceptsZeroProgress)
{
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS download 0 0");
ASSERT_TRUE(progress.has_value());
EXPECT_EQ(0, progress->done);
EXPECT_EQ(0, progress->total);
}
TEST(CardUpdateProgressTest, RejectsLinesWithoutProgressPrefix)
{
EXPECT_FALSE(parseLine("download 42 100").has_value());
EXPECT_FALSE(parseLine("PROGRESSdownload 42 100").has_value());
EXPECT_FALSE(parseLine("").has_value());
}
TEST(CardUpdateProgressTest, RejectsMalformedLines)
{
EXPECT_FALSE(parseLine("PROGRESS").has_value());
EXPECT_FALSE(parseLine("PROGRESS download").has_value());
EXPECT_FALSE(parseLine("PROGRESS download 42 100 extra").has_value());
EXPECT_FALSE(parseLine("PROGRESS download 42").has_value());
EXPECT_FALSE(parseLine("PROGRESS download notANumber 100").has_value());
}
TEST(CardUpdateProgressTest, RejectsNegativeValues)
{
EXPECT_FALSE(parseLine("PROGRESS download -1 100").has_value());
EXPECT_FALSE(parseLine("PROGRESS download 42 -100").has_value());
}
TEST(CardUpdateProgressTest, AcceptsUnknownStagesSchemalessly)
{
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS spoilers 1 2");
ASSERT_TRUE(progress.has_value());
EXPECT_EQ(CardUpdateStage::Unknown, progress->stage);
EXPECT_EQ(1, progress->done);
EXPECT_EQ(2, progress->total);
}
TEST(CardUpdateProgressTest, StageTokensRoundTrip)
{
EXPECT_EQ("download", CardUpdateProgress{CardUpdateStage::Download}.stageToken());
EXPECT_EQ("scan", CardUpdateProgress{CardUpdateStage::Scan}.stageToken());
EXPECT_EQ("import", CardUpdateProgress{CardUpdateStage::Import}.stageToken());
EXPECT_EQ("unknown", CardUpdateProgress{CardUpdateStage::Unknown}.stageToken());
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -166,6 +166,12 @@ TEST_F(SettingsDefaultsTest, Updates_NotifyAboutNewVersion_Default)
ASSERT_EQ(s.getNotifyAboutNewVersion(), true);
}
TEST_F(SettingsDefaultsTest, Updates_CardDatabaseUpdateTrayNotification_Default)
{
UpdatesSettings s(settingsPath, nullptr);
ASSERT_EQ(s.getCardDatabaseUpdateTrayNotification(), true);
}
TEST_F(SettingsDefaultsTest, Updates_UpdateReleaseChannelIndex_Default)
{
UpdatesSettings s(settingsPath, nullptr);