From 02f2f203567a9f64212873b3cf3b33cf7e7bc1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 20 Sep 2026 19:27:59 +0200 Subject: [PATCH] [DeckShare] Abandon an in-flight tree share on cancel Leaving share mode never stopped the timeout timer, and a late response still ran shareFromTreeFinished, copying the link and announcing success for a share the user backed out of. Stopping the timer and tracking the outstanding request by sequence number means a stale reply (or a timed-out one) after cancel is ignored, and cancelling + re-entering share mode can no longer confuse the two requests. --- .../widgets/tabs/tab_deck_storage.cpp | 19 ++++++++++++++++++- .../interface/widgets/tabs/tab_deck_storage.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp index b1f38793b..cde06fae6 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.cpp @@ -683,6 +683,10 @@ void TabDeckStorage::setShareModeEnabled(bool enabled) onServerSelectionChanged(); shareBar->focusName(); } else { + // 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; serverDirView->clearSelection(); } } @@ -775,8 +779,17 @@ void TabDeckStorage::actShareSelection() } shareBar->setCreateEnabled(false); + const int seq = ++shareRequestSeq; + shareInFlightSeq = seq; PendingCommand *pend = client->prepareSessionCommand(cmd); - connect(pend, &PendingCommand::finished, this, &TabDeckStorage::shareFromTreeFinished); + 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; + shareFromTreeFinished(response, commandContainer); + }); client->sendCommand(pend); shareTimeoutTimer->start(); } @@ -808,6 +821,10 @@ void TabDeckStorage::showShareNotice(const QString &message, bool warning) void TabDeckStorage::onShareFromTreeTimeout() { + 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/tab_deck_storage.h b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.h index a80537033..bc363010d 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_deck_storage.h +++ b/cockatrice/src/interface/widgets/tabs/tab_deck_storage.h @@ -39,6 +39,8 @@ private: QGroupBox *leftGroupBox, *rightGroupBox; ShareBarWidget *shareBar; QTimer *shareTimeoutTimer; + int shareRequestSeq = 0; + int shareInFlightSeq = 0; QAction *aOpenLocalDeck, *aRenameLocal, *aUpload, *aNewLocalFolder, *aDeleteLocalDeck; QAction *aOpenDecksFolder;