Skip to content

Commit

Permalink
Changed RpcHub missing function handling.
Browse files Browse the repository at this point in the history
Missing functions no longer cause log messages
to be emitted, but are collected in an error container.
  • Loading branch information
5cript committed Sep 26, 2023
1 parent 81b96ac commit 8a5e999
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions nui/include/nui/backend/rpc_hub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ namespace Nui
RpcHub& operator=(RpcHub&&) = delete;

constexpr static char const* remoteCallScript = R"(
(function() {{
globalThis.nui_rpc.frontend["{}"]({});
}})();
)";
(function() {{
if (globalThis.nui_rpc.frontend.hasOwnProperty("{0}")) {{
globalThis.nui_rpc.frontend["{0}"]({1});
return;
}}
constexpr static char const* remoteCallScript0Args = R"(
(function() {{
globalThis.nui_rpc.frontend["{}"](undefined);
globalThis.nui_rpc.errors = globalThis.nui_rpc.errors || [];
globalThis.nui_rpc.errors.push("Function {0} does not exist.");
if (globalThis.nui_rpc.errors.length > 100) {{
globalThis.nui_rpc.errors.shift();
}}
}})();
)";

Expand Down Expand Up @@ -243,7 +246,7 @@ namespace Nui
void callRemoteImpl(std::string const& name) const
{
// window is threadsafe.
window_->eval(fmt::format(remoteCallScript0Args, name));
window_->eval(fmt::format(remoteCallScript, name, "undefined"));
}

private:
Expand Down

0 comments on commit 8a5e999

Please sign in to comment.