summaryrefslogtreecommitdiff
path: root/src/helpers/AsyncDialogBox.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-04-27 00:03:32 +0100
committerVaxry <vaxry@vaxry.net>2025-04-27 13:28:06 +0100
commit0302bfdc2207f9b5482fb07aa6052e7f6cb237ca (patch)
treec2039f2d4f01327b23b39493bc03b90d195fa6d3 /src/helpers/AsyncDialogBox.cpp
parent4f868a1f3c1edfc1f5998f7d21e46e7c23aeb02f (diff)
async: add Promise and use it for AsyncDialogBox
Diffstat (limited to 'src/helpers/AsyncDialogBox.cpp')
-rw-r--r--src/helpers/AsyncDialogBox.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/helpers/AsyncDialogBox.cpp b/src/helpers/AsyncDialogBox.cpp
index 73bae8f6..86eb9e1f 100644
--- a/src/helpers/AsyncDialogBox.cpp
+++ b/src/helpers/AsyncDialogBox.cpp
@@ -59,8 +59,7 @@ void CAsyncDialogBox::onWrite(int fd, uint32_t mask) {
if (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR)) {
Debug::log(LOG, "CAsyncDialogBox: dialog {:x} hung up, closed.");
- if (m_onResolution)
- m_onResolution(m_stdout);
+ m_promiseResolver->resolve(m_stdout);
wl_event_source_remove(m_readEventSource);
m_selfReference.reset();
@@ -68,9 +67,7 @@ void CAsyncDialogBox::onWrite(int fd, uint32_t mask) {
}
}
-void CAsyncDialogBox::open(std::function<void(std::string)> onResolution) {
- m_onResolution = onResolution;
-
+SP<CPromise<std::string>> CAsyncDialogBox::open() {
std::string buttonsString = "";
for (auto& b : m_buttons) {
buttonsString += b + ";";
@@ -83,7 +80,7 @@ void CAsyncDialogBox::open(std::function<void(std::string)> onResolution) {
int outPipe[2];
if (pipe(outPipe)) {
Debug::log(ERR, "CAsyncDialogBox::open: failed to pipe()");
- return;
+ return nullptr;
}
m_pipeReadFd = CFileDescriptor(outPipe[0]);
@@ -94,7 +91,7 @@ void CAsyncDialogBox::open(std::function<void(std::string)> onResolution) {
if (!m_readEventSource) {
Debug::log(ERR, "CAsyncDialogBox::open: failed to add read fd to loop");
- return;
+ return nullptr;
}
m_selfReference = m_selfWeakReference.lock();
@@ -102,13 +99,17 @@ void CAsyncDialogBox::open(std::function<void(std::string)> onResolution) {
if (!proc.runAsync()) {
Debug::log(ERR, "CAsyncDialogBox::open: failed to run async");
wl_event_source_remove(m_readEventSource);
- return;
+ return nullptr;
}
m_dialogPid = proc.pid();
// close the write fd, only the dialog owns it now
close(outPipe[1]);
+
+ auto promise = CPromise<std::string>::make([this](SP<CPromiseResolver<std::string>> r) { m_promiseResolver = r; });
+
+ return promise;
}
void CAsyncDialogBox::kill() {