Pause menu: Show a slot as busy while its save is being written

On a slow device, pausing again right after saving a state could show
the slot's Save and Load buttons enabled while the save was still being
written. The slot now has its buttons and screenshot disabled, with a
spinner, until the save ends, and the menu refreshes then.

The refresh message is now posted when a save ends any way (written,
failed or refused), after it has left the pending list, so the refresh
can't still see it as pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-11-11 14:22:33 +01:00
1 parent 562f22a60f
commit 42c6c4420b
4 files changed
+28 -6

No files matched your search

+1 -1
View File
@@ -330,7 +330,7 @@ enum class UIMessage {
RECENT_FILES_CHANGED,
SAVE_FRAME_DUMP,
ADHOC_SERVER_LIST_CHANGED,
SAVESTATE_SLOT_SAVED, // A slot's save state file was written.
SAVESTATE_SLOT_SAVED, // A save state save finished: written, failed or refused.
SOFT_KEYBOARD_HIDDEN, // The platform closed a soft keyboard forced by System_SetSoftKeyboardForced.
};
+14 -5
View File
@@ -454,9 +454,16 @@ int g_screenshotFailures;
// A save is done (written, failed or refused). Returns the callbacks of its repeats.
static std::vector<Callback> FinishPendingSave(const std::shared_ptr<SaveRecord> &save) {
std::lock_guard<std::mutex> guard(mutex);
g_pendingSaves.erase(std::remove(g_pendingSaves.begin(), g_pendingSaves.end(), save), g_pendingSaves.end());
return std::move(save->repeats);
std::vector<Callback> repeats;
{
std::lock_guard<std::mutex> guard(mutex);
g_pendingSaves.erase(std::remove(g_pendingSaves.begin(), g_pendingSaves.end(), save), g_pendingSaves.end());
repeats = std::move(save->repeats);
}
// The pause screen shows a slot with a save pending as busy, or listed it before the file was there.
// Posted after the save left the pending list, so the refresh doesn't still see it.
System_PostUIMessage(UIMessage::SAVESTATE_SLOT_SAVED);
return repeats;
}
static void RefuseOperation(const Operation &op) {
@@ -935,6 +942,10 @@ int g_screenshotFailures;
return g_files.find(GenerateSaveSlotFilename(gamePrefix, slot, extension)) != g_files.end();
}
bool IsSlotSavePending(std::string_view gamePrefix, int slot) {
return IsSavePending(GenerateSaveSlotPath(gamePrefix, slot, STATE_EXTENSION));
}
bool HasSaveInSlot(std::string_view gamePrefix, int slot) {
return SaveStateFileExists(gamePrefix, slot, STATE_EXTENSION);
}
@@ -1254,8 +1265,6 @@ int g_screenshotFailures;
g_Config.Save("Saving config for savestate last save undo");
}
g_filesStale = true;
// The pause screen may have listed the slots before the file was there.
System_PostUIMessage(UIMessage::SAVESTATE_SLOT_SAVED);
}
} else {
if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
+2
View File
@@ -68,6 +68,8 @@ namespace SaveState {
// Checks whether there's an existing save in the specified slot.
bool HasSaveInSlot(std::string_view gamePrefix, int slot);
// A save to the slot was asked for and isn't written yet. UIMessage::SAVESTATE_SLOT_SAVED says when it ends.
bool IsSlotSavePending(std::string_view gamePrefix, int slot);
bool HasUndoSaveInSlot(std::string_view gamePrefix, int slot);
bool HasUndoLastSave(std::string_view gamePrefix);
bool HasUndoLoad(std::string_view gamePrefix);
+11
View File
@@ -311,11 +311,18 @@ SaveSlotView::SaveSlotView(std::string_view saveStatePrefix, int slot, UI::Layou
OnScreenshotClicked.Trigger(e);
});
// A save to this slot is still being written (slow storage, a save asked for just before the menu
// opened). The screen is rebuilt when it finishes, on UIMessage::SAVESTATE_SLOT_SAVED.
const bool savePending = SaveState::IsSlotSavePending(saveStatePrefix_, slot_);
saveStateButton_->SetEnabled(!savePending);
fv->SetEnabled(!savePending);
if (SaveState::HasSaveInSlot(saveStatePrefix_, slot_)) {
if (!Achievements::HardcoreModeActive()) {
loadStateButton_ = buttons->Add(new Button(pa->T("Load State"), new LinearLayoutParams(0.0, Gravity::G_VCENTER)));
loadStateButton_->OnClick.Handle(this, &SaveSlotView::OnLoadState);
loadStateButton_->SetRoundCorners();
loadStateButton_->SetEnabled(!savePending);
}
std::string nameStr = SaveState::GetSlotCustomName(saveStatePrefix_, slot_);
@@ -340,6 +347,10 @@ SaveSlotView::SaveSlotView(std::string_view saveStatePrefix, int slot, UI::Layou
} else {
fv->SetFilename(Path());
}
if (savePending) {
buttons->Add(new Spinner(nullptr, 0, new LinearLayoutParams(32.0f, 32.0f, 0.0f, Gravity::G_VCENTER)));
}
}
void SaveSlotView::Draw(UIContext &dc) {