diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index c9c2213a1..87847ba94 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -1917,6 +1917,18 @@ bool Host::ConfirmMessage(std::string_view title, std::string_view message) QString::fromUtf8(message.data(), message.size())); } +void Host::ConfirmMessageAsync(std::string_view title, std::string_view message, ConfirmMessageAsyncCallback callback) +{ + QtHost::RunOnUIThread([title = QtUtils::StringViewToQString(title), message = QtUtils::StringViewToQString(message), + callback = std::move(callback)]() mutable { + auto lock = g_main_window->pauseAndLockSystem(); + + const bool result = (QMessageBox::question(lock.getDialogParent(), title, message) != QMessageBox::No); + + callback(result); + }); +} + void Host::OpenURL(std::string_view url) { QtHost::RunOnUIThread([url = QtUtils::StringViewToQString(url)]() { QtUtils::OpenURL(g_main_window, QUrl(url)); }); diff --git a/src/duckstation-regtest/regtest_host.cpp b/src/duckstation-regtest/regtest_host.cpp index c7923c9ac..9f96a69c8 100644 --- a/src/duckstation-regtest/regtest_host.cpp +++ b/src/duckstation-regtest/regtest_host.cpp @@ -150,6 +150,16 @@ bool Host::ConfirmMessage(std::string_view title, std::string_view message) return true; } +void Host::ConfirmMessageAsync(std::string_view title, std::string_view message, ConfirmMessageAsyncCallback callback) +{ + if (!title.empty() && !message.empty()) + ERROR_LOG("ConfirmMessage: {}: {}", title, message); + else if (!message.empty()) + ERROR_LOG("ConfirmMessage: {}", message); + + callback(true); +} + void Host::ReportDebuggerMessage(std::string_view message) { ERROR_LOG("ReportDebuggerMessage: {}", message); diff --git a/src/util/host.h b/src/util/host.h index 5afe611ab..d0258bfba 100644 --- a/src/util/host.h +++ b/src/util/host.h @@ -8,6 +8,7 @@ #include "common/types.h" #include +#include #include #include #include @@ -44,6 +45,11 @@ void ReportErrorAsync(std::string_view title, std::string_view message); /// Displays a synchronous confirmation on the UI thread, i.e. blocks the caller. bool ConfirmMessage(std::string_view title, std::string_view message); +/// Displays an asynchronous confirmation on the UI thread, but does not block the caller. +/// The callback may be executed on a different thread. Use RunOnCPUThread() in the callback to ensure safety. +using ConfirmMessageAsyncCallback = std::function; +void ConfirmMessageAsync(std::string_view title, std::string_view message, ConfirmMessageAsyncCallback callback); + /// Returns the user agent to use for HTTP requests. std::string GetHTTPUserAgent();