From 0302bfdc2207f9b5482fb07aa6052e7f6cb237ca Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 27 Apr 2025 00:03:32 +0100 Subject: async: add Promise and use it for AsyncDialogBox --- src/helpers/AsyncDialogBox.hpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/helpers/AsyncDialogBox.hpp') diff --git a/src/helpers/AsyncDialogBox.hpp b/src/helpers/AsyncDialogBox.hpp index d3cc242c..0cb95846 100644 --- a/src/helpers/AsyncDialogBox.hpp +++ b/src/helpers/AsyncDialogBox.hpp @@ -2,6 +2,7 @@ #include "../macros.hpp" #include "./memory/Memory.hpp" +#include "./defer/Promise.hpp" #include #include @@ -15,29 +16,30 @@ class CAsyncDialogBox { public: static SP create(const std::string& title, const std::string& description, std::vector 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 onResolution); - void kill(); - bool isRunning() const; + SP> 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 buttons); - pid_t m_dialogPid = 0; - wl_event_source* m_readEventSource = nullptr; - std::function 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 m_buttons; + const std::string m_title; + const std::string m_description; + const std::vector m_buttons; + + SP> m_promiseResolver; // WARNING: cyclic reference. This will be removed once the event source is removed to avoid dangling pointers SP m_selfReference; -- cgit v1.2.3