From 2cf03124de22a02159d51368d03f9b47abde5b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 20 Sep 2026 19:28:10 +0200 Subject: [PATCH] [DeckShare] Abandon an in-flight tile share on cancel exitShareMode() left shareTimeoutTimer running and did not abandon the pending Command_DeckShareCreate, so a timer pop or a late success still reported the share after the user cancelled. Stop the timer and ignore stale responses via a sequence number, mirroring the tree tab. --- .../tab_deck_storage_visual.cpp | 19 ++++++++++++++++++- .../tab_deck_storage_visual.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index 5ea0fa89a..d42740cb0 100644 --- a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -103,6 +103,10 @@ void TabDeckStorageVisual::enterShareMode(const QStringList &preselectFiles) void TabDeckStorageVisual::exitShareMode() { + // Abandon any in-flight request: otherwise the timer keeps running and a late + // response reports the share as created after the user already backed out. + shareTimeoutTimer->stop(); + shareInFlightSeq = 0; visualDeckStorageWidget->setShareSelectable(false); visualDeckStorageWidget->clearShareSelection(); shareBar->setVisible(false); @@ -165,8 +169,17 @@ void TabDeckStorageVisual::actShareSelected() } shareBar->setCreateEnabled(false); + const int seq = ++shareRequestSeq; + shareInFlightSeq = seq; PendingCommand *pend = client->prepareSessionCommand(cmd); - connect(pend, &PendingCommand::finished, this, &TabDeckStorageVisual::shareFinished); + connect(pend, &PendingCommand::finished, this, + [this, seq](const Response &response, const CommandContainer &commandContainer) { + if (shareInFlightSeq != seq) { + return; // the user cancelled or a newer request superseded this one + } + shareInFlightSeq = 0; + shareFinished(response, commandContainer); + }); client->sendCommand(pend); shareTimeoutTimer->start(); } @@ -207,6 +220,10 @@ void TabDeckStorageVisual::showShareNotice(const QString &message, bool warning) void TabDeckStorageVisual::onShareTimeout() { + if (shareInFlightSeq == 0) { + return; // share mode was left while the request was still outstanding + } + shareInFlightSeq = 0; shareBar->setCreateEnabled(true); showShareNotice(tr("The server did not respond in time. Try again."), true); } diff --git a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h index 549f7bf07..1878ae9e8 100644 --- a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h +++ b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h @@ -77,6 +77,8 @@ private: ShareBarWidget *shareBar; AbstractClient *client; QTimer *shareTimeoutTimer; + int shareRequestSeq = 0; + int shareInFlightSeq = 0; bool shareDeckAvailable = false; };