@@ -75,6 +75,7 @@ namespace QtHost
7575 static bool ParseCommandLineOptions (const QStringList& args, std::shared_ptr<VMBootParameters>& autoboot);
7676 static bool InitializeConfig ();
7777 static void SaveSettings ();
78+ static void SaveSecretsSettings ();
7879 static void HookSignals ();
7980 static void RegisterTypes ();
8081 static bool RunSetupWizard ();
@@ -1439,6 +1440,24 @@ void QtHost::SaveSettings()
14391440 }
14401441}
14411442
1443+ void QtHost::SaveSecretsSettings ()
1444+ {
1445+ pxAssertRel (!g_emu_thread->isOnEmuThread (), " Saving should happen on the UI thread." );
1446+
1447+ {
1448+ Error error;
1449+ auto lock = Host::GetSettingsLock ();
1450+ if (!s_secrets_settings_interface->Save (&error))
1451+ Console.ErrorFmt (" Failed to save settings: {}" , error.GetDescription ());
1452+ }
1453+
1454+ if (s_settings_save_timer)
1455+ {
1456+ s_settings_save_timer->deleteLater ();
1457+ s_settings_save_timer = nullptr ;
1458+ }
1459+ }
1460+
14421461void Host::CommitBaseSettingChanges ()
14431462{
14441463 if (!QtHost::IsOnUIThread ())
@@ -1447,6 +1466,35 @@ void Host::CommitBaseSettingChanges()
14471466 return ;
14481467 }
14491468
1469+ auto lock = Host::GetSettingsLock ();
1470+ if (s_settings_save_timer)
1471+ return ;
1472+
1473+ s_settings_save_timer = new QTimer;
1474+ s_settings_save_timer->connect (s_settings_save_timer, &QTimer::timeout, &QtHost::SaveSecretsSettings);
1475+ s_settings_save_timer->setSingleShot (true );
1476+ s_settings_save_timer->start (SETTINGS_SAVE_DELAY);
1477+
1478+ static bool connected = false ;
1479+ if (!connected)
1480+ {
1481+ QObject::connect (QCoreApplication::instance (), &QCoreApplication::aboutToQuit, []() {
1482+ delete s_settings_save_timer;
1483+ s_settings_save_timer = nullptr ;
1484+ });
1485+
1486+ connected = true ;
1487+ }
1488+ }
1489+
1490+ void Host::CommitSecretsSettingChanges ()
1491+ {
1492+ if (!QtHost::IsOnUIThread ())
1493+ {
1494+ QtHost::RunOnUIThread (&Host::CommitSecretsSettingChanges);
1495+ return ;
1496+ }
1497+
14501498 auto lock = Host::GetSettingsLock ();
14511499 if (s_settings_save_timer)
14521500 return ;
0 commit comments