Skip to content

Commit

Permalink
tweak: nui_devtools improvements for rootless NUI
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed May 25, 2020
1 parent d016801 commit 0143a47
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions code/components/nui-core/src/CefOverlay.cpp
Expand Up @@ -52,8 +52,8 @@ namespace nui
return g_mainUIFlag;
}

static std::unordered_map<std::string, fwRefContainer<NUIWindow>> windowList;
static std::shared_mutex windowListMutex;
std::unordered_map<std::string, fwRefContainer<NUIWindow>> windowList;
std::shared_mutex windowListMutex;

fwRefContainer<NUIWindow> FindNUIWindow(fwString windowName)
{
Expand Down
9 changes: 8 additions & 1 deletion code/components/nui-core/src/NUICallbacks_PushEvent.cpp
Expand Up @@ -94,7 +94,14 @@ class PushCallbacks

NUIClient::OnClientCreated.Connect([](NUIClient* client)
{
auto frameName = client->GetWindow()->GetName();
auto window = client->GetWindow();

if (!window)
{
return;
}

auto frameName = window->GetName();

if (frameName.find("nui_") == 0)
{
Expand Down
31 changes: 31 additions & 0 deletions code/components/nui-core/src/NUIInitialize.cpp
Expand Up @@ -709,6 +709,9 @@ std::set<std::string> g_recreateBrowsers;

namespace nui
{
extern std::unordered_map<std::string, fwRefContainer<NUIWindow>> windowList;
extern std::shared_mutex windowListMutex;

void Initialize(nui::GameInterface* gi)
{
g_nuiGi = gi;
Expand Down Expand Up @@ -799,12 +802,36 @@ void Initialize(nui::GameInterface* gi)
}
}
});
#else
static ConsoleCommand devtoolsListCmd("nui_devtools", []()
{
trace("Active NUI windows:\n");

std::shared_lock<std::shared_mutex> _(windowListMutex);

for (const auto& [ windowName, window ] : windowList)
{
std::string_view name = windowName;

if (name.find("nui_") == 0)
{
name = name.substr(4);
}

trace(" nui_devtools %s\n", name);
}
});
#endif

static ConsoleCommand devtoolsCmd("nui_devtools", [](const std::string& windowName)
{
auto browser = nui::GetNUIWindowBrowser(windowName);

if (!browser)
{
browser = nui::GetNUIWindowBrowser(fmt::sprintf("nui_%s", windowName));
}

if (browser)
{
CefWindowInfo wi;
Expand All @@ -814,6 +841,10 @@ void Initialize(nui::GameInterface* gi)

browser->GetHost()->ShowDevTools(wi, new NUIClient(nullptr), s, {});
}
else
{
trace("No such NUI window: %s\n", windowName);
}
});

g_nuiGi->OnInitRenderer.Connect([]()
Expand Down

0 comments on commit 0143a47

Please sign in to comment.