Improve crash detection logic

pull/298/head
James H Ball 2025-04-20 20:11:11 +01:00
rodzic edff0e529e
commit f7f4f7b0eb
4 zmienionych plików z 50 dodań i 29 usunięć

Wyświetl plik

@ -360,3 +360,44 @@ void CommonAudioProcessor::saveGlobalSettings()
if (globalSettings != nullptr)
globalSettings->saveIfNeeded();
}
bool CommonAudioProcessor::programCrashedAndUserWantsToReset() {
bool userWantsToReset = false;
if (!hasSetSessionStartTime) {
// check that the previous end time is later than the start time.
// if not, the program did not close properly.
juce::String startTime = getGlobalStringValue("startTime");
juce::String endTime = getGlobalStringValue("endTime");
if ((startTime.isNotEmpty() && endTime.isNotEmpty()) || (startTime.isNotEmpty() && endTime.isEmpty())) {
juce::Time start = juce::Time::fromISO8601(startTime);
juce::Time end = juce::Time::fromISO8601(endTime);
if ((start > end || end == juce::Time()) && juce::MessageManager::getInstance()->isThisTheMessageThread()) {
juce::String message = "It appears that " + juce::String(ProjectInfo::projectName) + " did not close properly during your last session. This may indicate a problem with your project or session.";
// Use a synchronous dialog to ensure user makes a choice before proceeding
bool userPressedReset = juce::AlertWindow::showOkCancelBox(
juce::AlertWindow::WarningIcon,
"Possible Crash Detected",
message + "\n\nDo you want to reset to a new project, or continue loading your previous session?",
"Reset to New Project",
"Continue",
nullptr,
nullptr
);
if (userPressedReset) {
userWantsToReset = true;
}
}
}
setGlobalValue("startTime", juce::Time::getCurrentTime().toISO8601(true));
saveGlobalSettings();
hasSetSessionStartTime = true;
}
return userWantsToReset;
}

Wyświetl plik

@ -74,6 +74,9 @@ public:
void removeGlobalValue(const juce::String& keyName);
void saveGlobalSettings();
bool hasSetSessionStartTime = false;
bool programCrashedAndUserWantsToReset();
juce::SpinLock audioPlayerListenersLock;
std::vector<AudioPlayerListener*> audioPlayerListeners;

Wyświetl plik

@ -709,37 +709,10 @@ void OscirenderAudioProcessor::getStateInformation(juce::MemoryBlock& destData)
}
void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInBytes) {
// check that the previous end time is later than the start time.
// if not, the program did not close properly.
juce::String startTime = getGlobalStringValue("startTime");
juce::String endTime = getGlobalStringValue("endTime");
if (startTime.isNotEmpty() && endTime.isNotEmpty()) {
juce::Time start = juce::Time::fromISO8601(startTime);
juce::Time end = juce::Time::fromISO8601(endTime);
if ((start > end || end == juce::Time()) && juce::MessageManager::getInstance()->isThisTheMessageThread()) {
juce::String message = "It appears that " + juce::String(ProjectInfo::projectName) + " did not close properly during your last session. This may indicate a problem with your project or session.";
// Use a synchronous dialog to ensure user makes a choice before proceeding
bool userPressedReset = juce::AlertWindow::showOkCancelBox(
juce::AlertWindow::WarningIcon,
"Possible Crash Detected",
message + "\n\nDo you want to reset to a new project, or continue loading your previous session?",
"Reset to New Project",
"Continue",
nullptr,
nullptr
);
if (userPressedReset) {
return;
}
}
if (juce::JUCEApplicationBase::isStandaloneApp() && programCrashedAndUserWantsToReset()) {
return;
}
setGlobalValue("startTime", juce::Time::getCurrentTime().toISO8601(true));
std::unique_ptr<juce::XmlElement> xml;
const uint32_t magicXmlNumber = 0x21324356;

Wyświetl plik

@ -135,6 +135,10 @@ void SosciAudioProcessor::getStateInformation(juce::MemoryBlock& destData) {
}
void SosciAudioProcessor::setStateInformation(const void* data, int sizeInBytes) {
if (juce::JUCEApplicationBase::isStandaloneApp() && programCrashedAndUserWantsToReset()) {
return;
}
std::unique_ptr<juce::XmlElement> xml;
const uint32_t magicXmlNumber = 0x21324356;