mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[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.
This commit is contained in:
parent
ffa3971e90
commit
02f2f20356
2 changed files with 20 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue