mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 10:23:02 -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()
|
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->setShareSelectable(false);
|
||||||
visualDeckStorageWidget->clearShareSelection();
|
visualDeckStorageWidget->clearShareSelection();
|
||||||
shareBar->setVisible(false);
|
shareBar->setVisible(false);
|
||||||
|
|
@ -165,8 +169,17 @@ void TabDeckStorageVisual::actShareSelected()
|
||||||
}
|
}
|
||||||
|
|
||||||
shareBar->setCreateEnabled(false);
|
shareBar->setCreateEnabled(false);
|
||||||
|
const int seq = ++shareRequestSeq;
|
||||||
|
shareInFlightSeq = seq;
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
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);
|
client->sendCommand(pend);
|
||||||
shareTimeoutTimer->start();
|
shareTimeoutTimer->start();
|
||||||
}
|
}
|
||||||
|
|
@ -207,6 +220,10 @@ void TabDeckStorageVisual::showShareNotice(const QString &message, bool warning)
|
||||||
|
|
||||||
void TabDeckStorageVisual::onShareTimeout()
|
void TabDeckStorageVisual::onShareTimeout()
|
||||||
{
|
{
|
||||||
|
if (shareInFlightSeq == 0) {
|
||||||
|
return; // share mode was left while the request was still outstanding
|
||||||
|
}
|
||||||
|
shareInFlightSeq = 0;
|
||||||
shareBar->setCreateEnabled(true);
|
shareBar->setCreateEnabled(true);
|
||||||
showShareNotice(tr("The server did not respond in time. Try again."), true);
|
showShareNotice(tr("The server did not respond in time. Try again."), true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@ private:
|
||||||
ShareBarWidget *shareBar;
|
ShareBarWidget *shareBar;
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
QTimer *shareTimeoutTimer;
|
QTimer *shareTimeoutTimer;
|
||||||
|
int shareRequestSeq = 0;
|
||||||
|
int shareInFlightSeq = 0;
|
||||||
bool shareDeckAvailable = false;
|
bool shareDeckAvailable = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue