Add QTimer::singleShot() wrappers to display startup dialogs on macOS

This commit is contained in:
WarmUpTill
2026-02-10 21:29:19 +01:00
committed by WarmUpTill
parent 87c45e2b32
commit fcb3ea50d3
6 changed files with 101 additions and 31 deletions

View File

@@ -8,13 +8,18 @@
#include <obs-frontend-api.h>
#include <obs-module.h>
#include <QFileDialog>
#include <QTextStream>
#include <util/config-file.h>
#include <QFileDialog>
#include <QMainWindow>
#include <QTextStream>
#include <QTimer>
#include <thread>
namespace advss {
void AskForBackup(const QString &json)
static void showBackupDialogs(const QString &json)
{
const bool backupWasConfirmed = DisplayMessage(
obs_module_text("AdvSceneSwitcher.askBackup"), true, false);
@@ -42,6 +47,40 @@ void AskForBackup(const QString &json)
out << json;
}
void AskForBackup(obs_data_t *settings)
{
// This function is called while the plugin settings are being loaded.
// Blocking at this stage can cause issues such as OBS failing to start
// or crashing.
// Therefore, we ask the user whether they want to back up the settings
// asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
auto json = obs_data_get_json(settings);
static QString jsonQString = json ? json : "";
static const auto askForBackupWrapper = [](void *) {
#ifdef __APPLE__
QTimer::singleShot(0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
showBackupDialogs(jsonQString);
#ifdef __APPLE__
});
#endif
};
std::thread t([]() {
obs_queue_task(OBS_TASK_UI, askForBackupWrapper, nullptr,
false);
});
t.detach();
}
void BackupSettingsOfCurrentVersion()
{
auto sceneCollectionName = obs_frontend_get_current_scene_collection();