async: add Promise and use it for AsyncDialogBox

This commit is contained in:
Vaxry 2025-04-27 00:03:32 +01:00
parent 4f868a1f3c
commit 0302bfdc22
No known key found for this signature in database
GPG key ID: 665806380871D640
7 changed files with 208 additions and 36 deletions

View file

@ -2,6 +2,7 @@
#include "../macros.hpp"
#include "./memory/Memory.hpp"
#include "./defer/Promise.hpp"
#include <vector>
#include <functional>
@ -15,29 +16,30 @@ class CAsyncDialogBox {
public:
static SP<CAsyncDialogBox> create(const std::string& title, const std::string& description, std::vector<std::string> buttons);
CAsyncDialogBox(const CAsyncDialogBox&) = delete;
CAsyncDialogBox(CAsyncDialogBox&&) = delete;
CAsyncDialogBox& operator=(const CAsyncDialogBox&) = delete;
CAsyncDialogBox& operator=(CAsyncDialogBox&&) = delete;
CAsyncDialogBox(const CAsyncDialogBox&) = delete;
CAsyncDialogBox(CAsyncDialogBox&&) = delete;
CAsyncDialogBox& operator=(const CAsyncDialogBox&) = delete;
CAsyncDialogBox& operator=(CAsyncDialogBox&&) = delete;
void open(std::function<void(std::string)> onResolution);
void kill();
bool isRunning() const;
SP<CPromise<std::string>> open();
void kill();
bool isRunning() const;
void onWrite(int fd, uint32_t mask);
void onWrite(int fd, uint32_t mask);
private:
CAsyncDialogBox(const std::string& title, const std::string& description, std::vector<std::string> buttons);
pid_t m_dialogPid = 0;
wl_event_source* m_readEventSource = nullptr;
std::function<void(std::string)> m_onResolution;
Hyprutils::OS::CFileDescriptor m_pipeReadFd;
std::string m_stdout = "";
pid_t m_dialogPid = 0;
wl_event_source* m_readEventSource = nullptr;
Hyprutils::OS::CFileDescriptor m_pipeReadFd;
std::string m_stdout = "";
const std::string m_title;
const std::string m_description;
const std::vector<std::string> m_buttons;
const std::string m_title;
const std::string m_description;
const std::vector<std::string> m_buttons;
SP<CPromiseResolver<std::string>> m_promiseResolver;
// WARNING: cyclic reference. This will be removed once the event source is removed to avoid dangling pointers
SP<CAsyncDialogBox> m_selfReference;