Skip to content

Commit

Permalink
Merge pull request #101 from NuiCpp/devel
Browse files Browse the repository at this point in the history
Added support for dispatch and mutable rpc lambdas.
  • Loading branch information
5cript authored Dec 14, 2023
2 parents fba94e2 + 353bc2a commit 9eec1ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nui/include/nui/backend/rpc_hub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Nui
template <typename FunctionT>
constexpr static auto wrapFunction(FunctionT&& func)
{
return [func = std::move(func)](nlohmann::json const& args) {
return [func = std::move(func)](nlohmann::json const& args) mutable {
func(args);
};
}
Expand All @@ -52,7 +52,7 @@ namespace Nui
template <typename FunctionT>
constexpr static auto wrapFunction(FunctionT&& func)
{
return [func = std::move(func)](nlohmann::json const& args) {
return [func = std::move(func)](nlohmann::json const& args) mutable {
func(extractJsonMember<ArgsTypes>(args[Is])...);
};
}
Expand Down
7 changes: 7 additions & 0 deletions nui/include/nui/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ namespace Nui
*/
void run();

/**
* @brief Run a function on the main thread
*
* @param func
*/
void dispatch(std::function<void()> func);

/**
* @brief Set page html from a string.
*
Expand Down
6 changes: 6 additions & 0 deletions nui/src/nui/backend/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,12 @@ namespace Nui
impl_->view->navigate("file://"s + file.string());
}
//---------------------------------------------------------------------------------------------------------------------
void Window::dispatch(std::function<void()> func)
{
std::scoped_lock lock{impl_->viewGuard};
impl_->view->dispatch(std::move(func));
}
//---------------------------------------------------------------------------------------------------------------------
void Window::run()
{
#ifdef _WIN32
Expand Down

0 comments on commit 9eec1ba

Please sign in to comment.