Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect failed startups and prompt for safe mode #2799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ Misc:
- GBA: Improve detection of valid ELF ROMs
- mGUI: Enable auto-softpatching (closes mgba.io/i/2899)
- Scripting: Add `callbacks:oneshot` for single-call callbacks
- Qt: Detect failed startup and prompt for safe mode

0.10.2: (2023-04-23)
Emulation fixes:
35 changes: 35 additions & 0 deletions src/platform/qt/ConfigController.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

#include "ActionMapper.h"
#include "CoreController.h"
#include "Display.h"

#include <QDir>
#include <QMenu>
@@ -114,6 +115,16 @@ ConfigController::ConfigController(QObject* parent)
fileName.append("qt.ini");
m_settings = std::make_unique<QSettings>(fileName, QSettings::IniFormat);

if (getQtOption("loadStarted").toBool()) {
// If the loadStarted flag is lingering in qt.ini, then that indicates that
// the frontend crashed before clearing the flag.
// Prompt the user to enter into a safe mode to try to get safely started up.
setQtOption("safeModeWarning", true);
} else {
setQtOption("loadStarted", true);
m_settings->sync();
}

mCoreConfigInit(&m_config, PORT);

m_opts.audioSync = CoreController::AUDIO_SYNC;
@@ -306,6 +317,16 @@ void ConfigController::setQtOption(const QString& key, const QVariant& value, co
}
}

void ConfigController::removeQtOption(const QString& key, const QString& group) {
if (!group.isNull()) {
m_settings->beginGroup(group);
}
m_settings->remove(key);
if (!group.isNull()) {
m_settings->endGroup();
}
}

QStringList ConfigController::getMRU(ConfigController::MRU mruType) const {
QStringList mru;
m_settings->beginGroup(mruName(mruType));
@@ -354,6 +375,20 @@ void ConfigController::write() {
mCoreConfigMap(&m_config, &m_opts);
}

void ConfigController::setLoadingComplete() {
removeQtOption("loadStarted");
write();
}

void ConfigController::setSafeMode() {
setQtOption("displayDriver", static_cast<int>(Display::Driver::QT));
removeQtOption("safeModeWarning");
}

void ConfigController::declineSafeMode() {
removeQtOption("safeModeWarning");
}

void ConfigController::makePortable() {
mCoreConfigMakePortable(&m_config);

7 changes: 6 additions & 1 deletion src/platform/qt/ConfigController.h
Original file line number Diff line number Diff line change
@@ -104,6 +104,10 @@ Q_OBJECT
const mGraphicsOpts* graphicsOpts() const { return &m_graphicsOpts; }
void usage(const char* arg0) const;

void setLoadingComplete();
void setSafeMode();
void declineSafeMode();

static const QString& configDir();
static const QString& cacheDir();
static bool isPortable();
@@ -115,6 +119,7 @@ public slots:
void setOption(const char* key, const char* value);
void setOption(const char* key, const QVariant& value);
void setQtOption(const QString& key, const QVariant& value, const QString& group = QString());
void removeQtOption(const QString& key, const QString& group = QString());

void makePortable();
void write();
@@ -130,7 +135,7 @@ public slots:
mGraphicsOpts m_graphicsOpts{};
std::array<mSubParser, 2> m_subparsers;
bool m_parsed = false;

QHash<QString, QVariant> m_argvOptions;
QHash<QString, ConfigOption*> m_optionSet;
std::unique_ptr<QSettings> m_settings;
14 changes: 14 additions & 0 deletions src/platform/qt/GBAApp.cpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
#include <QFileOpenEvent>
#include <QFontDatabase>
#include <QIcon>
#include <QMessageBox>

#include <mgba/core/version.h>
#include <mgba/feature/updater.h>
@@ -384,6 +385,19 @@ void GBAApp::finishJob(qint64 jobId) {
m_workerJobCallbacks.remove(jobId);
}

void GBAApp::checkSafeMode() {
if (m_configController->getQtOption("safeModeWarning").toBool()) {
int choice = QMessageBox::warning(nullptr, tr("Safe Mode"),
tr("mGBA detected a problem while starting.\n\nWould you like to reset settings to failsafe values?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (choice == QMessageBox::Yes) {
m_configController->setSafeMode();
} else {
m_configController->declineSafeMode();
}
}
}

GBAApp::WorkerJob::WorkerJob(qint64 id, std::function<void ()> job, GBAApp* owner)
: m_id(id)
, m_job(job)
2 changes: 2 additions & 0 deletions src/platform/qt/GBAApp.h
Original file line number Diff line number Diff line change
@@ -82,6 +82,8 @@ Q_OBJECT
ApplicationUpdater* updater() { return &m_updater; }
QString invokeOnExit() { return m_invokeOnExit; }

void checkSafeMode();

public slots:
void restartForUpdate();
Window* newWindow();
9 changes: 5 additions & 4 deletions src/platform/qt/Window.cpp
Original file line number Diff line number Diff line change
@@ -122,17 +122,17 @@ Window::Window(CoreManager* manager, ConfigController* config, int playerId, QWi
if (value.toBool()) {
attachWidget(m_libraryView);
} else {
attachWidget(m_screenWidget);
attachWidget(m_screenWidget);
}
}
}, this);
m_config->updateOption("showLibrary");

ConfigOption* showFilenameInLibrary = m_config->addOption("showFilenameInLibrary");
showFilenameInLibrary->connect([this](const QVariant& value) {
m_libraryView->setShowFilename(value.toBool());
}, this);
m_config->updateOption("showFilenameInLibrary");
m_libraryView->setShowFilename(value.toBool());
}, this);
m_config->updateOption("showFilenameInLibrary");
ConfigOption* libraryStyle = m_config->addOption("libraryStyle");
libraryStyle->connect([this](const QVariant& value) {
m_libraryView->setViewStyle(static_cast<LibraryStyle>(value.toInt()));
@@ -734,6 +734,7 @@ void Window::showEvent(QShowEvent* event) {
}
reloadDisplayDriver();
setFocus();
m_config->setLoadingComplete();
}

void Window::hideEvent(QHideEvent* event) {
2 changes: 2 additions & 0 deletions src/platform/qt/main.cpp
Original file line number Diff line number Diff line change
@@ -118,6 +118,8 @@ int main(int argc, char* argv[]) {
langTranslator.load(locale, binaryName, "-", ":/translations/");
application.installTranslator(&langTranslator);

application.checkSafeMode();

Window* w = application.newWindow();
w->loadConfig();
w->argumentsPassed();