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

@ -192,17 +192,7 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
switcher->m.lock();
if (switcher->VersionChanged(data, g_GIT_SHA1)) {
auto json = obs_data_get_json(data);
static QString jsonQString = json ? json : "";
std::thread t([]() {
obs_queue_task(
OBS_TASK_UI,
[](void *) {
AskForBackup(jsonQString);
},
nullptr, false);
});
t.detach();
AskForBackup(data);
}
switcher->LoadSettings(data);

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();

View File

@ -1,9 +1,9 @@
#pragma once
#include <QString>
#include <obs-data.h>
namespace advss {
void AskForBackup(const QString &json);
void AskForBackup(obs_data_t *settings);
void BackupSettingsOfCurrentVersion();
} // namespace advss

View File

@ -9,6 +9,8 @@
#include <QDir>
#include <QFile>
#include <QMainWindow>
#include <QTimer>
#include <thread>
@ -104,10 +106,13 @@ static bool wasUncleanShutdown()
return true;
}
static bool askForStartupSkip()
static void askForStartupSkip()
{
return DisplayMessage(obs_module_text("AdvSceneSwitcher.crashDetected"),
true, false);
bool skipStart = DisplayMessage(
obs_module_text("AdvSceneSwitcher.crashDetected"), true, false);
if (!skipStart) {
StartPlugin();
}
}
bool ShouldSkipPluginStartOnUncleanShutdown()
@ -116,16 +121,29 @@ bool ShouldSkipPluginStartOnUncleanShutdown()
return false;
}
// 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 start the plugin
// asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
static const auto showDialogWrapper = [](void *) {
#ifdef __APPLE__
QTimer::singleShot(0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
askForStartupSkip();
#ifdef __APPLE__
});
#endif
};
std::thread t([]() {
obs_queue_task(
OBS_TASK_UI,
[](void *) {
const bool skipStart = askForStartupSkip();
if (!skipStart) {
StartPlugin();
}
},
nullptr, false);
obs_queue_task(OBS_TASK_UI, showDialogWrapper, nullptr, false);
});
t.detach();

View File

@ -1,14 +1,12 @@
#include "non-modal-dialog.hpp"
#include "obs-module-helper.hpp"
#include <atomic>
#include <mutex>
#include <obs-frontend-api.h>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLayout>
#include <QMainWindow>
#include <QCoreApplication>
namespace advss {

View File

@ -7,7 +7,11 @@
#include "ui-helpers.hpp"
#include <QDialogButtonBox>
#include <QMainWindow>
#include <QTabWidget>
#include <QTimer>
#include <obs-frontend-api.h>
namespace advss {
@ -38,8 +42,29 @@ static bool setup()
}
};
// 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 update their Twitch
// connections asynchronously.
//
// On macOS, an additional QTimer::singleShot wrapper is required for
// this to work correctly.
AddLoadStep([](obs_data_t *) {
AddPostLoadStep([]() { showInvalidWarnings(); });
AddPostLoadStep([]() {
#ifdef __APPLE__
QTimer::singleShot(
0,
static_cast<QMainWindow *>(
obs_frontend_get_main_window()),
[]() {
#endif
showInvalidWarnings();
#ifdef __APPLE__
});
#endif
});
});
return true;