Skip to content

Commit 4d598c5

Browse files
Merge pull request mixxxdj#15214 from acolombier/feat/qml-prevent-user-setting-corruption
feat(QML): add checks to ensure user run with a dedicated test profile
2 parents 2055e8c + 82cd64b commit 4d598c5

6 files changed

Lines changed: 69 additions & 3 deletions

File tree

src/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ int runMixxx(MixxxApplication* pApp, const CmdlineArgs& args) {
9393

9494
pCoreServices->initialize(pApp);
9595

96+
if (pCoreServices->getSettings()->getValue(
97+
ConfigKey("[Config]", "did_run_with_unstable"), false)) {
98+
qInfo() << "User previously ran the unstable version on this profile";
99+
}
100+
96101
#ifdef MIXXX_USE_QOPENGL
97102
// Will call initialize when the initial wglwidget's
98103
// qopenglwindow has been exposed

src/preferences/upgrade.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,20 @@ UserSettingsPointer Upgrade::versionUpgrade(const QString& settingsPath) {
357357
else {
358358
#endif
359359
// This must have been the first run... right? :)
360-
qDebug() << "No version number in configuration file. Setting to"
361-
<< VersionStore::version();
362-
config->set(ConfigKey("[Config]", "Version"), ConfigValue(VersionStore::version()));
360+
#ifdef MIXXX_USE_QML
361+
if (CmdlineArgs::Instance().isQml()) {
362+
// If running the QML version (aka 3.0 unstable), we set a dummy
363+
// unstable version in the settings. This is used to detect if
364+
// the current user profile is being used for testing purpose
365+
// and if it is safe for the user to potentially lose their data
366+
config->setValue(ConfigKey("[Config]", "Version"), VersionStore::FUTURE_UNSTABLE);
367+
} else
368+
#endif
369+
{
370+
qDebug() << "No version number in configuration file. Setting to"
371+
<< VersionStore::version();
372+
config->set(ConfigKey("[Config]", "Version"), ConfigValue(VersionStore::version()));
373+
}
363374
m_bFirstRun = true;
364375
return config;
365376
#ifdef __APPLE__

src/qml/qmlapplication.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#include "qmlapplication.h"
22

3+
#include <qtextdocument.h>
4+
35
#include <QQmlEngineExtensionPlugin>
46
#include <QQuickStyle>
57

68
#include "controllers/controllermanager.h"
79
#include "mixer/playermanager.h"
810
#include "moc_qmlapplication.cpp"
11+
#include "preferences/configobject.h"
912
#include "qml/asyncimageprovider.h"
1013
#include "qml/qmldlgpreferencesproxy.h"
1114
#include "soundio/soundmanager.h"
15+
#include "util/versionstore.h"
1216
#include "waveform/visualsmanager.h"
1317
#include "waveform/waveformwidgetfactory.h"
1418
Q_IMPORT_QML_PLUGIN(MixxxPlugin)
@@ -42,6 +46,36 @@ QmlApplication::QmlApplication(
4246
QQuickStyle::setStyle("Basic");
4347

4448
m_pCoreServices->initialize(app);
49+
50+
QString configVersion = m_pCoreServices->getSettings()->getValue(
51+
ConfigKey("[Config]", "Version"), "");
52+
if (configVersion == VersionStore::FUTURE_UNSTABLE) {
53+
qDebug() << "Generating a new user profile for safe testing with unstable code";
54+
} else if (CmdlineArgs::Instance().isAwareOfRisk()) {
55+
qCritical() << "Existing user profile detected from" << configVersion
56+
<< "but you said you wanted to play with fire!";
57+
m_pCoreServices->getSettings()->setValue(
58+
ConfigKey("[Config]", "did_run_with_unstable"), true);
59+
} else {
60+
QMessageBox msgBox;
61+
msgBox.setIcon(QMessageBox::Critical);
62+
msgBox.setWindowTitle(tr("Existing user profile detected"));
63+
msgBox.setText(
64+
tr("Trying to run Mixxx 3.0 with an existing %0 user profile! "
65+
"<br><br>There is <b>serious risks</b> of data loss and "
66+
"corruption.<br>We recommend using a test profile folder "
67+
"with the '--settings-path' argument. <br><br>If you want "
68+
"to continue at your own risk, run Mixxx with the argument "
69+
"'--allow-dangerous-data-corruption-risk'.")
70+
.arg(configVersion));
71+
72+
QPushButton* continueButton =
73+
msgBox.addButton(tr("Ok"), QMessageBox::ActionRole);
74+
msgBox.exec();
75+
m_pCoreServices.reset();
76+
exit(-1);
77+
}
78+
4579
SoundDeviceStatus result = m_pCoreServices->getSoundManager()->setupDevices();
4680
if (result != SoundDeviceStatus::Ok) {
4781
const int reInt = static_cast<int>(result);

src/util/cmdlineargs.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
285285
"Loads experimental QML GUI instead of legacy QWidget skin")
286286
: QString());
287287
parser.addOption(qml);
288+
const QCommandLineOption awareOfRisk(
289+
QStringLiteral("allow-dangerous-data-corruption-risk"),
290+
forUserFeedback
291+
? QCoreApplication::translate("CmdlineArgs",
292+
"Force Mixxx to load an unstable version with an "
293+
"existing user profile from a stable version")
294+
: QString());
295+
parser.addOption(awareOfRisk);
288296
#endif
289297
const QCommandLineOption safeMode(QStringLiteral("safe-mode"),
290298
forUserFeedback ? QCoreApplication::translate("CmdlineArgs",
@@ -459,6 +467,7 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
459467
m_developer = parser.isSet(developer);
460468
#ifdef MIXXX_USE_QML
461469
m_qml = parser.isSet(qml);
470+
m_awareOfRisk = parser.isSet(awareOfRisk);
462471
#endif
463472
m_safeMode = parser.isSet(safeMode) || parser.isSet(safeModeDeprecated);
464473
m_debugAssertBreak = parser.isSet(debugAssertBreak) || parser.isSet(debugAssertBreakDeprecated);

src/util/cmdlineargs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class CmdlineArgs final {
5050
bool isQml() const {
5151
return m_qml;
5252
}
53+
bool isAwareOfRisk() const {
54+
return m_awareOfRisk;
55+
}
5356
#endif
5457
bool getSafeMode() const { return m_safeMode; }
5558
bool useColors() const {
@@ -106,6 +109,7 @@ class CmdlineArgs final {
106109
bool m_developer; // Developer Mode
107110
#ifdef MIXXX_USE_QML
108111
bool m_qml;
112+
bool m_awareOfRisk;
109113
#endif
110114
bool m_safeMode;
111115
bool m_useLegacyVuMeter;

src/util/versionstore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <QVersionNumber>
66

77
namespace VersionStore {
8+
/// Constant to store the future unreleased Mixxx 3.0
9+
static QString FUTURE_UNSTABLE = QStringLiteral("3.0-unstable");
10+
811
/// Returns the current Mixxx version string (e.g. 1.12.0-alpha)
912
QString version();
1013

0 commit comments

Comments
 (0)