aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-08-02 22:19:24 +0530
committerAkshay Nair <phenax5@gmail.com>2025-08-02 22:19:24 +0530
commit0d1258aee3f39c8d5348588a87e804ec8cd27bd5 (patch)
tree60b0c15a9f61ab825a1e1d9c6f8388b0aaf03d7c
parentd37020870600d6c842f9a75ebd3986df6010c25c (diff)
downloadnull-browser-0d1258aee3f39c8d5348588a87e804ec8cd27bd5.tar.gz
null-browser-0d1258aee3f39c8d5348588a87e804ec8cd27bd5.zip
Add web.view.reload
-rw-r--r--lua/null-browser/api.lua16
-rw-r--r--lua/null-browser/defaults/vi.lua4
-rw-r--r--src/LuaRuntime.hpp1
-rw-r--r--src/LuaRuntimeApi.hpp9
-rw-r--r--src/WindowActionRouter.cpp3
-rw-r--r--src/widgets/BrowserWindow.cpp5
-rw-r--r--src/widgets/BrowserWindow.hpp1
-rw-r--r--src/widgets/Decorations.cpp2
-rw-r--r--src/widgets/Decorations.hpp1
-rw-r--r--src/widgets/IWebViewMediator.hpp1
-rw-r--r--src/widgets/WebViewStack.cpp10
-rw-r--r--src/widgets/WebViewStack.hpp1
12 files changed, 52 insertions, 2 deletions
diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua
index 5475beb..65a7663 100644
--- a/lua/null-browser/api.lua
+++ b/lua/null-browser/api.lua
@@ -132,7 +132,7 @@ function web.view.set_html(html, opts) return __internals.view_set_html(html, (o
--- @class RunJSOpts
--- @field view? number View id
---- Set html in a given view
+--- Run js in a given view
---
--- @param js string HTML string
--- @param opts? RunJSOpts Options
@@ -144,6 +144,20 @@ function web.view.set_html(html, opts) return __internals.view_set_html(html, (o
--- ```
function web.view.run_js(js, opts) return __internals.view_run_js(js, (opts or {}).view) end
+--- @class ReloadOpts
+--- @field view? number View id
+
+--- Relaod a given view
+---
+--- @param opts? RunJSOpts Options
+---
+--- @example
+--- ```lua
+--- web.view.reload()
+--- web.view.reload({ view = 3 }) -- Reload view with id 3
+--- ```
+function web.view.reload(opts) return __internals.view_reload((opts or {}).view) end
+
--- @class ExposeOpts
--- @field view? number View id
diff --git a/lua/null-browser/defaults/vi.lua b/lua/null-browser/defaults/vi.lua
index d6193de..ba7eaba 100644
--- a/lua/null-browser/defaults/vi.lua
+++ b/lua/null-browser/defaults/vi.lua
@@ -26,6 +26,10 @@ function M.initialize()
web.keymap.set('n', 'gg', function() web.view.scroll_to_top() end)
web.keymap.set('n', '<s-g>', function() web.view.scroll_to_bottom() end)
+ -- Reload page
+ web.keymap.set('n', '<c-r>', function() web.view.reload() end)
+ web.keymap.set('n', 'r', function() web.view.reload() end)
+
-- Open in new view
web.keymap.set('n', 'o', function()
config.menu:select(config.history.list(), { prompt = 'Open view:' }, function(err, result)
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp
index 66572e4..d5cd12c 100644
--- a/src/LuaRuntime.hpp
+++ b/src/LuaRuntime.hpp
@@ -67,6 +67,7 @@ signals:
void webview_js_eval_requested(const QString &js_code, WebViewId view_id);
void schedule_for_next_tick(const std::function<void()> &action);
void webview_rpc_action_defined(const QString &name, const RpcFunc &action, WebViewId view_id);
+ void webview_reload_requested(WebViewId webview_id);
protected:
LuaRuntime();
diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp
index 28ffd5f..0af1e9e 100644
--- a/src/LuaRuntimeApi.hpp
+++ b/src/LuaRuntimeApi.hpp
@@ -339,6 +339,14 @@ int lua_api_decorations_get_view(lua_State *state) {
return 1;
}
+int lua_api_view_reload(lua_State *state) {
+ WebViewId webview_id = lua_isnoneornil(state, 1) ? 0 : lua_tointeger(state, 1);
+ auto &runtime = LuaRuntime::instance();
+ emit runtime.webview_reload_requested(webview_id);
+ lua_pushnil(state);
+ return 1;
+}
+
// :: string -> (table -> nil) -> WebViewId -> nil
int lua_api_view_expose(lua_State *state) {
const char *name = lua_tostring(state, 1);
@@ -390,6 +398,7 @@ static luaL_Reg internals_api[] = {
luaL_Reg{"view_scroll", &lua_api_view_scroll},
luaL_Reg{"view_scroll_to_top", &lua_api_view_scroll_top},
luaL_Reg{"view_scroll_to_bottom", &lua_api_view_scroll_bottom},
+ luaL_Reg{"view_reload", &lua_api_view_reload},
luaL_Reg{"view_expose", &lua_api_view_expose},
luaL_Reg{"history_back", &lua_history_back},
luaL_Reg{"history_forward", &lua_history_forward},
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 3db1cb3..558a46e 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -82,6 +82,9 @@ void WindowActionRouter::initialize(Configuration *config) {
WITH_WEBVIEW_WINDOW(webview_id, window,
{ window->run_javascript(js_code, webview_id); });
});
+ connect(&runtime, &LuaRuntime::webview_reload_requested, this, [this](WebViewId webview_id) {
+ WITH_WEBVIEW_WINDOW(webview_id, window, { window->reload(webview_id); });
+ });
// Search
connect(&runtime, &LuaRuntime::search_requested, this,
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 7852a66..87e315c 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -10,7 +10,6 @@
#include "WindowActionRouter.hpp"
#include "events/KeyPressedEvent.hpp"
#include "keymap/KeymapEvaluator.hpp"
-#include "widgets/BrowserApp.hpp"
#include "widgets/Decorations.hpp"
#include "widgets/WebViewStack.hpp"
@@ -111,3 +110,7 @@ void BrowserWindow::expose_rpc_function(const QString &name, const RpcFunc &acti
WebViewId webview_id) {
get_webview_mediator(webview_id)->expose_rpc_function(name, action, webview_id);
}
+
+void BrowserWindow::reload(WebViewId webview_id) {
+ get_webview_mediator(webview_id)->reload(webview_id);
+}
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index bc6cea1..de48c6e 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -40,6 +40,7 @@ public:
void set_html(const QString &html, WebViewId webview_id);
void run_javascript(const QString &js_code, WebViewId webview_id);
void expose_rpc_function(const QString &name, const RpcFunc &action, WebViewId webview_id);
+ void reload(WebViewId webview_id);
bool on_window_key_event(QObject *target, QKeyEvent *event);
diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp
index dc644d5..1cff3d4 100644
--- a/src/widgets/Decorations.cpp
+++ b/src/widgets/Decorations.cpp
@@ -101,3 +101,5 @@ void Decorations::expose_rpc_function(const QString &name, const RpcFunc &action
if (decoration.has_value())
decoration.value()->expose_rpc_function(name, action);
}
+
+void Decorations::reload(WebViewId /* unused */) { qDebug() << "TODO: Impl"; }
diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp
index 97e0415..108b13e 100644
--- a/src/widgets/Decorations.hpp
+++ b/src/widgets/Decorations.hpp
@@ -32,6 +32,7 @@ public:
void run_javascript(const QString &js_code, WebViewId webview_id) override;
void expose_rpc_function(const QString &name, const RpcFunc &action,
WebViewId webview_id) override;
+ void reload(WebViewId webview_id) override;
private:
EdgeDecoration *decoration_top;
diff --git a/src/widgets/IWebViewMediator.hpp b/src/widgets/IWebViewMediator.hpp
index 9c64e53..a7007f2 100644
--- a/src/widgets/IWebViewMediator.hpp
+++ b/src/widgets/IWebViewMediator.hpp
@@ -13,4 +13,5 @@ public:
virtual void expose_rpc_function(const QString &name, const RpcFunc &action,
WebViewId webview_id) = 0;
virtual void run_javascript(const QString &js_code, WebViewId webview_id) = 0;
+ virtual void reload(WebViewId webview_id) = 0;
};
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 37532ff..ab5808f 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -356,3 +356,13 @@ void WebViewStack::expose_rpc_function(const QString &name, const RpcFunc & /* u
WebViewId /* unused */) {
qDebug() << "expose_rpc_function: NOT IMPLEMENTED" << name;
}
+
+void WebViewStack::reload(WebViewId webview_id) {
+ auto *webview = get_webview(webview_id);
+ if (webview == nullptr) {
+ qDebug() << "Webview does not exist";
+ return;
+ }
+
+ webview->reload();
+}
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index 5a88266..bbee44c 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -65,6 +65,7 @@ public slots:
void run_javascript(const QString &js_code, WebViewId webview_id) override;
void expose_rpc_function(const QString &name, const RpcFunc &action,
WebViewId webview_id) override;
+ void reload(WebViewId webview_id) override;
protected slots:
void on_new_webview_request(QWebEngineNewWindowRequest &request);