mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[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.
This commit is contained in:
parent
02f2f20356
commit
2cf03124de
2 changed files with 20 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ private:
|
|||
ShareBarWidget *shareBar;
|
||||
AbstractClient *client;
|
||||
QTimer *shareTimeoutTimer;
|
||||
int shareRequestSeq = 0;
|
||||
int shareInFlightSeq = 0;
|
||||
bool shareDeckAvailable = false;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue