aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-07-26 00:56:14 +0530
committerAkshay Nair <phenax5@gmail.com>2025-07-26 00:56:14 +0530
commit68448538172663279919b29dd09b5faa51e0628a (patch)
tree032a321c645fca3aec7ba52efd60b55048536b2b /src
parent3f56d76a2b0d528c05ab8d0a38059ca82ba90952 (diff)
downloadnull-browser-68448538172663279919b29dd09b5faa51e0628a.tar.gz
null-browser-68448538172663279919b29dd09b5faa51e0628a.zip
Add web.schedule to schedule an action after qt+libuv tick
Diffstat (limited to 'src')
-rw-r--r--src/LuaRuntime.hpp1
-rw-r--r--src/LuaRuntimeApi.hpp23
-rw-r--r--src/WindowActionRouter.cpp3
3 files changed, 27 insertions, 0 deletions
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 1132270..5d8e7cc 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -64,6 +64,7 @@ signals:
void webview_scroll_bottom_requested(WebViewId webview_id);
void decoration_set_enabled(DecorationType type, bool enabled, std::optional<WindowId> win_id);
void set_view_html(const QString &html, WebViewId view_id);
+ void schedule_for_next_tick(const std::function<void()> &action);
protected:
LuaRuntime();
diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp
index 17e0fe9..06323f0 100644
--- a/src/LuaRuntimeApi.hpp
+++ b/src/LuaRuntimeApi.hpp
@@ -10,6 +10,27 @@
#include "widgets/BrowserWindow.hpp"
#include "widgets/Decorations.hpp"
+int lua_api_schedule_fn(lua_State *state) {
+ lua_pushvalue(state, 1);
+ const int function_ref = luaL_ref(state, LUA_REGISTRYINDEX);
+ auto action = [state, function_ref]() {
+ preserve_top(state, {
+ lua_rawgeti(state, LUA_REGISTRYINDEX, function_ref);
+ if (lua_pcall(state, 0, 0, 0) != LUA_OK) {
+ const char *error = lua_tostring(state, -1);
+ qDebug() << "Error calling Lua function:" << error;
+ }
+ luaL_unref(state, LUA_REGISTRYINDEX, function_ref);
+ })
+ };
+
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.schedule_for_next_tick(action);
+
+ lua_pushnil(state);
+ return 1;
+}
+
int lua_api_view_set_url(lua_State *state) {
const char *url = lua_tostring(state, 1);
WebViewId view_id = lua_isnoneornil(state, 2) ? 0 : lua_tointeger(state, 2);
@@ -78,6 +99,7 @@ int lua_api_keymap_set(lua_State *state) {
auto &runtime = LuaRuntime::instance();
emit runtime.keymap_add_requested(mode, keyseq, action);
+ lua_pushnil(state);
return 1;
}
@@ -337,5 +359,6 @@ static luaL_Reg internals_api[] = {
luaL_Reg{"decorations_set_enabled", &lua_api_decorations_set_enabled},
luaL_Reg{"decorations_get_enabled", &lua_api_decorations_get_enabled},
luaL_Reg{"decorations_get_view", &lua_api_decorations_get_view},
+ luaL_Reg{"schedule", &lua_api_schedule_fn},
luaL_Reg{nullptr, nullptr},
};
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 1278d48..99d9931 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -106,6 +106,9 @@ void WindowActionRouter::initialize(Configuration *config) {
for (auto *win : get_relevant_windows(win_id))
win->set_decoration_enabled(type, enabled);
});
+
+ connect(&runtime, &LuaRuntime::schedule_for_next_tick, this,
+ [](const std::function<void()> &action) { LuaRuntime::instance().queue_task(action); });
}
void WindowActionRouter::find_current_search_text(WebViewId webview_id, bool forward) {