Skip to content

Commit

Permalink
Merge pull request #3144 from pljones/bugfix/2395-save-settings-on-st…
Browse files Browse the repository at this point in the history
…ate-change

Android: settings lost on GUI state change
  • Loading branch information
pljones authored Mar 28, 2024
2 parents 2f769f5 + 1ebb55f commit 6f28c7c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QSettings>
#include <QDir>
#ifndef HEADLESS
# include <QApplication>
# include <QMessageBox>
#endif
#include "global.h"
Expand All @@ -50,6 +51,31 @@ class CSettings : public QObject
strFileName ( "" )
{
QObject::connect ( QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CSettings::OnAboutToQuit );
#ifndef HEADLESS

// The Jamulus App will be created as either a QCoreApplication or QApplication (a subclass of QGuiApplication).
// State signals are only delivered to QGuiApplications, so we determine here whether we instantiated the GUI.
const QGuiApplication* pGApp = dynamic_cast<const QGuiApplication*> ( QCoreApplication::instance() );

if ( pGApp != nullptr )
{
# ifndef QT_NO_SESSIONMANAGER
QObject::connect (
pGApp,
&QGuiApplication::saveStateRequest,
this,
[=] ( QSessionManager& ) { Save(); },
Qt::DirectConnection );

# endif
QObject::connect ( pGApp, &QGuiApplication::applicationStateChanged, this, [=] ( Qt::ApplicationState state ) {
if ( Qt::ApplicationActive != state )
{
Save();
}
} );
}
#endif
}

void Load ( const QList<QString>& CommandLineOptions );
Expand Down

0 comments on commit 6f28c7c

Please sign in to comment.