Skip to content

Commit 174d3f3

Browse files
committed
add event for checking if devtools is open
1 parent 492429c commit 174d3f3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/API.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ namespace devtools {
3131
using Event::Event;
3232
};
3333

34+
struct IsOpenEvent final : geode::Event<IsOpenEvent, bool(bool&)> {
35+
using Event::Event;
36+
};
37+
3438
template <typename T>
3539
struct PropertyFnEvent final : geode::Event<PropertyFnEvent<T>, bool(bool(*&)(geode::ZStringView name, T&))> {
3640
using Fn = bool(geode::ZStringView name, T&);
@@ -49,6 +53,14 @@ namespace devtools {
4953
return geode::Loader::get()->getLoadedMod("geode.devtools") != nullptr;
5054
}
5155

56+
/// @brief Checks if DevTools is currently open.
57+
/// @return True if DevTools is open, false otherwise.
58+
inline bool isOpen() {
59+
bool isOpen = false;
60+
IsOpenEvent().send(isOpen);
61+
return isOpen;
62+
}
63+
5264
/// @brief Waits for DevTools to be loaded and then calls the provided callback.
5365
/// @param callback The function to call once DevTools is loaded.
5466
template <typename F>

src/API.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ bool devtools::button(ZStringView label) {
9292
return ListenerResult::Stop;
9393
}).leak();
9494

95+
devtools::IsOpenEvent().listen([](bool& isOpen) {
96+
isOpen = DevTools::get()->isVisible();
97+
return ListenerResult::Stop;
98+
}).leak();
99+
95100
// Scalars & Enums
96101
handleType<char>();
97102
handleType<unsigned char>();

0 commit comments

Comments
 (0)